用户管理

This commit is contained in:
2023-05-24 09:58:48 +08:00
parent ce3e78f13c
commit 59ca5ef790
6 changed files with 614 additions and 534 deletions

View File

@@ -9,7 +9,7 @@
<table>
<tr>
<th>序号</th>
<th>任务号</th>
<th>用户名</th>
<th>姓名</th>
<th>电话</th>
<th>性别</th>
@@ -18,16 +18,16 @@
</tr>
<tr v-for="(e, i) in datalist" :key="i">
<td>{{i+1}}</td>
<td>admin</td>
<td>管理员</td>
<td>18888888888</td>
<td></td>
<td>2023-05-05 08:50:08</td>
<td>{{ e.username }}</td>
<td>{{ e.personName }}</td>
<td>{{ e.phone }}</td>
<td>{{ e.gender }}</td>
<td>{{ e.createTime }}</td>
<td>
<div class="row">
<button class="button button--primary grid_button" @click="showDialog('2')">修改</button>
<button class="button button--primary grid_button" @click="showDialog('3')">重置密码</button>
<button class="button button--primary grid_button" @click="showDialog('4')">删除</button>
<button class="button button--primary grid_button" @click="showDialog('2', e)">修改</button>
<button class="button button--primary grid_button" @click="showDialog('3', e)">重置密码</button>
<button class="button button--primary grid_button" @click="showDialog('4', e)">删除</button>
</div>
</td>
</tr>
@@ -37,6 +37,7 @@
ref="child"
:title="title"
:type="type"
:unclick="unclick"
@toSure="toSureDialog"
>
<div v-if="type === '1' || type === '2'" class="form_wraper">
@@ -87,9 +88,9 @@
<el-select v-model="value" placeholder="请选择">
<el-option
v-for="item in options"
:key="item.value"
:label="item.label"
:value="item.value">
:key="item.roleId"
:label="item.name"
:value="item.roleId">
</el-option>
</el-select>
</div>
@@ -104,36 +105,28 @@
<script>
import jxDialog from '@components/dialog.vue'
import {usersQuery, sysRoleQuery, usersAdd, usersEdit, usersDelete} from '@config/getData2.js'
export default {
components: {
jxDialog
},
data () {
return {
datalist: [{name: ''}, {name: 'a'}, {name: 'a'}, {name: 'a'}, {name: 'a'}, {name: 'a'}, {name: 'a'}],
datalist: [],
active: false,
type: '',
title: '',
username: '',
phone: '',
name: '',
sexArr: [{label: '男', value: '1'}, {label: '女', value: '2'}],
sex: '1',
sexArr: [{label: '男', value: ''}, {label: '女', value: ''}],
sex: '',
password: '',
options: [{
value: '选项1',
label: '超级管理员'
}, {
value: '选项2',
label: '系统管理员'
}, {
value: '选项3',
label: '普通用户'
}, {
value: '选项4',
label: '开发人员'
}],
value: ''
options: [],
value: '',
disabled1: false,
pkObj: {},
unclick: false
}
},
watch: {
@@ -154,33 +147,181 @@ export default {
default:
this.title = ''
}
},
username (val) {
if (this.type === '1' && this.password !== '' && val !== '') {
this.unclick = false
}
if (this.type === '2' && val !== '') {
this.unclick = false
}
},
password (val) {
if (this.type === '1' && this.password !== '' && val !== '') {
this.unclick = false
}
}
},
created () {
this._usersQuery()
this._sysRoleQuery()
},
methods: {
showDialog (type) {
async _usersQuery () {
let res = await usersQuery('0', '100')
this.datalist = [...res]
},
async _sysRoleQuery () {
let res = await sysRoleQuery('0', '100')
this.options = [...res]
},
showDialog (type, e) {
this.type = type
this.$refs.child.active = true
switch (type) {
case '1':
this.username = ''
this.phone = ''
this.name = ''
this.sex = ''
this.password = ''
this.value = ''
this.unclick = true
break
case '2':
this.pkObj = e
this.username = e.username
this.phone = e.phone
this.name = e.personName
this.sex = this.gender
this.options.map(el => {
if (el.roleId === e.roles[0].roleId) {
this.value = el.roleId
}
})
if (this.username && this.password) {
this.unclick = true
}
break
case '3':
this.pkObj = e
this.unclick = false
break
case '4':
this.pkObj = e
this.unclick = false
break
}
},
toSureDialog (type) {
switch (type) {
case '1':
console.log(type)
this._usersAdd()
break
case '2':
console.log(type)
this._usersEdit()
break
case '3':
console.log(type)
this.resetPassword()
break
case '4':
console.log(type)
this._usersDelete()
break
default:
console.log(type)
}
},
toRadio (e) {
this.sex = e.value
},
async _usersAdd () {
this.$refs.child.disabled = true
if (!this.username) {
this.toast('用户名不能为空')
this.$refs.child.disabled = false
return
}
if (!this.password) {
this.toast('密码不能为空')
this.$refs.child.disabled = false
return
}
try {
let rolesIds = []
this.options.map(el => {
if (el.roleId === this.value) {
rolesIds.push(el)
}
})
await usersAdd(this.username, this.name, this.sex, this.phone, rolesIds, this.password)
this.toast('操作成功')
this._usersQuery()
this.$refs.child.active = false
this.$refs.child.disabled = false
} catch (e) {
this.$refs.child.active = false
this.$refs.child.disabled = false
}
},
async _usersEdit () {
this.$refs.child.disabled = true
if (!this.username) {
this.toast('用户名不能为空')
this.$refs.child.disabled = false
return
}
try {
let rolesIds = []
this.options.map(el => {
if (el.roleId === this.value) {
rolesIds.push(el)
}
})
let obj = {
userId: this.pkObj.userId,
username: this.username,
personName: this.name,
gender: this.sex,
phone: this.phone,
rolesIds: rolesIds
}
await usersEdit(obj)
this.toast('操作成功')
this._usersQuery()
this.$refs.child.active = false
this.$refs.child.disabled = false
} catch (e) {
this.$refs.child.active = false
this.$refs.child.disabled = false
}
},
async resetPassword () {
this.$refs.child.disabled = true
try {
let obj = {
userId: this.pkObj.userId,
password: '123456'
}
await usersEdit(obj)
this.toast('操作成功')
this._usersQuery()
this.$refs.child.active = false
this.$refs.child.disabled = false
} catch (e) {
this.$refs.child.active = false
this.$refs.child.disabled = false
}
},
async _usersDelete () {
this.$refs.child.disabled = true
try {
await usersDelete([this.pkObj.userId])
this.toast('操作成功')
this._usersQuery()
this.$refs.child.active = false
this.$refs.child.disabled = false
} catch (e) {
this.$refs.child.active = false
this.$refs.child.disabled = false
}
}
}
}