Skip to content

Commit c4bf19c

Browse files
committed
refactor: user manage add filter
1 parent a26c432 commit c4bf19c

File tree

4 files changed

+123
-71
lines changed

4 files changed

+123
-71
lines changed

ui/src/api/system/chat-user.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { Result } from '@/request/Result'
2-
import { get, put, post, del } from '@/request/index'
3-
import type { pageRequest, PageList } from '@/api/type/common'
4-
import type { ChatUserItem } from '@/api/type/systemChatUser'
5-
import type { Ref } from 'vue'
1+
import {Result} from '@/request/Result'
2+
import {get, put, post, del} from '@/request/index'
3+
import type {pageRequest, PageList} from '@/api/type/common'
4+
import type {ChatUserItem} from '@/api/type/systemChatUser'
5+
import type {Ref} from 'vue'
6+
67
const prefix = '/system/chat_user'
78

89

@@ -20,12 +21,12 @@ const getChatUserList: (loading?: Ref<boolean>) => Promise<Result<ChatUserItem[]
2021
*/
2122
const getUserManage: (
2223
page: pageRequest,
23-
username_or_nickname: string,
24+
params?: any,
2425
loading?: Ref<boolean>,
25-
) => Promise<Result<PageList<ChatUserItem[]>>> = (page, username_or_nickname, loading) => {
26+
) => Promise<Result<PageList<ChatUserItem[]>>> = (page, params, loading) => {
2627
return get(
2728
`${prefix}/user_manage/${page.current_page}/${page.page_size}`,
28-
username_or_nickname ? { username_or_nickname } : undefined,
29+
params ? params : undefined,
2930
loading,
3031
)
3132
}

ui/src/api/system/user-manage.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ const prefix = '/user_manage'
1212
*/
1313
const getUserManage: (
1414
page: pageRequest,
15-
email_or_username: string,
15+
params?: any,
1616
loading?: Ref<boolean>,
17-
) => Promise<Result<any>> = (page, email_or_username, loading) => {
17+
) => Promise<Result<any>> = (page, params, loading) => {
1818
return get(
1919
`${prefix}/${page.current_page}/${page.page_size}`,
20-
email_or_username ? {email_or_username} : undefined,
20+
params ? params : undefined,
2121
loading,
2222
)
2323
}

ui/src/views/system-chat-user/user-manage/index.vue

