2021-04-22 17:43:13 +08:00
|
|
|
<template>
|
2021-06-02 17:16:00 +08:00
|
|
|
<div v-clickoutside="{obj: editUser, func: esc}" class="right-box right-box-user">
|
2021-04-22 17:43:13 +08:00
|
|
|
<div class="right-box__header">
|
|
|
|
|
<div class="header__title">{{editUser.id ? $t('config.user.editUser') : $t('config.user.createUser')}}</div>
|
|
|
|
|
<div class="header__operation">
|
|
|
|
|
<span v-cancel="{obj: editUser, func: esc}"><i class="nz-icon nz-icon-close"></i></span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="right-box__container">
|
|
|
|
|
<div class="container__form">
|
2021-05-19 23:17:24 +08:00
|
|
|
<el-form ref="userForm" :model="editUser" :rules="editUser.id ? rules2 : rules" label-position="top" label-width="120px">
|
2021-04-22 17:43:13 +08:00
|
|
|
<!--name-->
|
|
|
|
|
<el-form-item :label="$t('config.user.name')" prop="name">
|
|
|
|
|
<el-input id="account-input-name" v-model="editUser.name" :disabled="editUser.username==='admin' && editUser.id==1"
|
|
|
|
|
maxlength="64" placeholder="" show-word-limit size="small" type="text"></el-input>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<!--username-->
|
|
|
|
|
<el-form-item :label="$t('config.user.username')" prop="username">
|
|
|
|
|
<el-input id="account-input-username" v-model="editUser.username" :disabled="editUser.username==='admin' && editUser.id==1"
|
|
|
|
|
maxlength="64" placeholder="" show-word-limit size="small" type="text"></el-input>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<!--password-->
|
2021-04-27 10:50:44 +08:00
|
|
|
<el-form-item :label="$t('config.user.pin')" prop="pin">
|
2021-05-28 10:43:41 +08:00
|
|
|
<el-input id="account-input-password" v-model="editUser.pin" maxlength="64" placeholder=""
|
2021-05-12 17:45:48 +08:00
|
|
|
show-word-limit size="small" type="password" @blur="pinBlur" autocomplete="new-password"></el-input>
|
2021-04-22 17:43:13 +08:00
|
|
|
</el-form-item>
|
2021-04-27 20:31:54 +08:00
|
|
|
<!--pinChange-->
|
|
|
|
|
<el-form-item :label="$t('config.user.confirmPin')" label-width="200px" prop="pinChange">
|
2021-05-28 10:43:41 +08:00
|
|
|
<el-input id="account-input-pinChange" v-model="editUser.pinChange" maxlength="64" placeholder=""
|
2021-04-22 17:43:13 +08:00
|
|
|
show-word-limit size="small" type="password"></el-input>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<!--email-->
|
|
|
|
|
<el-form-item label="E-mail" prop="email">
|
2021-05-28 10:43:41 +08:00
|
|
|
<el-input id="account-input-email" v-model="editUser.email" maxlength="64" show-word-limit placeholder="" size="small" type="text"></el-input>
|
2021-04-22 17:43:13 +08:00
|
|
|
</el-form-item>
|
|
|
|
|
<!--mobile-->
|
|
|
|
|
<el-form-item :label="$t('config.user.mobile')" prop="mobile">
|
2021-05-28 10:43:41 +08:00
|
|
|
<el-input id="account-input-mobile" v-model.number="editUser.mobile" maxlength="64" show-word-limit placeholder="" size="small" type="text"></el-input>
|
2021-04-22 17:43:13 +08:00
|
|
|
</el-form-item>
|
|
|
|
|
<!--roles-->
|
|
|
|
|
<el-form-item :label="$t('config.user.roles')" prop="roleIds">
|
2021-05-19 23:17:24 +08:00
|
|
|
<el-select id="account-input-roleIds"
|
|
|
|
|
v-model="editUser.roleIds"
|
|
|
|
|
:disabled="(editUser.username==='admin') && editUser.id==1"
|
|
|
|
|
class="right-box__select"
|
|
|
|
|
clearable
|
|
|
|
|
collapse-tags
|
|
|
|
|
placeholder=""
|
|
|
|
|
popper-class="right-box-select-dropdown prevent-clickoutside"
|
|
|
|
|
size="small"
|
|
|
|
|
@change="()=>{this.$forceUpdate()}">
|
2021-04-22 17:43:13 +08:00
|
|
|
<template v-for="role in roles">
|
2021-05-12 17:45:48 +08:00
|
|
|
<!-- <el-option :key="role.id" :label="role.i18n?$t(role.i18n+''):role.name" :value="role.id"></el-option>-->
|
|
|
|
|
<el-option :key="role.id" :label="role.name" :value="role.id"></el-option>
|
2021-04-22 17:43:13 +08:00
|
|
|
</template>
|
|
|
|
|
</el-select>
|
|
|
|
|
</el-form-item>
|
2021-04-23 20:06:58 +08:00
|
|
|
<!--enable-->
|
|
|
|
|
<el-form-item :label="$t('config.user.enable')">
|
|
|
|
|
<el-switch id="account-input-status" v-model="editUser.status" :disabled="isCurrentUser(editUser.username) || (editUser.username==='admin' && editUser.id==1) " active-color="#ee9d3f" active-value="1"
|
|
|
|
|
inactive-value="0">
|
|
|
|
|
</el-switch>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
2021-04-22 17:43:13 +08:00
|
|
|
<el-form-item v-if="editUser.id" :label="$t('config.user.createTime')">
|
|
|
|
|
<div class="right-box-form-content-txt">{{editUser.createAt}}</div>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
|
|
</el-form>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="right-box__footer">
|
|
|
|
|
<button id="asset-edit-cancel" v-cancel="{obj: editUser, func: esc}" class="footer__btn footer__btn--light">
|
|
|
|
|
<span>{{$t('overall.cancel')}}</span>
|
|
|
|
|
</button>
|
|
|
|
|
<button id="asset-edit-save" :class="{'footer__btn--disabled': prevent_opt.save}" :disabled="prevent_opt.save" class="footer__btn" @click="save">
|
|
|
|
|
<span>{{$t('overall.save')}}</span>
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2021-05-28 13:12:05 +08:00
|
|
|
// import { host, port } from '@/components/common/js/validate'
|
2021-07-05 14:43:47 +08:00
|
|
|
import editRigthBox from '../../mixin/editRigthBox'
|
2021-05-28 13:12:05 +08:00
|
|
|
|
2021-04-22 18:03:56 +08:00
|
|
|
export default {
|
|
|
|
|
name: 'userBox',
|
|
|
|
|
components: {
|
|
|
|
|
},
|
|
|
|
|
props: {
|
|
|
|
|
obj: {
|
|
|
|
|
type: Object
|
|
|
|
|
}
|
|
|
|
|
},
|
2021-07-05 14:43:47 +08:00
|
|
|
mixins: [editRigthBox],
|
2021-04-22 18:03:56 +08:00
|
|
|
computed: {
|
|
|
|
|
isCurrentUser () {
|
|
|
|
|
return function (username) {
|
|
|
|
|
return localStorage.getItem('nz-username') == username
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
data () {
|
|
|
|
|
const vm = this
|
2021-04-27 20:31:54 +08:00
|
|
|
const validatePin = (rule, value, callback) => { // 确认密码的二次校验
|
2021-04-22 18:03:56 +08:00
|
|
|
if (value === '' && this.editUser.pin) {
|
2021-04-27 20:31:54 +08:00
|
|
|
callback(new Error(this.$t('config.user.inputConfirmPin')))
|
2021-04-22 18:03:56 +08:00
|
|
|
} else if (value !== this.editUser.pin) {
|
2021-04-27 20:31:54 +08:00
|
|
|
callback(new Error(this.$t('config.user.confirmPinErr')))
|
2021-04-22 18:03:56 +08:00
|
|
|
} else {
|
|
|
|
|
callback()
|
|
|
|
|
}
|
2021-06-30 17:11:46 +08:00
|
|
|
}
|
2021-04-22 18:03:56 +08:00
|
|
|
return {
|
|
|
|
|
editUser: {},
|
|
|
|
|
url: 'sys/user',
|
|
|
|
|
rightBox: { model: { show: false } },
|
|
|
|
|
rules: { // 表单校验规则
|
|
|
|
|
name: [
|
|
|
|
|
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
|
|
|
|
|
],
|
|
|
|
|
username: [
|
|
|
|
|
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
|
|
|
|
|
],
|
|
|
|
|
pin: [
|
|
|
|
|
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
|
|
|
|
|
],
|
|
|
|
|
pinChange: [
|
2021-04-27 20:31:54 +08:00
|
|
|
{ validator: validatePin, trigger: 'blur' },
|
2021-04-22 18:03:56 +08:00
|
|
|
{ required: true, message: '', trigger: 'blur' }
|
|
|
|
|
],
|
|
|
|
|
roleIds: [
|
|
|
|
|
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
|
|
|
|
|
],
|
|
|
|
|
email: [
|
|
|
|
|
{ type: 'email', message: this.$t('validate.email') }
|
|
|
|
|
]
|
2021-04-22 17:43:13 +08:00
|
|
|
},
|
2021-04-22 18:03:56 +08:00
|
|
|
rules2: { // 表单校验规则
|
|
|
|
|
username: [
|
|
|
|
|
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
|
|
|
|
|
],
|
|
|
|
|
pinChange: [
|
2021-04-27 20:31:54 +08:00
|
|
|
{ validator: validatePin, trigger: 'blur' }
|
2021-04-22 18:03:56 +08:00
|
|
|
],
|
|
|
|
|
roleIds: [
|
|
|
|
|
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
|
|
|
|
|
],
|
|
|
|
|
email: [
|
|
|
|
|
{ type: 'email', message: this.$t('validate.email') }
|
|
|
|
|
]
|
2021-04-22 17:43:13 +08:00
|
|
|
},
|
2021-04-22 18:03:56 +08:00
|
|
|
roles: []
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
watch: {
|
|
|
|
|
obj: {
|
|
|
|
|
deep: true,
|
|
|
|
|
immediate: true,
|
|
|
|
|
handler (n) {
|
2021-07-15 11:56:25 +08:00
|
|
|
this.isEdit = true
|
2021-04-22 18:03:56 +08:00
|
|
|
this.editUser = JSON.parse(JSON.stringify(n))
|
2021-05-12 17:45:48 +08:00
|
|
|
// if (this.editUser.roles && this.editUser.roles.length > 0) {
|
|
|
|
|
// this.editUser.roleIds = this.editUser.roles.map(t => t.id)
|
|
|
|
|
// }
|
2021-04-22 17:43:13 +08:00
|
|
|
}
|
2021-04-22 18:03:56 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
mounted () {
|
|
|
|
|
this.getRoles()
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
clickOutside () {
|
|
|
|
|
this.esc(false)
|
2021-04-22 17:43:13 +08:00
|
|
|
},
|
2021-04-22 18:03:56 +08:00
|
|
|
/* 关闭弹框 */
|
|
|
|
|
esc (refresh) {
|
|
|
|
|
this.prevent_opt.save = false
|
|
|
|
|
this.$emit('close', refresh)
|
2021-04-22 17:43:13 +08:00
|
|
|
},
|
2021-04-22 18:03:56 +08:00
|
|
|
/* 密码失去焦点 检验确认密码 */
|
2021-04-27 20:31:54 +08:00
|
|
|
pinBlur () {
|
2021-04-22 18:03:56 +08:00
|
|
|
if (this.editUser.pin && this.editUser.pinChange) {
|
2021-04-27 20:31:54 +08:00
|
|
|
this.$refs.accountForm.validateField('pinChange')
|
2021-04-22 18:03:56 +08:00
|
|
|
}
|
2021-04-22 17:43:13 +08:00
|
|
|
},
|
2021-04-22 18:03:56 +08:00
|
|
|
getRoles () {
|
|
|
|
|
this.roles = []
|
|
|
|
|
this.$get('sys/role?pageSize=-1').then(response => {
|
|
|
|
|
if (response.code === 200) {
|
|
|
|
|
this.roles = response.data.list
|
|
|
|
|
} else {
|
|
|
|
|
this.$message.error('load roles faild')
|
2021-04-22 17:43:13 +08:00
|
|
|
}
|
2021-04-22 18:03:56 +08:00
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
save () {
|
|
|
|
|
if (this.prevent_opt.save) { return } ;
|
|
|
|
|
this.prevent_opt.save = true
|
2021-04-22 17:43:13 +08:00
|
|
|
|
2021-04-22 18:03:56 +08:00
|
|
|
this.$refs.userForm.validate((valid) => {
|
|
|
|
|
if (valid) {
|
|
|
|
|
if (this.editUser.id) {
|
|
|
|
|
this.$put(this.url, this.editUser).then(res => {
|
|
|
|
|
this.prevent_opt.save = false
|
|
|
|
|
if (res.code === 200) {
|
|
|
|
|
this.$message({ duration: 2000, type: 'success', message: this.$t('tip.saveSuccess') })
|
|
|
|
|
this.esc(true)
|
|
|
|
|
} else {
|
|
|
|
|
this.$message.error(res.msg)
|
|
|
|
|
}
|
|
|
|
|
})
|
2021-04-22 17:43:13 +08:00
|
|
|
} else {
|
2021-04-22 18:03:56 +08:00
|
|
|
this.$post(this.url, this.editUser).then(res => {
|
|
|
|
|
this.prevent_opt.save = false
|
|
|
|
|
if (res.code === 200) {
|
|
|
|
|
this.$message({ duration: 2000, type: 'success', message: this.$t('tip.saveSuccess') })
|
|
|
|
|
this.esc(true)
|
|
|
|
|
} else {
|
|
|
|
|
this.$message.error(res.msg)
|
|
|
|
|
}
|
|
|
|
|
})
|
2021-04-22 17:43:13 +08:00
|
|
|
}
|
2021-04-22 18:03:56 +08:00
|
|
|
} else {
|
|
|
|
|
this.prevent_opt.save = false
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
})
|
2021-04-22 17:43:13 +08:00
|
|
|
}
|
|
|
|
|
}
|
2021-04-22 18:03:56 +08:00
|
|
|
}
|
2021-04-22 17:43:13 +08:00
|
|
|
</script>
|
|
|
|
|
<style lang="scss">
|
|
|
|
|
@import '@/assets/css/common/rightBoxCommon.scss';
|
|
|
|
|
</style>
|