2023-05-06 15:58:45 +08:00
|
|
|
<template>
|
|
|
|
<a-card :bordered="false">
|
2023-05-12 17:32:51 +08:00
|
|
|
<!-- 搜索栏 -->
|
2023-05-11 20:19:02 +08:00
|
|
|
<search-form :items="formItems" v-model="queryParam" @search="searchQuery">
|
|
|
|
<a-space style="float: right" class="btn-group" slot="additional">
|
|
|
|
<a-button @click="handleAdd" type="primary">
|
|
|
|
<img src="@/assets/images/global/add.png" alt="" />
|
|
|
|
Add
|
2023-05-06 15:58:45 +08:00
|
|
|
</a-button>
|
2023-05-12 17:32:51 +08:00
|
|
|
<a-button @click="handleEdit" type="primary">
|
2023-05-11 20:19:02 +08:00
|
|
|
<img src="@/assets/images/global/edit.png" alt="" />
|
|
|
|
Edit
|
|
|
|
</a-button>
|
2023-05-12 17:32:51 +08:00
|
|
|
<a-button @click="onDel" type="primary">
|
2023-05-11 20:19:02 +08:00
|
|
|
<img src="@/assets/images/global/delete.png" alt="" />
|
|
|
|
Delete
|
|
|
|
</a-button>
|
2023-05-12 17:32:51 +08:00
|
|
|
<a-button @click="handleReset" type="primary">
|
2023-05-11 20:19:02 +08:00
|
|
|
<img src="@/assets/images/global/reset-pwd.png" alt="" />
|
|
|
|
Reset pwd
|
|
|
|
</a-button>
|
|
|
|
</a-space>
|
|
|
|
</search-form>
|
2023-05-12 17:32:51 +08:00
|
|
|
<!-- 搜索栏结束 -->
|
|
|
|
<!-- 列表 -->
|
2023-05-06 15:58:45 +08:00
|
|
|
<div>
|
2023-05-12 17:32:51 +08:00
|
|
|
<custom-table
|
2023-05-06 15:58:45 +08:00
|
|
|
size="middle"
|
|
|
|
rowKey="id"
|
|
|
|
:columns="columns"
|
2023-05-12 17:32:51 +08:00
|
|
|
:list="dataSource"
|
2023-05-06 15:58:45 +08:00
|
|
|
:pagination="ipagination"
|
|
|
|
:loading="loading"
|
2023-05-11 20:19:02 +08:00
|
|
|
@change="handleTableChange"
|
2023-05-12 17:32:51 +08:00
|
|
|
:selectedRowKeys.sync="selectedRowKeys"
|
2023-05-16 09:08:13 +08:00
|
|
|
:scroll="{ y: 'calc(100vh - 365px)' }"
|
2023-05-11 20:19:02 +08:00
|
|
|
>
|
2023-05-12 17:32:51 +08:00
|
|
|
<template slot="index" slot-scope="{ index }">
|
2023-05-11 20:19:02 +08:00
|
|
|
{{ index + 1 }}
|
2023-05-06 15:58:45 +08:00
|
|
|
</template>
|
2023-05-16 09:08:13 +08:00
|
|
|
<template slot="roles" slot-scope="{ text }">
|
|
|
|
<span v-for="role of text" :key="role.id">
|
|
|
|
{{ role.roleName }}
|
|
|
|
</span>
|
|
|
|
</template>
|
2023-05-12 17:32:51 +08:00
|
|
|
</custom-table>
|
2023-05-06 15:58:45 +08:00
|
|
|
</div>
|
2023-05-12 17:32:51 +08:00
|
|
|
<!-- 列表结束 -->
|
|
|
|
<!-- 新增/编辑 账号 -->
|
|
|
|
<custom-modal :title="isAdd ? 'Add' : 'Edit'" v-model="visible" :width="475" :okHandler="onSubmit">
|
|
|
|
<a-form-model
|
|
|
|
ref="form"
|
|
|
|
layout="horizontal"
|
|
|
|
:model="accountModel"
|
|
|
|
:rules="rules"
|
|
|
|
:labelCol="{ style: { width: '80px' } }"
|
|
|
|
:wrapperCol="{ style: { width: '300px' } }"
|
|
|
|
autocomplete="off"
|
2023-05-16 09:08:13 +08:00
|
|
|
:colon="false"
|
2023-05-12 17:32:51 +08:00
|
|
|
>
|
|
|
|
<a-form-model-item label="User" prop="username">
|
|
|
|
<a-input v-model="accountModel.username"></a-input>
|
|
|
|
</a-form-model-item>
|
|
|
|
<a-form-model-item label="Name">
|
|
|
|
<a-input type="text" v-model="accountModel.realname"></a-input>
|
|
|
|
</a-form-model-item>
|
2023-05-16 10:07:58 +08:00
|
|
|
<a-form-model-item label="Role" prop="selectedRoles">
|
2023-05-16 09:08:13 +08:00
|
|
|
<custom-select :options="roleOptions" mode="multiple" v-model="accountModel.selectedRoles"></custom-select>
|
2023-05-12 17:32:51 +08:00
|
|
|
</a-form-model-item>
|
|
|
|
<a-form-model-item label="E-Mail">
|
|
|
|
<a-input v-model="accountModel.email"></a-input>
|
|
|
|
</a-form-model-item>
|
|
|
|
<a-form-model-item label="Phone">
|
|
|
|
<a-input v-model="accountModel.phone"></a-input>
|
|
|
|
</a-form-model-item>
|
|
|
|
</a-form-model>
|
|
|
|
</custom-modal>
|
|
|
|
<!-- 新增/编辑 账号结束 -->
|
2023-05-06 15:58:45 +08:00
|
|
|
</a-card>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-05-11 20:19:02 +08:00
|
|
|
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
|
2023-05-12 17:32:51 +08:00
|
|
|
import { queryall, addUser, editUser, changePassword } from '@/api/api'
|
|
|
|
import { cloneDeep } from 'lodash'
|
|
|
|
import FormMixin from '@/mixins/FormMixin'
|
2023-05-11 20:19:02 +08:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'UserList',
|
2023-05-12 17:32:51 +08:00
|
|
|
mixins: [JeecgListMixin, FormMixin],
|
2023-05-11 20:19:02 +08:00
|
|
|
data() {
|
|
|
|
return {
|
2023-05-12 17:32:51 +08:00
|
|
|
queryParam: {
|
|
|
|
role: undefined
|
|
|
|
},
|
2023-05-11 20:19:02 +08:00
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
title: 'NO',
|
|
|
|
align: 'center',
|
|
|
|
width: 100,
|
|
|
|
scopedSlots: {
|
|
|
|
customRender: 'index'
|
2023-05-06 15:58:45 +08:00
|
|
|
}
|
2023-05-11 20:19:02 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'USER',
|
|
|
|
align: 'center',
|
|
|
|
dataIndex: 'username',
|
|
|
|
width: 100
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'NAME',
|
|
|
|
align: 'center',
|
|
|
|
width: 100,
|
|
|
|
dataIndex: 'realname'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'ROLE',
|
|
|
|
align: 'center',
|
|
|
|
width: 100,
|
2023-05-16 09:08:13 +08:00
|
|
|
dataIndex: 'roles',
|
|
|
|
scopedSlots: {
|
|
|
|
customRender: 'roles'
|
|
|
|
}
|
2023-05-11 20:19:02 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'PHONE',
|
|
|
|
align: 'center',
|
|
|
|
width: 100,
|
|
|
|
dataIndex: 'phone'
|
2023-05-06 15:58:45 +08:00
|
|
|
}
|
2023-05-11 20:19:02 +08:00
|
|
|
],
|
|
|
|
url: {
|
|
|
|
list: '/sys/user/list',
|
|
|
|
delete: '/sys/user/delete'
|
2023-05-12 17:32:51 +08:00
|
|
|
},
|
|
|
|
roleOptions: [],
|
|
|
|
visible: false,
|
|
|
|
isAdd: false,
|
|
|
|
accountModel: {},
|
|
|
|
rules: {
|
2023-05-16 10:07:58 +08:00
|
|
|
username: [{ required: true, message: 'Please Enter User' }],
|
|
|
|
selectedRoles: [{ required: true, message: 'Please Select Role' , trigger: 'change' }],
|
2023-05-11 20:19:02 +08:00
|
|
|
}
|
2023-05-06 15:58:45 +08:00
|
|
|
}
|
2023-05-11 20:19:02 +08:00
|
|
|
},
|
2023-05-12 17:32:51 +08:00
|
|
|
created() {
|
|
|
|
this.getRoles()
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
customRow(record) {
|
|
|
|
return {
|
|
|
|
class: this.selectedRowKeys.includes(record.id) ? 'ant-table-row-selected' : '',
|
|
|
|
on: {
|
|
|
|
click: () => {
|
|
|
|
if (this.selectedRowKeys.includes(record.id)) {
|
|
|
|
this.selectedRowKeys = []
|
|
|
|
} else {
|
|
|
|
this.selectedRowKeys = [record.id]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
async getRoles() {
|
|
|
|
try {
|
|
|
|
const res = await queryall()
|
|
|
|
if (res.success) {
|
|
|
|
this.roleOptions = res.result.map(item => {
|
|
|
|
return {
|
|
|
|
label: item.roleName,
|
|
|
|
value: item.id
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
handleAdd() {
|
|
|
|
this.visible = true
|
|
|
|
this.isAdd = true
|
|
|
|
this.accountModel = {}
|
|
|
|
},
|
|
|
|
handleEdit() {
|
|
|
|
if (this.selectedRowKeys && this.selectedRowKeys.length) {
|
|
|
|
this.visible = true
|
|
|
|
this.isAdd = false
|
|
|
|
const find = this.dataSource.find(item => item.id === this.selectedRowKeys[0])
|
|
|
|
this.accountModel = cloneDeep(find)
|
2023-05-16 09:08:13 +08:00
|
|
|
this.accountModel.selectedRoles = this.accountModel.roles.map(role => role.id)
|
2023-05-12 17:32:51 +08:00
|
|
|
} else {
|
2023-05-16 09:08:13 +08:00
|
|
|
this.$message.warn('Please Select An Item To Edit')
|
2023-05-12 17:32:51 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// 提交
|
|
|
|
async onSubmit() {
|
|
|
|
await this.$refs.form.validate()
|
|
|
|
const request = this.isAdd ? addUser : editUser
|
2023-05-16 09:08:13 +08:00
|
|
|
const selectedroles = this.accountModel.selectedRoles.join(',')
|
|
|
|
const { success, message } = await request(Object.assign({ selectedroles }, this.accountModel))
|
2023-05-12 17:32:51 +08:00
|
|
|
if (success) {
|
|
|
|
this.$message.success(`${this.isAdd ? 'Add' : 'Edit'} Success`)
|
|
|
|
this.loadData()
|
|
|
|
} else {
|
|
|
|
this.$message.error(`${this.isAdd ? 'Add' : 'Edit'} Fail`)
|
|
|
|
throw new Error(message)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onDel() {
|
|
|
|
if (this.selectedRowKeys && this.selectedRowKeys.length) {
|
|
|
|
this.$confirm({
|
2023-05-16 09:08:13 +08:00
|
|
|
title: 'Do You Want To Delete This Item?',
|
2023-05-12 17:32:51 +08:00
|
|
|
okText: 'OK',
|
|
|
|
cancelText: 'Cancel',
|
|
|
|
onOk: () => {
|
|
|
|
this.handleDelete(this.selectedRowKeys[0])
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} else {
|
2023-05-16 09:08:13 +08:00
|
|
|
this.$message.warn('Please Select An Item To Delete')
|
2023-05-12 17:32:51 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
handleReset() {
|
|
|
|
if (this.selectedRowKeys && this.selectedRowKeys.length) {
|
|
|
|
const find = this.dataSource.find(item => item.id === this.selectedRowKeys[0])
|
|
|
|
this.$confirm({
|
2023-05-16 09:08:13 +08:00
|
|
|
title: 'Do You Want To Reset Password?',
|
2023-05-12 17:32:51 +08:00
|
|
|
okText: 'OK',
|
|
|
|
cancelText: 'Cancel',
|
|
|
|
onOk: async () => {
|
|
|
|
const { success, message } = await changePassword({
|
|
|
|
username: find.username
|
|
|
|
})
|
2023-05-16 09:08:13 +08:00
|
|
|
if (success) {
|
2023-05-12 17:32:51 +08:00
|
|
|
this.$message.success('Reset Success')
|
2023-05-16 09:08:13 +08:00
|
|
|
} else {
|
2023-05-12 17:32:51 +08:00
|
|
|
this.$message.error('Reset Fail')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} else {
|
2023-05-16 09:08:13 +08:00
|
|
|
this.$message.warn('Please Select An Item To Reset')
|
2023-05-12 17:32:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
formItems() {
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
type: 'a-input',
|
|
|
|
label: 'User',
|
|
|
|
name: 'username',
|
|
|
|
span: 4
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'a-input',
|
|
|
|
label: 'Name',
|
|
|
|
name: 'realname',
|
|
|
|
span: 4
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'custom-select',
|
|
|
|
label: 'Role',
|
|
|
|
name: 'role',
|
|
|
|
span: 4,
|
|
|
|
props: {
|
|
|
|
options: this.roleOptions
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2023-05-11 20:19:02 +08:00
|
|
|
}
|
2023-05-06 15:58:45 +08:00
|
|
|
</script>
|
2023-05-11 20:19:02 +08:00
|
|
|
<style scoped lang="less">
|
|
|
|
@import '~@assets/less/common.less';
|
|
|
|
.btn-group {
|
|
|
|
img {
|
|
|
|
margin-right: 12px;
|
|
|
|
height: 18px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|