Lines changed: 77 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<div class="flex-between mb-16">
1515
<div>
1616
<el-button type="primary" @click="createUser()"
17-
v-hasPermission="new ComplexPermission([RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE.getWorkspaceRole, RoleConst.USER.getWorkspaceRole,],
17+
v-hasPermission="new ComplexPermission([RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE.getWorkspaceRole, RoleConst.USER.getWorkspaceRole,],
1818
[PermissionConst.WORKSPACE_CHAT_USER_CREATE.getWorkspacePermission],[],'OR')"
1919
>
2020
{{ t('views.userManage.createUser') }}
@@ -23,38 +23,46 @@
2323
{{ $t('views.chatUser.syncUsers') }}
2424
</el-button>
2525
<el-button :disabled="multipleSelection.length === 0" @click="setUserGroups"
26-
v-hasPermission="new ComplexPermission([RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE.getWorkspaceRole, RoleConst.USER.getWorkspaceRole,],
26+
v-hasPermission="new ComplexPermission([RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE.getWorkspaceRole, RoleConst.USER.getWorkspaceRole,],
2727
[PermissionConst.WORKSPACE_CHAT_USER_GROUP.getWorkspacePermission],[],'OR')"
2828
>
2929
{{ $t('views.chatUser.setUserGroups') }}
3030
</el-button>
3131
<el-button :disabled="multipleSelection.length === 0" @click="handleBatchDelete"
32-
v-hasPermission="new ComplexPermission([RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE.getWorkspaceRole, RoleConst.USER.getWorkspaceRole,],
32+
v-hasPermission="new ComplexPermission([RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE.getWorkspaceRole, RoleConst.USER.getWorkspaceRole,],
3333
[PermissionConst.WORKSPACE_CHAT_USER_DELETE.getWorkspacePermission],[],'OR')"
3434
>
3535
{{ $t('common.delete') }}
3636
</el-button>
3737
</div>
3838
<div class="flex-between complex-search">
3939
<el-select class="complex-search__left" v-model="search_type" style="width: 120px"
40-
@change="search_type_change">
41-
<el-option :label="$t('views.login.loginForm.username.label')" value="name" />
40+
@change="search_type_change">
41+
<el-option :label="$t('views.login.loginForm.username.label')" value="username"/>
42+
<el-option :label="$t('views.userManage.userForm.nick_name.label')"
43+
value="nick_name"/>
4244
</el-select>
43-
<el-input v-if="search_type === 'name'" v-model="search_form.name" @change="getList"
44-
:placeholder="$t('common.searchBar.placeholder')" style="width: 220px" clearable />
45+
<el-input v-if="search_type === 'username'" v-model="search_form.username"
46+
@change="getList"
47+
style="width: 220px"
48+
clearable/>
49+
<el-input v-if="search_type === 'nick_name'" v-model="search_form.nick_name"
50+
@change="getList"
51+
style="width: 220px" clearable/>
4552
</div>
4653
</div>
4754
<app-table class="mt-16" :data="userTableData" :pagination-config="paginationConfig"
48-
@sizeChange="handleSizeChange" @changePage="getList" v-loading="loading"
49-
@selection-change="handleSelectionChange" @sort-change="handleSortChange">
50-
<el-table-column type="selection" width="55" />
51-
<el-table-column prop="nick_name" :label="$t('views.userManage.userForm.nick_name.label')" />
52-
<el-table-column prop="username" :label="$t('common.username')" />
55+
@sizeChange="handleSizeChange" @changePage="getList" v-loading="loading"
56+
@selection-change="handleSelectionChange" @sort-change="handleSortChange">
57+
<el-table-column type="selection" width="55"/>
58+
<el-table-column prop="nick_name"
59+
:label="$t('views.userManage.userForm.nick_name.label')"/>
60+
<el-table-column prop="username" :label="$t('common.username')"/>
5361
<el-table-column prop="is_active" :label="$t('common.status.label')">
5462
<template #default="{ row }">
5563
<div v-if="row.is_active" class="flex align-center">
5664
<el-icon class="color-success mr-8" style="font-size: 16px">
57-
<SuccessFilled />
65+
<SuccessFilled/>
5866
</el-icon>
5967
<span class="color-secondary">
6068
{{ $t('common.status.enabled') }}
@@ -69,7 +77,8 @@
6977
</template>
7078
</el-table-column>
7179

72-
<el-table-column prop="email" :label="$t('views.login.loginForm.email.label')" show-overflow-tooltip>
80+
<el-table-column prop="email" :label="$t('views.login.loginForm.email.label')"
81+
show-overflow-tooltip>
7382
<template #default="{ row }">
7483
{{ row.email || '-' }}
7584
</template>
@@ -79,9 +88,10 @@
7988
{{ row.phone || '-' }}
8089
</template>
8190
</el-table-column>
82-
<el-table-column prop="user_group_names" :label="$t('views.chatUser.group.title')" min-width="100">
91+
<el-table-column prop="user_group_names" :label="$t('views.chatUser.group.title')"
92+
min-width="100">
8393
<template #default="{ row }">
84-
<TagGroup :tags="row.user_group_names" />
94+
<TagGroup :tags="row.user_group_names"/>
8595
</template>
8696
</el-table-column>
8797
<el-table-column prop="source" :label="$t('views.userManage.source.label')">
@@ -111,39 +121,42 @@
111121
<el-table-column :label="$t('common.operation')" width="160" align="left" fixed="right">
112122
<template #default="{ row }">
113123
<span @click.stop>
114-
<el-switch size="small" v-model="row.is_active" :before-change="() => changeState(row)" />
124+
<el-switch size="small" v-model="row.is_active"
125+
:before-change="() => changeState(row)"/>
115126
</span>
116-
<el-divider direction="vertical" />
127+
<el-divider direction="vertical"/>
117128
<span class="mr-8">
118-
<el-button type="primary" text @click.stop="editUser(row)" :title="$t('common.edit')"
119-
v-hasPermission="new ComplexPermission([RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE.getWorkspaceRole, RoleConst.USER.getWorkspaceRole,],
129+
<el-button type="primary" text @click.stop="editUser(row)"
130+
:title="$t('common.edit')"
131+
v-hasPermission="new ComplexPermission([RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE.getWorkspaceRole, RoleConst.USER.getWorkspaceRole,],
120132
[PermissionConst.WORKSPACE_CHAT_USER_EDIT.getWorkspacePermission],[],'OR')"
121133
>
122134
<el-icon>
123-
<EditPen />
135+
<EditPen/>
124136
</el-icon>
125137
</el-button>
126138
</span>
127139

