This commit is contained in:
851673013@qq.com 2022-08-02 17:39:06 +08:00
parent 5a14127977
commit 2bbb2e19cd
1 changed files with 216 additions and 100 deletions

View File

@ -1,40 +1,110 @@
<template> <template>
<el-dialog :visible.sync="visible" :title="!dataForm.id ? $t('add') : $t('update')" :close-on-click-modal="false" :close-on-press-escape="false"> <el-dialog
<el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmitHandle()" label-width="120px"> :visible.sync="visible"
<el-form-item prop="username" :label="$t('user.username')" auto-complete="new-password"> :title="!dataForm.id ? $t('add') : $t('update')"
<el-input v-model="dataForm.username" :placeholder="$t('user.username')" auto-complete="new-password"></el-input> :close-on-click-modal="false"
:close-on-press-escape="false"
>
<el-form
:model="dataForm"
:rules="dataRule"
ref="dataForm"
@keyup.enter.native="dataFormSubmitHandle()"
label-width="120px"
>
<el-form-item
prop="username"
:label="$t('user.username')"
auto-complete="new-password"
>
<el-input
v-model="dataForm.username"
:placeholder="$t('user.username')"
auto-complete="new-password"
></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 prop="password" :label="$t('user.password')" :class="{ 'is-required': !dataForm.id }" auto-complete="new-password" v-if="!dataForm.id"> <el-form-item
<el-input v-model="dataForm.password" type="password" :placeholder="$t('user.password')" auto-complete="new-password" @input="changeInput"></el-input> prop="password"
:label="$t('user.password')"
:class="{ 'is-required': !dataForm.id }"
auto-complete="new-password"
v-if="!dataForm.id"
>
<el-input
v-model="dataForm.password"
type="password"
:placeholder="$t('user.password')"
auto-complete="new-password"
@input="changeInput"
></el-input>
</el-form-item> </el-form-item>
<el-form-item prop="confirmPassword" :label="$t('user.confirmPassword')" :class="{ 'is-required': !dataForm.id }" v-if="!dataForm.id"> <el-form-item
<el-input v-model="dataForm.confirmPassword" type="password" :placeholder="$t('user.confirmPassword')"></el-input> prop="confirmPassword"
:label="$t('user.confirmPassword')"
:class="{ 'is-required': !dataForm.id }"
v-if="!dataForm.id"
>
<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" :label="$t('user.gender')"> <el-form-item prop="gender" :label="$t('user.gender')">
<ren-radio-group v-model="dataForm.gender" dict-type="gender"></ren-radio-group> <ren-radio-group
v-model="dataForm.gender"
dict-type="gender"
></ren-radio-group>
</el-form-item> </el-form-item>
<el-form-item prop="email" :label="$t('user.email')"> <el-form-item prop="email" :label="$t('user.email')">
<el-input v-model="dataForm.email" :placeholder="$t('user.email')"></el-input> <el-input
v-model="dataForm.email"
:placeholder="$t('user.email')"
></el-input>
</el-form-item> </el-form-item>
<el-form-item prop="mobile" :label="$t('user.mobile')"> <el-form-item prop="mobile" :label="$t('user.mobile')">
<el-input v-model="dataForm.mobile" :placeholder="$t('user.mobile')"></el-input> <el-input
v-model="dataForm.mobile"
:placeholder="$t('user.mobile')"
></el-input>
</el-form-item> </el-form-item>
<el-form-item prop="roleIdList" :label="$t('user.roleIdList')" class="role-list"> <el-form-item
<el-select v-model="dataForm.roleIdList" multiple :placeholder="$t('user.roleIdList')"> prop="roleIdList"
<el-option v-for="role in roleList" :key="role.id" :label="role.name" :value="role.id"></el-option> :label="$t('user.roleIdList')"
class="role-list"
>
<el-select
v-model="dataForm.roleIdList"
multiple
:placeholder="$t('user.roleIdList')"
>
<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="postIdList" :label="$t('user.postIdList')" class="role-list"> <!-- 所在岗位屏蔽掉bug729 -->
<!-- <el-form-item prop="postIdList" :label="$t('user.postIdList')" class="role-list">
<el-select v-model="dataForm.postIdList" multiple :placeholder="$t('user.postIdList')"> <el-select v-model="dataForm.postIdList" multiple :placeholder="$t('user.postIdList')">
<el-option v-for="post in postList" :key="post.id" :label="post.postName" :value="post.id"></el-option> <el-option v-for="post in postList" :key="post.id" :label="post.postName" :value="post.id"></el-option>
</el-select> </el-select>
</el-form-item> </el-form-item> -->
<el-form-item prop="status" :label="$t('user.status')" size="mini"> <el-form-item prop="status" :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>
@ -44,7 +114,9 @@
</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" @click="dataFormSubmitHandle()">{{ $t('confirm') }}</el-button> <el-button type="primary" @click="dataFormSubmitHandle()">{{
$t('confirm')
}}</el-button>
</template> </template>
</el-dialog> </el-dialog>
</template> </template>
@ -93,8 +165,22 @@ export default {
const low = /^.*[a-z]+.*/ const low = /^.*[a-z]+.*/
const up = /^.*[A-Z]+.*/ const up = /^.*[A-Z]+.*/
const spe = /^.*[^a-zA-Z0-9]+.*/ const spe = /^.*[^a-zA-Z0-9]+.*/
console.log('包含数字', num.test(value), '包含字母', low.test(value), up.test(value), '包含特殊符号', spe.test(value)) console.log(
if (!(num.test(value) && (low.test(value) || up.test(value)) && spe.test(value))) { '包含数字',
num.test(value),
'包含字母',
low.test(value),
up.test(value),
'包含特殊符号',
spe.test(value)
)
if (
!(
num.test(value) &&
(low.test(value) || up.test(value)) &&
spe.test(value)
)
) {
return callback(new Error(this.$t('validate.pwdStrength'))) return callback(new Error(this.$t('validate.pwdStrength')))
} }
// if (!this.dataForm.id && !/\S/.test(value)) { // if (!this.dataForm.id && !/\S/.test(value)) {
@ -113,38 +199,52 @@ export default {
} }
var validateEmail = (rule, value, callback) => { var validateEmail = (rule, value, callback) => {
if (value && !isEmail(value)) { if (value && !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 (value && !isMobile(value)) { if (value && !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 {
username: [ username: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' } {
required: true,
message: this.$t('validate.required'),
trigger: 'blur'
}
], ],
deptName: [ deptName: [
{ required: true, message: this.$t('validate.required'), trigger: 'change' } {
], required: true,
password: [ message: this.$t('validate.required'),
{ validator: validatePassword, trigger: 'blur' } trigger: 'change'
}
], ],
password: [{ validator: validatePassword, trigger: 'blur' }],
confirmPassword: [ confirmPassword: [
{ validator: validateConfirmPassword, trigger: 'blur' } { validator: validateConfirmPassword, trigger: 'blur' }
], ],
realName: [ realName: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' } {
required: true,
message: this.$t('validate.required'),
trigger: 'blur'
}
], ],
email: [ email: [{ validator: validateEmail, trigger: 'blur' }],
{ validator: validateEmail, trigger: 'blur' } mobile: [{ validator: validateMobile, trigger: 'blur' }]
],
mobile: [
{ validator: validateMobile, trigger: 'blur' }
]
} }
} }
}, },
@ -165,10 +265,7 @@ export default {
this.$nextTick(() => { this.$nextTick(() => {
this.$refs.dataForm.resetFields() this.$refs.dataForm.resetFields()
this.roleIdListDefault = [] this.roleIdListDefault = []
Promise.all([ Promise.all([this.getRoleList(), this.getPostList()]).then(() => {
this.getRoleList(),
this.getPostList()
]).then(() => {
if (this.dataForm.id) { if (this.dataForm.id) {
this.getInfo() this.getInfo()
} else { } else {
@ -193,25 +290,33 @@ export default {
}, },
// //
getRoleList () { getRoleList () {
return this.$http.get('/sys/role/list').then(({ data: res }) => { return this.$http
.get('/sys/role/list')
.then(({ data: res }) => {
if (res.code !== 0) { if (res.code !== 0) {
return this.$message.error(res.msg) return this.$message.error(res.msg)
} }
this.roleList = res.data this.roleList = res.data
}).catch(() => {}) })
.catch(() => {})
}, },
// //
getPostList () { getPostList () {
return this.$http.get('/sys/post/list').then(({ data: res }) => { return this.$http
.get('/sys/post/list')
.then(({ data: res }) => {
if (res.code !== 0) { if (res.code !== 0) {
return this.$message.error(res.msg) return this.$message.error(res.msg)
} }
this.postList = res.data this.postList = res.data
}).catch(() => {}) })
.catch(() => {})
}, },
// //
getInfo () { getInfo () {
this.$http.get(`/sys/user/${this.dataForm.id}`).then(({ data: res }) => { this.$http
.get(`/sys/user/${this.dataForm.id}`)
.then(({ data: res }) => {
if (res.code !== 0) { if (res.code !== 0) {
return this.$message.error(res.msg) return this.$message.error(res.msg)
} }
@ -222,16 +327,22 @@ export default {
} }
// , // ,
for (var i = 0; i < res.data.roleIdList.length; i++) { for (var i = 0; i < res.data.roleIdList.length; i++) {
if (this.roleList.filter(item => item.id === res.data.roleIdList[i])[0]) { if (
this.roleList.filter(
(item) => item.id === res.data.roleIdList[i]
)[0]
) {
this.dataForm.roleIdList.push(res.data.roleIdList[i]) this.dataForm.roleIdList.push(res.data.roleIdList[i])
continue continue
} }
this.roleIdListDefault.push(res.data.roleIdList[i]) this.roleIdListDefault.push(res.data.roleIdList[i])
} }
}).catch(() => {}) })
.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
@ -248,7 +359,8 @@ export default {
...this.dataForm.roleIdList, ...this.dataForm.roleIdList,
...this.roleIdListDefault ...this.roleIdListDefault
] ]
}).then(({ data: res }) => { })
.then(({ data: res }) => {
if (res.code !== 0) { if (res.code !== 0) {
return this.$message.error(res.msg) return this.$message.error(res.msg)
} }
@ -262,10 +374,14 @@ export default {
} }
}) })
this.submitFlag = true this.submitFlag = true
}).catch(() => {}) })
.catch(() => {})
} }
}) })
}, 1000, { leading: true, trailing: false }) },
1000,
{ leading: true, trailing: false }
)
} }
} }
</script> </script>