wangxianzhang 3 years ago
parent
commit
4dd9b5d42f
  1. 11
      epmet-oper-web/src/utils/index.js
  2. 165
      epmet-oper-web/src/views/main-navbar-update-password.vue
  3. 346
      epmet-oper-web/src/views/modules/sys/user-add-or-update.vue
  4. 150
      epmet-oper-web/src/views/pages/login.vue

11
epmet-oper-web/src/utils/index.js

@ -1,5 +1,6 @@
import Cookies from 'js-cookie' import Cookies from 'js-cookie'
import store from '@/js/store' import store from '@/js/store'
import JSEncrypt from 'jsencrypt' //引入加密
/** /**
* 获取字典数据列表 * 获取字典数据列表
@ -93,3 +94,13 @@ export function treeDataTranslate(data, id = 'id', pid = 'pid') {
} }
return res return res
} }
// 加密
export function encryptedData(key, data) {
// 新建JSEncrypt对象
let encryptor = new JSEncrypt()
// 设置公钥
encryptor.setPublicKey(key)
// 加密数据
return encryptor.encrypt(data)
}

165
epmet-oper-web/src/views/main-navbar-update-password.vue

@ -1,93 +1,157 @@
<template> <template>
<el-dialog :visible.sync="visible" <el-dialog
:title="$t('updatePassword.title')" :visible.sync="visible"
width="500px" :title="$t('updatePassword.title')"
:close-on-click-modal="false" width="500px"
:close-on-press-escape="false" :close-on-click-modal="false"
:append-to-body="true"> :close-on-press-escape="false"
<el-form :model="dataForm" :append-to-body="true"
:rules="dataRule" >
ref="dataForm" <el-form
@keyup.enter.native="dataFormSubmitHandle()" :model="dataForm"
label-width="100px"> :rules="dataRule"
ref="dataForm"
@keyup.enter.native="dataFormSubmitHandle()"
label-width="100px"
>
<el-form-item :label="$t('updatePassword.username')"> <el-form-item :label="$t('updatePassword.username')">
<span>{{ $store.state.user.realName }}</span> <span>{{ $store.state.user.realName }}</span>
</el-form-item> </el-form-item>
<!-- <el-form-item prop="password" <el-form-item prop="password" :label="$t('updatePassword.password')">
:label="$t('updatePassword.password')"> <el-input
<el-input v-model="dataForm.password" v-model="dataForm.password"
type="password" type="password"
:placeholder="$t('updatePassword.password')"></el-input> :placeholder="$t('updatePassword.password')"
</el-form-item> --> ></el-input>
<el-form-item prop="newPassword"
:label="$t('updatePassword.newPassword')">
<el-input v-model="dataForm.newPassword"
type="password"
:placeholder="$t('updatePassword.newPassword')"></el-input>
</el-form-item> </el-form-item>
<el-form-item prop="confirmPassword" <el-form-item
:label="$t('updatePassword.confirmPassword')"> prop="newPassword"
<el-input v-model="dataForm.confirmPassword" :label="$t('updatePassword.newPassword')"
type="password" >
:placeholder="$t('updatePassword.confirmPassword')"></el-input> <el-input
v-model="dataForm.newPassword"
type="password"
placeholder="密码必须8-20个字符,而且同时包含大小写字母和数字"
></el-input>
</el-form-item>
<el-form-item
prop="confirmPassword"
:label="$t('updatePassword.confirmPassword')"
>
<el-input
v-model="dataForm.confirmPassword"
type="password"
:placeholder="$t('updatePassword.confirmPassword')"
></el-input>
</el-form-item> </el-form-item>
</el-form> </el-form>
<template slot="footer"> <template slot="footer">
<el-button @click="visible = false">{{ $t('cancel') }}</el-button> <el-button @click="visible = false">{{ $t('cancel') }}</el-button>
<el-button type="primary" <el-button type="primary" @click="dataFormSubmitHandle()">{{
@click="dataFormSubmitHandle()">{{ $t('confirm') }}</el-button> $t('confirm')
}}</el-button>
</template> </template>
</el-dialog> </el-dialog>
</template> </template>
<script> <script>
import debounce from 'lodash/debounce' import debounce from 'lodash/debounce'
import { clearLoginInfo } from '@/utils' import { clearLoginInfo, encryptedData } from '@/utils'
import { requestPost } from '@/js/dai/request' import { requestPost } from '@/js/dai/request'
export default { export default {
data () { data() {
return { return {
visible: false, visible: false,
pubKey: '',
dataForm: { dataForm: {
// password: '', password: '',
newPassword: '', newPassword: '',
confirmPassword: '' confirmPassword: ''
} }
} }
}, },
computed: { computed: {
dataRule () { dataRule() {
var validateConfirmPassword = (rule, value, callback) => { var validateConfirmPassword = (rule, value, callback) => {
if (this.dataForm.newPassword !== value) { if (this.dataForm.newPassword !== value) {
return callback(new Error(this.$t('updatePassword.validate.confirmPassword'))) return callback(
new Error(this.$t('updatePassword.validate.confirmPassword'))
)
} }
callback() callback()
} }
return { return {
// password: [ password: [
// { required: true, message: this.$t('validate.required'), trigger: 'blur' } {
// ], required: true,
message: this.$t('validate.required'),
trigger: 'blur'
}
],
newPassword: [ newPassword: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' } {
required: true,
message: this.$t('validate.required'),
trigger: 'blur'
}
], ],
confirmPassword: [ confirmPassword: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }, {
required: true,
message: this.$t('validate.required'),
trigger: 'blur'
},
{ validator: validateConfirmPassword, trigger: 'blur' } { validator: validateConfirmPassword, trigger: 'blur' }
] ]
} }
} }
}, },
methods: { methods: {
init () { init() {
this.visible = true this.visible = true
this.$nextTick(() => { this.$nextTick(() => {
this.$refs['dataForm'].resetFields() this.$refs['dataForm'].resetFields()
}) })
//
this.getPubKey()
},
//
getPubKey() {
this.$http
.post('/auth/govweb/getKey')
.then(({ data: res }) => {
if (res.code !== 0) {
return this.$message.error(res.msg)
}
this.pubKey = res.data // ;
})
.catch(() => {})
},
validateComplexity(pwd) {
let regex = new RegExp('(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z]).{8,20}')
if (!regex.test(pwd)) {
this.$message({
message: '密码必须8-20个字符,而且同时包含大小写字母和数字',
type: 'error'
})
return false
}
return true
}, },
// //
dataFormSubmitHandle () { dataFormSubmitHandle() {
this.$refs['dataForm'].validate((valid) => { this.$refs['dataForm'].validate((valid) => {
if (!valid) { if (!valid) return false
if (!this.validateComplexity(this.dataForm.newPassword)) return false
if (this.dataForm.newPassword !== this.dataForm.confirmPassword) {
this.$message.error('请输入相同密码')
return false return false
} }
@ -95,25 +159,20 @@ export default {
}) })
}, },
async submitForm () { async submitForm() {
const { pubKey } = this
if (this.dataForm.newPassword !== this.dataForm.confirmPassword) {
this.$message.info('请输入相同密码')
return false
}
const url = '/epmetuser/operuser/updatePwd' const url = '/epmetuser/operuser/updatePwd'
const params = { const params = {
// workAuth: 1, oldPassword: encryptedData(pubKey, this.dataForm.password),
// resiAuth: 1, password: encryptedData(pubKey, this.dataForm.newPassword),
newPassword: this.dataForm.newPassword, newPassword: encryptedData(pubKey, this.dataForm.newPassword),
confirmNewPassword: encryptedData(pubKey, this.dataForm.confirmPassword)
} }
const { data, code, msg } = await requestPost(url, params) const { data, code, msg } = await requestPost(url, params)
if (code === 0) { if (code === 0) {
this.$message.success('操作成功') this.$message.success('操作成功')
this.visible = false this.visible = false
} else { } else {
this.$message.error(msg) this.$message.error(msg)
} }

346
epmet-oper-web/src/views/modules/sys/user-add-or-update.vue

@ -1,74 +1,91 @@
<template> <template>
<el-dialog :visible.sync="visible" <el-dialog
:title="!dataForm.id ? $t('add') : $t('update')" :visible.sync="visible"
:close-on-click-modal="false" :title="!dataForm.id ? $t('add') : $t('update')"
:close-on-press-escape="false"> :close-on-click-modal="false"
<el-form :model="dataForm" :close-on-press-escape="false"
:rules="dataRule" >
ref="dataForm" <el-form
@keyup.enter.native="dataFormSubmitHandle()" :model="dataForm"
label-width="120px"> :rules="dataRule"
<el-form-item prop="username" ref="dataForm"
:label="$t('user.username')"> @keyup.enter.native="dataFormSubmitHandle()"
<el-input v-model="dataForm.realName" label-width="120px"
:placeholder="$t('user.username')"></el-input> >
<el-form-item prop="realName" :label="$t('user.username')">
<el-input
v-model="dataForm.realName"
:placeholder="$t('user.username')"
></el-input>
</el-form-item> </el-form-item>
<!-- <el-form-item prop="deptName" :label="$t('user.deptName')">--> <!-- <el-form-item prop="deptName" :label="$t('user.deptName')">-->
<!-- <ren-dept-tree v-model="dataForm.deptId" :placeholder="$t('dept.title')" :dept-name.sync="dataForm.deptName"></ren-dept-tree>--> <!-- <ren-dept-tree v-model="dataForm.deptId" :placeholder="$t('dept.title')" :dept-name.sync="dataForm.deptName"></ren-dept-tree>-->
<!-- </el-form-item>--> <!-- </el-form-item>-->
<el-form-item v-if="!dataForm.id" <el-form-item
prop="password" v-if="!dataForm.id"
:label="$t('user.password')" prop="password"
:class="{ 'is-required': !dataForm.id }"> :label="$t('user.password')"
<el-input v-model="dataForm.password" :class="{ 'is-required': !dataForm.id }"
type="password" >
:placeholder="$t('user.password')"></el-input> <el-input
v-model="dataForm.password"
type="password"
placeholder="密码必须8-20个字符,而且同时包含大小写字母和数字"
></el-input>
</el-form-item> </el-form-item>
<el-form-item v-if="!dataForm.id" <el-form-item
prop="confirmPassword" v-if="!dataForm.id"
:label="$t('user.confirmPassword')" prop="confirmPassword"
:class="{ 'is-required': !dataForm.id }"> :label="$t('user.confirmPassword')"
<el-input v-model="dataForm.confirmPassword" :class="{ 'is-required': !dataForm.id }"
type="password" >
:placeholder="$t('user.confirmPassword')"></el-input> <el-input
v-model="dataForm.confirmPassword"
type="password"
:placeholder="$t('user.confirmPassword')"
></el-input>
</el-form-item> </el-form-item>
<!-- <el-form-item prop="realName" :label="$t('user.realName')">--> <!-- <el-form-item prop="realName" :label="$t('user.realName')">-->
<!-- <el-input v-model="dataForm.realName" :placeholder="$t('user.realName')"></el-input>--> <!-- <el-input v-model="dataForm.realName" :placeholder="$t('user.realName')"></el-input>-->
<!-- </el-form-item>--> <!-- </el-form-item>-->
<el-form-item prop="gender" <el-form-item prop="gender" :label="$t('user.gender')" size="mini">
:label="$t('user.gender')"
size="mini">
<el-radio-group v-model="dataForm.gender"> <el-radio-group v-model="dataForm.gender">
<el-radio :label="0">{{ $t('user.gender0') }}</el-radio> <el-radio :label="0">{{ $t('user.gender0') }}</el-radio>
<el-radio :label="1">{{ $t('user.gender1') }}</el-radio> <el-radio :label="1">{{ $t('user.gender1') }}</el-radio>
<el-radio :label="2">{{ $t('user.gender2') }}</el-radio> <el-radio :label="2">{{ $t('user.gender2') }}</el-radio>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
<el-form-item prop="email" <el-form-item prop="email" :label="$t('user.email')">
:label="$t('user.email')"> <el-input
<el-input v-model="dataForm.email" v-model="dataForm.email"
:placeholder="$t('user.email')"></el-input> :placeholder="$t('user.email')"
></el-input>
</el-form-item> </el-form-item>
<el-form-item prop="phone" <el-form-item prop="phone" :label="$t('user.mobile')">
:label="$t('user.mobile')"> <el-input
<el-input v-model="dataForm.phone" v-model="dataForm.phone"
:placeholder="$t('user.mobile')"></el-input> :placeholder="$t('user.mobile')"
></el-input>
</el-form-item> </el-form-item>
<el-form-item prop="roleIdList" <el-form-item
:label="$t('user.roleIdList')" prop="roleIdList"
class="role-list"> :label="$t('user.roleIdList')"
<el-select v-model="dataForm.roleIdList" class="role-list"
multiple >
:placeholder="$t('user.roleIdList')"> <el-select
<el-option v-for="role in roleList" v-model="dataForm.roleIdList"
:key="role.id" multiple
:label="role.name" :placeholder="$t('user.roleIdList')"
:value="role.id"></el-option> >
<el-option
v-for="role in roleList"
:key="role.id"
:label="role.name"
:value="role.id"
></el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item prop="status" <el-form-item prop="status" :label="$t('user.status')" size="mini">
:label="$t('user.status')"
size="mini">
<el-radio-group v-model="dataForm.status"> <el-radio-group v-model="dataForm.status">
<el-radio :label="0">{{ $t('user.status0') }}</el-radio> <el-radio :label="0">{{ $t('user.status0') }}</el-radio>
<el-radio :label="1">{{ $t('user.status1') }}</el-radio> <el-radio :label="1">{{ $t('user.status1') }}</el-radio>
@ -77,12 +94,13 @@
</el-form> </el-form>
<template slot="footer"> <template slot="footer">
<el-button @click="visible = false">{{ $t('cancel') }}</el-button> <el-button @click="visible = false">{{ $t('cancel') }}</el-button>
<el-button type="primary" <el-button
v-if="canSave" type="primary"
@click="dataFormSubmitHandle()">{{ $t('confirm') }}</el-button> v-if="canSave"
<el-button type="primary" @click="dataFormSubmitHandle()"
v-else >{{ $t('confirm') }}</el-button
disabled>{{ $t('confirm') }}</el-button> >
<el-button type="primary" v-else disabled>{{ $t('confirm') }}</el-button>
</template> </template>
</el-dialog> </el-dialog>
</template> </template>
@ -90,8 +108,10 @@
<script> <script>
import debounce from 'lodash/debounce' import debounce from 'lodash/debounce'
import { isEmail, isMobile } from '@/utils/validate' import { isEmail, isMobile } from '@/utils/validate'
import { encryptedData } from '@/utils'
export default { export default {
data () { data() {
return { return {
visible: false, visible: false,
canSave: true, canSave: true,
@ -111,11 +131,18 @@ export default {
} }
}, },
computed: { computed: {
dataRule () { dataRule() {
var validatePassword = (rule, value, callback) => { var validatePassword = (rule, value, callback) => {
if (!this.dataForm.id && !/\S/.test(value)) { if (!this.dataForm.id && !/\S/.test(value)) {
return callback(new Error(this.$t('validate.required'))) return callback(new Error(this.$t('validate.required')))
} }
let regex = new RegExp('(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z]).{8,20}')
if (!regex.test(value)) {
return callback(
new Error('密码必须8-20个字符,而且同时包含大小写字母和数字')
)
}
callback() callback()
} }
var validateConfirmPassword = (rule, value, callback) => { var validateConfirmPassword = (rule, value, callback) => {
@ -129,120 +156,179 @@ export default {
} }
var validateEmail = (rule, value, callback) => { var validateEmail = (rule, value, callback) => {
if (!isEmail(value)) { if (!isEmail(value)) {
return callback(new Error(this.$t('validate.format', { 'attr': this.$t('user.email') }))) return callback(
new Error(
this.$t('validate.format', { attr: this.$t('user.email') })
)
)
} }
callback() callback()
} }
var validateMobile = (rule, value, callback) => { var validateMobile = (rule, value, callback) => {
if (!isMobile(value)) { if (!isMobile(value)) {
return callback(new Error(this.$t('validate.format', { 'attr': this.$t('user.mobile') }))) return callback(
new Error(
this.$t('validate.format', { attr: this.$t('user.mobile') })
)
)
} }
callback() callback()
} }
return { return {
realName: [ realName: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' } {
], required: true,
password: [ message: this.$t('validate.required'),
{ validator: validatePassword, trigger: 'blur' } trigger: 'blur'
}
], ],
password: [{ validator: validatePassword, trigger: 'blur' }],
confirmPassword: [ confirmPassword: [
{ validator: validateConfirmPassword, trigger: 'blur' } { validator: validateConfirmPassword, trigger: 'blur' }
], ],
email: [ email: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }, {
required: true,
message: this.$t('validate.required'),
trigger: 'blur'
},
{ validator: validateEmail, trigger: 'blur' } { validator: validateEmail, trigger: 'blur' }
], ],
phone: [ phone: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }, {
required: true,
message: this.$t('validate.required'),
trigger: 'blur'
},
{ validator: validateMobile, trigger: 'blur' } { validator: validateMobile, trigger: 'blur' }
] ]
} }
} }
}, },
methods: { methods: {
init () { init() {
this.visible = true this.visible = true
this.dataForm.deptId = '' this.dataForm.deptId = ''
this.$nextTick(() => { this.$nextTick(() => {
this.$refs['dataForm'].resetFields() this.$refs['dataForm'].resetFields()
this.roleIdListDefault = [] this.roleIdListDefault = []
Promise.all([ Promise.all([this.getRoleList()]).then(() => {
this.getRoleList()
]).then(() => {
if (this.dataForm.id) { if (this.dataForm.id) {
this.getInfo() this.getInfo()
} }
}) })
}) })
//
this.getPubKey()
},
//
getPubKey() {
this.$http
.post('/auth/govweb/getKey')
.then(({ data: res }) => {
if (res.code !== 0) {
return this.$message.error(res.msg)
}
this.pubKey = res.data // ;
})
.catch(() => {})
}, },
// //
getRoleList () { getRoleList() {
return this.$http.get('/oper/access/operrole/list').then(({ data: res }) => { return this.$http
if (res.code !== 0) { .get('/oper/access/operrole/list')
return this.$message.error(res.msg) .then(({ data: res }) => {
} if (res.code !== 0) {
this.roleList = res.data return this.$message.error(res.msg)
}).catch(() => { }) }
this.roleList = res.data
})
.catch(() => {})
}, },
// //
getInfo () { getInfo() {
this.$http.get(`/epmetuser/operuser/${this.dataForm.id}`).then(({ data: res }) => { this.$http
if (res.code !== 0) { .get(`/epmetuser/operuser/${this.dataForm.id}`)
return this.$message.error(res.msg) .then(({ data: res }) => {
} if (res.code !== 0) {
this.dataForm = { return this.$message.error(res.msg)
...this.dataForm,
...res.data,
roleIdList: []
}
// ,
for (var i = 0; i < res.data.roleIdList.length; i++) {
if (this.roleList.filter(item => item.id === res.data.roleIdList[i])[0]) {
this.dataForm.roleIdList.push(res.data.roleIdList[i])
continue
} }
this.roleIdListDefault.push(res.data.roleIdList[i]) this.dataForm = {
} ...this.dataForm,
}).catch(() => { }) ...res.data,
roleIdList: []
}
// ,
for (var i = 0; i < res.data.roleIdList.length; i++) {
if (
this.roleList.filter(
(item) => item.id === res.data.roleIdList[i]
)[0]
) {
this.dataForm.roleIdList.push(res.data.roleIdList[i])
continue
}
this.roleIdListDefault.push(res.data.roleIdList[i])
}
})
.catch(() => {})
}, },
// //
dataFormSubmitHandle: debounce(function() { dataFormSubmitHandle: debounce(
function () {
this.$refs['dataForm'].validate((valid) => { this.$refs['dataForm'].validate((valid) => {
if (!valid) { if (!valid) {
return false return false
}
if (!this.canSave) {
return;
}
this.canSave = false;
setTimeout(() => {
this.canSave = true //
}, 2000)
this.$http[!this.dataForm.id ? 'post' : 'put']('/epmetuser/operuser', {
...this.dataForm,
roleIdList: [
...this.dataForm.roleIdList,
...this.roleIdListDefault
]
}).then(({ data: res }) => {
if (res.code !== 0) {
return this.$message.error(res.msg)
} }
this.$message({ if (!this.canSave) {
message: this.$t('prompt.success'), return
type: 'success', }
duration: 500, this.canSave = false
onClose: () => { setTimeout(() => {
this.visible = false this.canSave = true //
this.$emit('refreshDataList') }, 2000)
const { pubKey } = this
this.$http[!this.dataForm.id ? 'post' : 'put'](
'/epmetuser/operuser',
{
...this.dataForm,
roleIdList: [
...this.dataForm.roleIdList,
...this.roleIdListDefault
],
password: encryptedData(pubKey, this.dataForm.password),
confirmPassword: encryptedData(
pubKey,
this.dataForm.confirmPassword
),
email: encryptedData(pubKey, this.dataForm.email),
phone: encryptedData(pubKey, this.dataForm.phone)
} }
}) )
}).catch(() => { }) .then(({ data: res }) => {
}) if (res.code !== 0) {
}, 1000, { 'leading': true, 'trailing': false }) return this.$message.error(res.msg)
}
this.$message({
message: this.$t('prompt.success'),
type: 'success',
duration: 500,
onClose: () => {
this.visible = false
this.$emit('refreshDataList')
}
})
})
.catch(() => {})
})
},
1000,
{ leading: true, trailing: false }
)
} }
} }
</script> </script>

150
epmet-oper-web/src/views/pages/login.vue

@ -7,11 +7,13 @@
</div> </div>
<div class="login-body"> <div class="login-body">
<h3 class="login-title">{{ $t('login.title') }}</h3> <h3 class="login-title">{{ $t('login.title') }}</h3>
<el-form :model="dataForm" <el-form
:rules="dataRule" :model="dataForm"
ref="dataForm" :rules="dataRule"
@keyup.enter.native="dataFormSubmitHandle()" ref="dataForm"
status-icon> @keyup.enter.native="dataFormSubmitHandle()"
status-icon
>
<!-- <el-form-item> <!-- <el-form-item>
<el-select v-model="$i18n.locale" <el-select v-model="$i18n.locale"
class="w-percent-100"> class="w-percent-100">
@ -22,25 +24,22 @@
</el-select> </el-select>
</el-form-item> --> </el-form-item> -->
<el-form-item prop="phone"> <el-form-item prop="phone">
<el-input v-model="dataForm.phone" <el-input v-model="dataForm.phone" placeholder="手机号">
placeholder="手机号"> <span slot="prefix" class="el-input__icon">
<span slot="prefix" <svg class="icon-svg" aria-hidden="true">
class="el-input__icon">
<svg class="icon-svg"
aria-hidden="true">
<use xlink:href="#icon-user"></use> <use xlink:href="#icon-user"></use>
</svg> </svg>
</span> </span>
</el-input> </el-input>
</el-form-item> </el-form-item>
<el-form-item prop="password"> <el-form-item prop="password">
<el-input v-model="dataForm.password" <el-input
type="password" v-model="dataForm.password"
:placeholder="$t('login.password')"> type="password"
<span slot="prefix" :placeholder="$t('login.password')"
class="el-input__icon"> >
<svg class="icon-svg" <span slot="prefix" class="el-input__icon">
aria-hidden="true"> <svg class="icon-svg" aria-hidden="true">
<use xlink:href="#icon-lock"></use> <use xlink:href="#icon-lock"></use>
</svg> </svg>
</span> </span>
@ -49,39 +48,46 @@
<el-form-item prop="captcha"> <el-form-item prop="captcha">
<el-row :gutter="20"> <el-row :gutter="20">
<el-col :span="14"> <el-col :span="14">
<el-input v-model="dataForm.captcha" <el-input
:placeholder="$t('login.captcha')"> v-model="dataForm.captcha"
<span slot="prefix" :placeholder="$t('login.captcha')"
class="el-input__icon"> >
<svg class="icon-svg" <span slot="prefix" class="el-input__icon">
aria-hidden="true"> <svg class="icon-svg" aria-hidden="true">
<use xlink:href="#icon-safetycertificate"></use> <use xlink:href="#icon-safetycertificate"></use>
</svg> </svg>
</span> </span>
</el-input> </el-input>
</el-col> </el-col>
<el-col :span="10" <el-col :span="10" class="login-captcha">
class="login-captcha"> <img :src="captchaPath" @click="getCaptcha()" />
<img :src="captchaPath"
@click="getCaptcha()">
</el-col> </el-col>
</el-row> </el-row>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button type="primary" <el-button
@click="dataFormSubmitHandle()" type="primary"
class="w-percent-100">{{ $t('login.title') }}</el-button> @click="dataFormSubmitHandle()"
class="w-percent-100"
>{{ $t('login.title') }}</el-button
>
</el-form-item> </el-form-item>
</el-form> </el-form>
</div> </div>
<div class="login-footer"> <div class="login-footer">
<p> <p>
<a href="https://demo.cloud.renren.io/renren-cloud" <a
target="_blank">{{ $t('login.demo') }}</a> href="https://demo.cloud.renren.io/renren-cloud"
target="_blank"
>{{ $t('login.demo') }}</a
>
</p> </p>
<!-- 2020 © renren.io --> <!-- 2020 © renren.io -->
<p><a href="https://www.renren.io/" <p>
target="_blank">{{ $t('login.copyright') }}</a></p> <a href="https://www.renren.io/" target="_blank">{{
$t('login.copyright')
}}</a>
</p>
</div> </div>
</main> </main>
</div> </div>
@ -92,12 +98,13 @@
import Cookies from 'js-cookie' import Cookies from 'js-cookie'
import debounce from 'lodash/debounce' import debounce from 'lodash/debounce'
import { messages } from '@/i18n' import { messages } from '@/i18n'
import { getUUID } from '@/utils' import { getUUID, encryptedData } from '@/utils'
export default { export default {
data () { data() {
return { return {
i18nMessages: messages, i18nMessages: messages,
captchaPath: '', captchaPath: '',
pubKey: '',
dataForm: { dataForm: {
app: 'oper', app: 'oper',
client: 'web', client: 'web',
@ -110,11 +117,9 @@ export default {
} }
}, },
computed: { computed: {
dataRule () { dataRule() {
return { return {
phone: [ phone: [{ required: true, message: '手机号不能为空', trigger: 'blur' }],
{ required: true, message: '手机号不能为空', trigger: 'blur' }
],
password: [ password: [
{ required: true, message: '密码不能为空', trigger: 'blur' } { required: true, message: '密码不能为空', trigger: 'blur' }
], ],
@ -124,32 +129,63 @@ export default {
} }
} }
}, },
created () { created() {
this.getCaptcha() this.getCaptcha()
//
this.getPubKey()
}, },
methods: { methods: {
// //
getCaptcha () { getCaptcha() {
this.dataForm.uuid = getUUID() this.dataForm.uuid = getUUID()
this.captchaPath = `${window.SITE_CONFIG['apiURL']}/auth/login/captcha?uuid=${this.dataForm.uuid}` this.captchaPath = `${window.SITE_CONFIG['apiURL']}/auth/login/captcha?uuid=${this.dataForm.uuid}`
}, },
//
dataFormSubmitHandle: debounce(function () { //
this.$refs['dataForm'].validate((valid, messageObj) => { getPubKey() {
if (!valid) { this.$http
app.util.validateRule(messageObj) .post('/auth/govweb/getKey')
} .then(({ data: res }) => {
this.$http.post('/auth/login/operweb/loginbypassword', this.dataForm).then(({ data: res }) => {
if (res.code !== 0) { if (res.code !== 0) {
this.getCaptcha()
return this.$message.error(res.msg) return this.$message.error(res.msg)
} }
localStorage.setItem('userType', 'oper')
Cookies.set('token', res.data.token) this.pubKey = res.data // ;
this.$router.replace({ name: 'home' }).catch(() => { }) })
}).catch(() => { }) .catch(() => {})
}) },
}, 1000, { 'leading': true, 'trailing': false })
//
dataFormSubmitHandle: debounce(
function () {
this.$refs['dataForm'].validate((valid, messageObj) => {
if (!valid) {
app.util.validateRule(messageObj)
return
}
const { pubKey } = this
this.$http
.post('/auth/login/operweb/loginbypassword', {
...this.dataForm,
phone: encryptedData(pubKey, this.dataForm.phone),
password: encryptedData(pubKey, this.dataForm.password)
})
.then(({ data: res }) => {
if (res.code !== 0) {
this.getCaptcha()
return this.$message.error(res.msg)
}
localStorage.setItem('userType', 'oper')
Cookies.set('token', res.data.token)
this.$router.replace({ name: 'home' }).catch(() => {})
})
.catch(() => {})
})
},
1000,
{ leading: true, trailing: false }
)
} }
} }
</script> </script>

Loading…
Cancel
Save