128140
<span class="mr-8">
129141
<el-button type="primary" text @click.stop="editPwdUser(row)"
130-
:title="$t('views.userManage.setting.updatePwd')"
131-
v-hasPermission="new ComplexPermission([RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE.getWorkspaceRole, RoleConst.USER.getWorkspaceRole,],
142+
:title="$t('views.userManage.setting.updatePwd')"
143+
v-hasPermission="new ComplexPermission([RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE.getWorkspaceRole, RoleConst.USER.getWorkspaceRole,],
132144
[PermissionConst.WORKSPACE_CHAT_USER_EDIT.getWorkspacePermission],[],'OR')"
133-
>
145+
>
134146
<el-icon>
135-
<Lock />
147+
<Lock/>
136148
</el-icon>
137149
</el-button>
138150
</span>
139151
<span>
140-
<el-button :disabled="row.role === 'ADMIN'" type="primary" text @click.stop="deleteUserManage(row)"
141-
:title="$t('common.delete')"
142-
v-hasPermission="new ComplexPermission([RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE.getWorkspaceRole, RoleConst.USER.getWorkspaceRole,],
152+
<el-button :disabled="row.role === 'ADMIN'" type="primary" text
153+
@click.stop="deleteUserManage(row)"
154+
:title="$t('common.delete')"
155+
v-hasPermission="new ComplexPermission([RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE.getWorkspaceRole, RoleConst.USER.getWorkspaceRole,],
143156
[PermissionConst.WORKSPACE_CHAT_USER_DELETE.getWorkspacePermission],[],'OR')"
144-
>
157+
>
145158
<el-icon>
146-
<Delete />
159+
<Delete/>
147160
</el-icon>
148161
</el-button>
149162
</span>
@@ -153,47 +166,52 @@
153166
</el-card>
154167
</ContentContainer>
155168

156-
<UserDrawer :title="title" :optionLoading="optionLoading" :chatGroupList="chatGroupList" ref="UserDrawerRef"
157-
@refresh="refresh" />
158-
<UserPwdDialog ref="UserPwdDialogRef" @refresh="refresh" />
159-
<SetUserGroupsDialog :optionLoading="optionLoading" :chatGroupList="chatGroupList" ref="setUserGroupsRef"
160-
@refresh="refresh" />
161-
<SyncUsersDialog ref="syncUsersDialogRef" @refresh="refresh" />
169+
<UserDrawer :title="title" :optionLoading="optionLoading" :chatGroupList="chatGroupList"
170+
ref="UserDrawerRef"
171+
@refresh="refresh"/>
172+
<UserPwdDialog ref="UserPwdDialogRef" @refresh="refresh"/>
173+
<SetUserGroupsDialog :optionLoading="optionLoading" :chatGroupList="chatGroupList"
174+
ref="setUserGroupsRef"
175+
@refresh="refresh"/>
176+
<SyncUsersDialog ref="syncUsersDialogRef" @refresh="refresh"/>
162177
</div>
163178
</template>
164179

