update axios response的解析
This commit is contained in:
@@ -1,28 +1,28 @@
|
||||
<template>
|
||||
<div class="aui-wrapper aui-page__login">
|
||||
<div class="aui-content__wrapper">
|
||||
<main class="aui-content">
|
||||
<div class="login-header">
|
||||
<h2 class="login-brand">{{ $t('brand.lg') }}</h2>
|
||||
</div>
|
||||
<div class="login-body">
|
||||
<h3 class="login-title">{{ $t('login.title') }}</h3>
|
||||
<el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmitHandle()" status-icon>
|
||||
<el-form-item prop="username">
|
||||
<el-input v-model="dataForm.username" :placeholder="$t('login.username')">
|
||||
<span slot="prefix" class="el-input__icon">
|
||||
<svg class="icon-svg" aria-hidden="true"><use xlink:href="#icon-user"></use></svg>
|
||||
</span>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="password">
|
||||
<el-input v-model="dataForm.password" type="password" :placeholder="$t('login.password')">
|
||||
<span slot="prefix" class="el-input__icon">
|
||||
<svg class="icon-svg" aria-hidden="true"><use xlink:href="#icon-lock"></use></svg>
|
||||
</span>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<!-- <el-form-item prop="captcha">
|
||||
<div class="aui-wrapper aui-page__login">
|
||||
<div class="aui-content__wrapper">
|
||||
<main class="aui-content">
|
||||
<div class="login-header">
|
||||
<h2 class="login-brand">{{ $t('brand.lg') }}</h2>
|
||||
</div>
|
||||
<div class="login-body">
|
||||
<h3 class="login-title">{{ $t('login.title') }}</h3>
|
||||
<el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmitHandle()" status-icon>
|
||||
<el-form-item prop="username">
|
||||
<el-input v-model="dataForm.username" :placeholder="$t('login.username')">
|
||||
<span slot="prefix" class="el-input__icon">
|
||||
<svg class="icon-svg" aria-hidden="true"><use xlink:href="#icon-user"></use></svg>
|
||||
</span>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="password">
|
||||
<el-input v-model="dataForm.password" type="password" :placeholder="$t('login.password')">
|
||||
<span slot="prefix" class="el-input__icon">
|
||||
<svg class="icon-svg" aria-hidden="true"><use xlink:href="#icon-lock"></use></svg>
|
||||
</span>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<!-- <el-form-item prop="captcha">
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="14">
|
||||
<el-input v-model="dataForm.captcha" :placeholder="$t('login.captcha')">
|
||||
@@ -36,20 +36,23 @@
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form-item> -->
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="dataFormSubmitHandle()" class="w-percent-100">{{ $t('login.title') }}</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
<div class="login-footer">
|
||||
<p>
|
||||
<a href="http://demo.open.renren.io/renren-security" target="_blank">{{ $t('login.demo') }}</a>
|
||||
</p>
|
||||
<p><a href="https://www.renren.io/" target="_blank">{{ $t('login.copyright') }}</a>2022 © renren.io</p>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="dataFormSubmitHandle()" class="w-percent-100">{{ $t('login.title') }}</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
<div class="login-footer">
|
||||
<p>
|
||||
<a href="http://demo.open.renren.io/renren-security" target="_blank">{{ $t('login.demo') }}</a>
|
||||
</p>
|
||||
<p>
|
||||
<a href="https://www.renren.io/" target="_blank">{{ $t('login.copyright') }}</a>
|
||||
2022 © renren.io
|
||||
</p>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
@@ -57,57 +60,60 @@ import Cookies from 'js-cookie'
|
||||
import debounce from 'lodash/debounce'
|
||||
// import { getUUID } from '@/utils'
|
||||
export default {
|
||||
data () {
|
||||
return {
|
||||
captchaPath: '',
|
||||
dataForm: {
|
||||
username: 'admin',
|
||||
password: 'admin',
|
||||
uuid: '',
|
||||
// captcha: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
dataRule () {
|
||||
return {
|
||||
username: [
|
||||
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
|
||||
],
|
||||
password: [
|
||||
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
|
||||
],
|
||||
// captcha: [
|
||||
// { required: true, message: this.$t('validate.required'), trigger: 'blur' }
|
||||
// ]
|
||||
}
|
||||
}
|
||||
},
|
||||
created () {
|
||||
// this.getCaptcha()
|
||||
},
|
||||
methods: {
|
||||
// 获取验证码
|
||||
getCaptcha () {
|
||||
this.dataForm.uuid = getUUID()
|
||||
this.captchaPath = `${window.SITE_CONFIG['apiURL']}/captcha?uuid=${this.dataForm.uuid}`
|
||||
},
|
||||
// 表单提交
|
||||
dataFormSubmitHandle: debounce(function () {
|
||||
this.$refs['dataForm'].validate((valid) => {
|
||||
if (!valid) {
|
||||
return false
|
||||
}
|
||||
this.$http.post(this.$http.adornUrl('/login'), this.dataForm).then(({ data: res }) => {
|
||||
if (res.code !== 200) {
|
||||
// this.getCaptcha()
|
||||
return this.$message.error(res.msg)
|
||||
}
|
||||
Cookies.set('token', res.data.token)
|
||||
this.$router.replace({ name: 'home' })
|
||||
}).catch(() => {})
|
||||
})
|
||||
}, 1000, { 'leading': true, 'trailing': false })
|
||||
}
|
||||
data() {
|
||||
return {
|
||||
captchaPath: '',
|
||||
dataForm: {
|
||||
username: 'admin',
|
||||
password: 'admin',
|
||||
uuid: ''
|
||||
// captcha: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
dataRule() {
|
||||
return {
|
||||
username: [{ required: true, message: this.$t('validate.required'), trigger: 'blur' }],
|
||||
password: [{ required: true, message: this.$t('validate.required'), trigger: 'blur' }]
|
||||
// captcha: [
|
||||
// { required: true, message: this.$t('validate.required'), trigger: 'blur' }
|
||||
// ]
|
||||
}
|
||||
}
|
||||
},
|
||||
created() {
|
||||
// this.getCaptcha()
|
||||
},
|
||||
methods: {
|
||||
// 获取验证码
|
||||
getCaptcha() {
|
||||
this.dataForm.uuid = getUUID()
|
||||
this.captchaPath = `${window.SITE_CONFIG['apiURL']}/captcha?uuid=${this.dataForm.uuid}`
|
||||
},
|
||||
// 表单提交
|
||||
dataFormSubmitHandle: debounce(
|
||||
function() {
|
||||
this.$refs['dataForm'].validate(valid => {
|
||||
if (!valid) {
|
||||
return false
|
||||
}
|
||||
this.$http
|
||||
.post(this.$http.adornUrl('/login'), this.dataForm)
|
||||
.then(({ data: res }) => {
|
||||
if (res.code !== 200) {
|
||||
// this.getCaptcha()
|
||||
return this.$message.error(res.msg)
|
||||
}
|
||||
Cookies.set('token', res.data.token)
|
||||
this.$router.replace({ name: 'home' })
|
||||
})
|
||||
.catch(() => {})
|
||||
})
|
||||
},
|
||||
1000,
|
||||
{ leading: true, trailing: false }
|
||||
)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user