Skip to content

Commit fcacbac

Browse files
authored
refactor(user): upgrade user management page (#415)
re #414
1 parent bedf71a commit fcacbac

9 files changed

Lines changed: 151 additions & 196 deletions

File tree

src/lin/model/admin.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ export default class Admin {
3535
return get('cms/admin/permission')
3636
}
3737

38-
static async getAdminUsers({ groupID, count = this.uCount, page = this.uPage }) {
38+
static async getAdminUsers({ groupId, count = this.uCount, page = this.uPage }) {
3939
let res
40-
if (groupID) {
40+
if (groupId) {
4141
res = await get('cms/admin/users', {
4242
count,
4343
page,
44-
group_id: groupID,
44+
group_id: groupId,
4545
})
4646
} else {
4747
res = await get('cms/admin/users', {

src/lin/model/user.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default class User {
1515
email: user.email,
1616
username: user.username,
1717
password: user.password,
18+
group_ids: user.groupIds,
1819
confirm_password: user.confirmPassword,
1920
},
2021
handleError: true,

src/view/admin/group/group-list.vue

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
<!-- 列表页面 -->
33
<div class="container">
44
<div class="title">分组列表信息</div>
5-
<lin-table
6-
:tableColumn="tableColumn"
7-
:tableData="tableData"
8-
:operate="operate"
9-
@handleEdit="handleEdit"
10-
@goToGroupEditPage="goToGroupEditPage"
11-
@handleDelete="handleDelete"
12-
@row-click="rowClick"
13-
v-loading="loading"
14-
>
15-
</lin-table>
5+
<el-table :data="tableData" v-loading="loading">
6+
<el-table-column prop="name" label="名称"></el-table-column>
7+
<el-table-column prop="info" label="分组描述"></el-table-column>
8+
<el-table-column label="操作" fixed="right" width="275">
9+
<template #default="scope">
10+
<el-button plain size="mini" type="primary" @click="handleEdit(scope.row.id)">信息</el-button>
11+
<el-button plain size="mini" type="info" @click="goToGroupEditPage(scope.row.id)">权限</el-button>
12+
<el-button plain size="mini" type="danger" @click="handleDelete(scope.row.id)">删除</el-button>
13+
</template>
14+
</el-table-column>
15+
</el-table>
1616
<el-dialog
1717
title="分组信息"
1818
:append-to-body="true"
@@ -39,7 +39,7 @@
3939
</el-form-item>
4040
</el-form>
4141
</div>
42-
<template v-slot:footer>
42+
<template #footer>
4343
<div class="dialog-footer" style="padding-left:5px;">
4444
<el-button type="primary" @click="confirmEdit">确 定</el-button>
4545
<el-button @click="resetForm('form')">重 置</el-button>
@@ -50,25 +50,10 @@
5050
</template>
5151

5252
<script>
53-
import LinTable from '@/component/base/table/lin-table'
5453
import { useGroupList, useEditGroup } from './hook'
5554
5655
export default {
57-
components: {
58-
LinTable,
59-
},
6056
setup(props, ctx) {
61-
// originally data properties
62-
const tableColumn = [
63-
{ prop: 'name', label: '名称' },
64-
{ prop: 'info', label: '分组描述' },
65-
]
66-
const operate = [
67-
{ name: '信息', func: 'handleEdit', type: 'primary' },
68-
{ name: '权限', func: 'goToGroupEditPage', type: 'info' },
69-
{ name: '删除', func: 'handleDelete', type: 'danger' },
70-
]
71-
7257
/**
7358
* 分组列表所需数据
7459
*/
@@ -102,13 +87,11 @@ export default {
10287
id,
10388
rules,
10489
group,
105-
operate,
10690
loading,
10791
rowClick,
10892
tableData,
10993
resetForm,
11094
handleEdit,
111-
tableColumn,
11295
confirmEdit,
11396
handleClose,
11497
handleDelete,
Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { ref, onMounted } from 'vue'
22
import AdminModel from '@/lin/model/admin'
33

44
export const useUserList = () => {
5-
const groups = ref([])
5+
const allGroups = ref([])
66
const pageCount = ref(10) // 每页10条数据
77
const tableData = ref([])
8-
const groupID = ref(null)
8+
const groupId = ref(null)
99
const loading = ref(false)
1010
const totalNum = ref(0) // 分组内的用户总数
1111
const currentPage = ref(1) // 默认获取第一页的数据
@@ -14,11 +14,11 @@ export const useUserList = () => {
1414
* 获取管理员列表数据
1515
*/
1616
const getAdminUsers = async () => {
17-
let res
17+
let res = {}
1818
try {
1919
loading.value = true
2020
res = await AdminModel.getAdminUsers({
21-
groupID: groupID.value,
21+
groupId: groupId.value,
2222
count: pageCount.value,
2323
page: currentPage.value - 1,
2424
})
@@ -37,7 +37,7 @@ export const useUserList = () => {
3737
const getAllGroups = async () => {
3838
try {
3939
loading.value = true
40-
groups.value = await AdminModel.getAllGroups()
40+
allGroups.value = await AdminModel.getAllGroups()
4141
loading.value = false
4242
} catch (e) {
4343
loading.value = false
@@ -46,16 +46,12 @@ export const useUserList = () => {
4646
}
4747

4848
/**
49-
* 多分组用 ',' 分割展示
49+
* 多分组用 '' 分割展示
5050
*/
5151
const shuffleList = users => {
5252
const list = []
5353
users.forEach(element => {
54-
const userGroups = []
55-
element.groups.forEach(item => {
56-
userGroups.push(item.name)
57-
})
58-
element.groupNames = userGroups.join(',')
54+
element.groupNames = element.groups.map(item => item.name).join(',')
5955
list.push(element)
6056
})
6157
return list
@@ -67,18 +63,18 @@ export const useUserList = () => {
6763
})
6864

6965
return {
70-
groups,
71-
groupID,
66+
groupId,
7267
loading,
7368
totalNum,
69+
allGroups,
7470
pageCount,
7571
tableData,
7672
currentPage,
7773
getAdminUsers,
7874
}
7975
}
8076

81-
export const useFormData = (ctx, dialogFormVisible, getAdminUsers, currentPage, loading) => {
77+
export const useFormData = (ctx, dialogFormVisible, getAdminUsers, currentPage, loading, info, password) => {
8278
const id = ref(null)
8379
const activeTab = ref('修改信息')
8480

@@ -113,13 +109,6 @@ export const useFormData = (ctx, dialogFormVisible, getAdminUsers, currentPage,
113109
}
114110
}
115111

116-
/**
117-
* 切换弹窗Tab栏
118-
*/
119-
const handleClick = tab => {
120-
activeTab.value = tab.name
121-
}
122-
123112
/**
124113
* 翻页
125114
*/
@@ -133,9 +122,9 @@ export const useFormData = (ctx, dialogFormVisible, getAdminUsers, currentPage,
133122
*/
134123
const confirmEdit = async () => {
135124
if (activeTab.value === '修改信息') {
136-
await ctx.refs.userInfo.submitForm('form')
125+
await info.value.submitForm()
137126
} else {
138-
await ctx.refs.password.submitForm('form')
127+
await password.value.submitForm()
139128
}
140129
}
141130

@@ -147,14 +136,18 @@ export const useFormData = (ctx, dialogFormVisible, getAdminUsers, currentPage,
147136
done()
148137
}
149138

139+
const handleClick = tab => {
140+
activeTab.value = tab.props.name
141+
}
142+
150143
/**
151144
* 重置表单
152145
*/
153146
const resetForm = () => {
154147
if (activeTab.value === '修改信息') {
155-
ctx.refs.userInfo.resetForm('form')
148+
info.value.resetForm()
156149
} else {
157-
ctx.refs.password.resetForm('form')
150+
password.value.resetForm()
158151
}
159152
}
160153

src/view/admin/user/user-create.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div class="container">
33
<div class="title">新建用户</div>
4-
<div class="wrap"><user-info :groups="groups" /></div>
4+
<div class="wrap"><user-info :allGroups="allGroups" /></div>
55
</div>
66
</template>
77

@@ -15,13 +15,13 @@ export default {
1515
UserInfo,
1616
},
1717
setup() {
18-
const groups = ref([])
18+
const allGroups = ref([])
1919
const loading = ref(false)
2020
2121
onMounted(async () => {
2222
try {
2323
loading.value = true
24-
groups.value = await Admin.getAllGroups()
24+
allGroups.value = await Admin.getAllGroups()
2525
loading.value = false
2626
} catch (e) {
2727
loading.value = false
@@ -30,8 +30,8 @@ export default {
3030
})
3131
3232
return {
33-
groups,
3433
loading,
34+
allGroups,
3535
}
3636
},
3737
}

0 commit comments

Comments
 (0)