165180
<script lang="ts" setup>
166-
import { onMounted, ref, reactive } from 'vue'
181+
import {onMounted, ref, reactive} from 'vue'
167182
import UserDrawer from './component/UserDrawer.vue'
168183
import UserPwdDialog from './component/UserPwdDialog.vue'
169184
import SetUserGroupsDialog from './component/SetUserGroupsDialog.vue'
170185
import SyncUsersDialog from './component/SyncUsersDialog.vue'
171186
import userManageApi from '@/api/system/chat-user'
172-
import { datetimeFormat } from '@/utils/time'
173-
import { MsgSuccess, MsgConfirm } from '@/utils/message'
174-
import { t } from '@/locales'
187+
import {datetimeFormat} from '@/utils/time'
188+
import {MsgSuccess, MsgConfirm} from '@/utils/message'
189+
import {t} from '@/locales'
175190
import iconMap from '@/components/app-icon/icons/common'
176-
import type { ChatUserItem } from '@/api/type/systemChatUser'
191+
import type {ChatUserItem} from '@/api/type/systemChatUser'
177192
import SystemGroupApi from '@/api/system/user-group'
178-
import type { ListItem } from '@/api/type/common'
179-
import { PermissionConst, RoleConst } from '@/utils/permission/data'
180-
import { ComplexPermission } from '@/utils/permission/type'
193+
import type {ListItem} from '@/api/type/common'
194+
import {PermissionConst, RoleConst} from '@/utils/permission/data'
195+
import {ComplexPermission} from '@/utils/permission/type'
181196
182197
const rightOutlined = iconMap['right-outlined'].iconReader()
183198
184199
const search_type = ref('name')
185200
const search_form = ref<{
186-
name: string
201+
username: string,
202+
nick_name?: string,
187203
}>({
188-
name: '',
204+
username: '',
205+
nick_name: '',
189206
})
190207
const search_type_change = () => {
191-
search_form.value = { name: '' }
208+
search_form.value = {username: '', nick_name: ''}
192209
}
193210
194211
const loading = ref(false)
195212
196213
const multipleSelection = ref<any[]>([])
214+
197215
function handleSelectionChange(val: any[]) {
198216
multipleSelection.value = val
199217
}
@@ -207,16 +225,20 @@ const paginationConfig = reactive({
207225
const userTableData = ref<ChatUserItem[]>([])
208226
209227
function getList() {
228+
const params = {
229+
[search_type.value]: search_form.value[search_type.value as keyof typeof search_form.value],
230+
}
210231
return userManageApi
211-
.getUserManage(paginationConfig, search_form.value.name, loading)
232+
.getUserManage(paginationConfig, params, loading)
212233
.then((res) => {
213234
userTableData.value = res.data.records
214235
paginationConfig.total = res.data.total
215236
})
216237
}
217238
218239
const orderBy = ref<string>('')
219-
function handleSortChange({ prop, order }: { prop: string; order: string }) {
240+
241+
function handleSortChange({prop, order}: { prop: string; order: string }) {
220242
orderBy.value = order === 'ascending' ? prop : `-${prop}`
221243
getList()
222244
}
@@ -246,6 +268,7 @@ function changeState(row: ChatUserItem) {
246268
247269
const title = ref('')
248270
const UserDrawerRef = ref()
271+
249272
function editUser(row: ChatUserItem) {
250273
title.value = t('views.userManage.editUser')
251274
UserDrawerRef.value.open(row)
@@ -277,6 +300,7 @@ function deleteUserManage(row: ChatUserItem) {
277300
}
278301
279302
const UserPwdDialogRef = ref()
303+
280304
function editPwdUser(row: ChatUserItem) {
281305
UserPwdDialogRef.value.open(row)
282306
}
@@ -292,6 +316,7 @@ onMounted(() => {
292316
293317
const optionLoading = ref(false)
294318
const chatGroupList = ref<ListItem[]>([])
319+
295320
async function getChatGroupList() {
296321
try {
297322
const res = await SystemGroupApi.getUserGroup(optionLoading)
@@ -303,7 +328,7 @@ async function getChatGroupList() {
303328
304329
function handleBatchDelete() {
305330
MsgConfirm(
306-
t('views.chatUser.batchDeleteUser', { count: multipleSelection.value.length }),
331+
t('views.chatUser.batchDeleteUser', {count: multipleSelection.value.length}),
307332
'',
308333
{
309334
confirmButtonText: t('common.confirm'),
@@ -321,11 +346,13 @@ function handleBatchDelete() {
321346
}
322347
323348
const setUserGroupsRef = ref<InstanceType<typeof SetUserGroupsDialog>>()
349+
324350
function setUserGroups() {
325351
setUserGroupsRef.value?.open(multipleSelection.value.map(item => (item.id)))
326352
}
327353
328354
const syncUsersDialogRef = ref<InstanceType<typeof SyncUsersDialog>>()
355+
329356
function syncUsers() {
330357
syncUsersDialogRef.value?.open()
331358
}

0 commit comments

Comments
 (0)