2023-05-12 13:54:40 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div class="right_side">
|
|
|
|
|
|
<div class="buttons_wrapper">
|
|
|
|
|
|
<div class="row">
|
2023-05-15 17:24:55 +08:00
|
|
|
|
<button class="button button--primary" @click="showDialog('1')">添加用户</button>
|
2023-05-12 13:54:40 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="grid_wrapper">
|
|
|
|
|
|
<table>
|
|
|
|
|
|
<tr>
|
|
|
|
|
|
<th>序号</th>
|
2023-05-24 09:58:48 +08:00
|
|
|
|
<th>用户名</th>
|
2023-05-12 13:54:40 +08:00
|
|
|
|
<th>姓名</th>
|
|
|
|
|
|
<th>电话</th>
|
|
|
|
|
|
<th>性别</th>
|
|
|
|
|
|
<th>创建日期</th>
|
|
|
|
|
|
<th>操作</th>
|
|
|
|
|
|
</tr>
|
|
|
|
|
|
<tr v-for="(e, i) in datalist" :key="i">
|
|
|
|
|
|
<td>{{i+1}}</td>
|
2023-05-24 09:58:48 +08:00
|
|
|
|
<td>{{ e.username }}</td>
|
|
|
|
|
|
<td>{{ e.personName }}</td>
|
|
|
|
|
|
<td>{{ e.phone }}</td>
|
|
|
|
|
|
<td>{{ e.gender }}</td>
|
|
|
|
|
|
<td>{{ e.createTime }}</td>
|
2023-05-12 17:59:29 +08:00
|
|
|
|
<td>
|
|
|
|
|
|
<div class="row">
|
2023-05-24 09:58:48 +08:00
|
|
|
|
<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>
|
2023-05-12 17:59:29 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</td>
|
2023-05-12 13:54:40 +08:00
|
|
|
|
</tr>
|
|
|
|
|
|
</table>
|
|
|
|
|
|
</div>
|
2023-05-12 17:59:29 +08:00
|
|
|
|
<jxDialog
|
2023-05-15 17:24:55 +08:00
|
|
|
|
ref="child"
|
|
|
|
|
|
:title="title"
|
|
|
|
|
|
:type="type"
|
2023-05-24 09:58:48 +08:00
|
|
|
|
:unclick="unclick"
|
2023-05-15 17:24:55 +08:00
|
|
|
|
@toSure="toSureDialog"
|
|
|
|
|
|
>
|
|
|
|
|
|
<div v-if="type === '1' || type === '2'" class="form_wraper">
|
|
|
|
|
|
<div class="form">
|
|
|
|
|
|
<div class="form_item">
|
|
|
|
|
|
<div class="form_item__label"><i>*</i>用户名</div>
|
|
|
|
|
|
<div class="form_item__content">
|
|
|
|
|
|
<input type="text" class="form_item__input" v-model="username">
|
|
|
|
|
|
</div>
|
2023-05-12 17:59:29 +08:00
|
|
|
|
</div>
|
2023-05-15 17:24:55 +08:00
|
|
|
|
<div class="form_item">
|
|
|
|
|
|
<div class="form_item__label">电话</div>
|
|
|
|
|
|
<div class="form_item__content">
|
|
|
|
|
|
<input type="text" class="form_item__input" v-model="phone">
|
|
|
|
|
|
</div>
|
2023-05-12 17:59:29 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2023-05-15 17:24:55 +08:00
|
|
|
|
<div class="form">
|
|
|
|
|
|
<div class="form_item">
|
|
|
|
|
|
<div class="form_item__label">姓名</div>
|
|
|
|
|
|
<div class="form_item__content">
|
|
|
|
|
|
<input type="text" class="form_item__input" v-model="name">
|
2023-05-12 13:54:40 +08:00
|
|
|
|
</div>
|
2023-05-15 17:24:55 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<div class="form_item">
|
|
|
|
|
|
<div class="form_item__label">性别</div>
|
|
|
|
|
|
<div class="form_item__content">
|
|
|
|
|
|
<div class="form_item__radio" v-for="(e, i) in sexArr" :key="i">
|
|
|
|
|
|
<div class="radio__input" :class="{'icon_radio_checked': e.value === sex}" @click="toRadio(e)">
|
|
|
|
|
|
<i class="icon_radio"></i>
|
|
|
|
|
|
<input type="radio" class="radio__original" v-model="e.value">
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="radio__label">{{ e.label }}</div>
|
|
|
|
|
|
</div>
|
2023-05-12 13:54:40 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2023-05-12 17:59:29 +08:00
|
|
|
|
</div>
|
2023-05-15 17:24:55 +08:00
|
|
|
|
<div class="form">
|
|
|
|
|
|
<div v-if="type === '1'" class="form_item">
|
|
|
|
|
|
<div class="form_item__label"><i>*</i>密码</div>
|
|
|
|
|
|
<div class="form_item__content">
|
|
|
|
|
|
<input type="text" class="form_item__input" v-model="password">
|
|
|
|
|
|
</div>
|
2023-05-12 17:59:29 +08:00
|
|
|
|
</div>
|
2023-05-15 17:24:55 +08:00
|
|
|
|
<div class="form_item">
|
|
|
|
|
|
<div class="form_item__label">角色</div>
|
|
|
|
|
|
<div class="form_item__content">
|
|
|
|
|
|
<el-select v-model="value" placeholder="请选择">
|
|
|
|
|
|
<el-option
|
|
|
|
|
|
v-for="item in options"
|
2023-05-24 09:58:48 +08:00
|
|
|
|
:key="item.roleId"
|
|
|
|
|
|
:label="item.name"
|
|
|
|
|
|
:value="item.roleId">
|
2023-05-15 17:24:55 +08:00
|
|
|
|
</el-option>
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
</div>
|
2023-05-12 13:54:40 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2023-05-15 17:24:55 +08:00
|
|
|
|
<div v-if="type === '3'" class="form_wraper">确定重置密码吗?</div>
|
|
|
|
|
|
<div v-if="type === '4'" class="form_wraper">确定删除该用户吗?</div>
|
2023-05-12 17:59:29 +08:00
|
|
|
|
</jxDialog>
|
2023-05-12 13:54:40 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
2023-05-12 17:59:29 +08:00
|
|
|
|
import jxDialog from '@components/dialog.vue'
|
2023-05-24 09:58:48 +08:00
|
|
|
|
import {usersQuery, sysRoleQuery, usersAdd, usersEdit, usersDelete} from '@config/getData2.js'
|
2023-05-12 13:54:40 +08:00
|
|
|
|
export default {
|
2023-05-12 17:59:29 +08:00
|
|
|
|
components: {
|
|
|
|
|
|
jxDialog
|
|
|
|
|
|
},
|
2023-05-12 13:54:40 +08:00
|
|
|
|
data () {
|
|
|
|
|
|
return {
|
2023-05-24 09:58:48 +08:00
|
|
|
|
datalist: [],
|
2023-05-15 17:24:55 +08:00
|
|
|
|
active: false,
|
|
|
|
|
|
type: '',
|
|
|
|
|
|
title: '',
|
|
|
|
|
|
username: '',
|
|
|
|
|
|
phone: '',
|
|
|
|
|
|
name: '',
|
2023-05-24 09:58:48 +08:00
|
|
|
|
sexArr: [{label: '男', value: '男'}, {label: '女', value: '女'}],
|
|
|
|
|
|
sex: '',
|
2023-05-15 17:24:55 +08:00
|
|
|
|
password: '',
|
2023-05-24 09:58:48 +08:00
|
|
|
|
options: [],
|
|
|
|
|
|
value: '',
|
|
|
|
|
|
disabled1: false,
|
|
|
|
|
|
pkObj: {},
|
|
|
|
|
|
unclick: false
|
2023-05-15 17:24:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
watch: {
|
|
|
|
|
|
type (val) {
|
|
|
|
|
|
switch (val) {
|
|
|
|
|
|
case '1':
|
|
|
|
|
|
this.title = '添加用户'
|
|
|
|
|
|
break
|
|
|
|
|
|
case '2':
|
|
|
|
|
|
this.title = '修改用户'
|
|
|
|
|
|
break
|
|
|
|
|
|
case '3':
|
|
|
|
|
|
this.title = ''
|
|
|
|
|
|
break
|
|
|
|
|
|
case '4':
|
|
|
|
|
|
this.title = ''
|
|
|
|
|
|
break
|
|
|
|
|
|
default:
|
|
|
|
|
|
this.title = ''
|
|
|
|
|
|
}
|
2023-05-24 09:58:48 +08:00
|
|
|
|
},
|
|
|
|
|
|
username (val) {
|
2023-05-24 14:43:07 +08:00
|
|
|
|
if (this.type === '1' && (this.password === '' || val === '')) {
|
|
|
|
|
|
this.unclick = true
|
|
|
|
|
|
} else if (this.type === '2' && val === '') {
|
|
|
|
|
|
this.unclick = true
|
|
|
|
|
|
} else {
|
2023-05-24 09:58:48 +08:00
|
|
|
|
this.unclick = false
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
password (val) {
|
2023-05-24 14:43:07 +08:00
|
|
|
|
if (this.type === '1' && (this.password === '' || val === '')) {
|
|
|
|
|
|
this.unclick = true
|
|
|
|
|
|
} else {
|
2023-05-24 09:58:48 +08:00
|
|
|
|
this.unclick = false
|
|
|
|
|
|
}
|
2023-05-12 13:54:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
2023-05-24 09:58:48 +08:00
|
|
|
|
created () {
|
|
|
|
|
|
this._usersQuery()
|
|
|
|
|
|
this._sysRoleQuery()
|
|
|
|
|
|
},
|
2023-05-12 13:54:40 +08:00
|
|
|
|
methods: {
|
2023-05-24 09:58:48 +08:00
|
|
|
|
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) {
|
2023-05-15 17:24:55 +08:00
|
|
|
|
this.type = type
|
|
|
|
|
|
this.$refs.child.active = true
|
2023-05-24 09:58:48 +08:00
|
|
|
|
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
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2023-05-24 14:43:07 +08:00
|
|
|
|
if (this.username === '') {
|
2023-05-24 09:58:48 +08:00
|
|
|
|
this.unclick = true
|
|
|
|
|
|
}
|
|
|
|
|
|
break
|
|
|
|
|
|
case '3':
|
|
|
|
|
|
this.pkObj = e
|
|
|
|
|
|
this.unclick = false
|
|
|
|
|
|
break
|
|
|
|
|
|
case '4':
|
|
|
|
|
|
this.pkObj = e
|
|
|
|
|
|
this.unclick = false
|
|
|
|
|
|
break
|
|
|
|
|
|
}
|
2023-05-15 17:24:55 +08:00
|
|
|
|
},
|
|
|
|
|
|
toSureDialog (type) {
|
|
|
|
|
|
switch (type) {
|
|
|
|
|
|
case '1':
|
2023-05-24 09:58:48 +08:00
|
|
|
|
this._usersAdd()
|
2023-05-15 17:24:55 +08:00
|
|
|
|
break
|
|
|
|
|
|
case '2':
|
2023-05-24 09:58:48 +08:00
|
|
|
|
this._usersEdit()
|
2023-05-15 17:24:55 +08:00
|
|
|
|
break
|
|
|
|
|
|
case '3':
|
2023-05-24 09:58:48 +08:00
|
|
|
|
this.resetPassword()
|
2023-05-15 17:24:55 +08:00
|
|
|
|
break
|
|
|
|
|
|
case '4':
|
2023-05-24 09:58:48 +08:00
|
|
|
|
this._usersDelete()
|
2023-05-15 17:24:55 +08:00
|
|
|
|
break
|
|
|
|
|
|
}
|
2023-05-12 13:54:40 +08:00
|
|
|
|
},
|
2023-05-15 17:24:55 +08:00
|
|
|
|
toRadio (e) {
|
|
|
|
|
|
this.sex = e.value
|
2023-05-24 09:58:48 +08:00
|
|
|
|
},
|
|
|
|
|
|
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
|
|
|
|
|
|
}
|
2023-05-12 13:54:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style lang="stylus" scoped>
|
|
|
|
|
|
@import '~@style/mixin'
|
|
|
|
|
|
.grid_wrapper
|
|
|
|
|
|
height calc(100% - 50px)
|
|
|
|
|
|
overflow-y auto
|
|
|
|
|
|
</style>
|