Skip to content

Commit 0af7da3

Browse files
committed
feat: chat user operation
1 parent 4975c4b commit 0af7da3

File tree

14 files changed

+347
-112
lines changed

14 files changed

+347
-112
lines changed

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

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Result } from '@/request/Result'
22
import { get, put, post, del } from '@/request/index'
3-
import type { pageRequest } from '@/api/type/common'
3+
import type { pageRequest, PageList } from '@/api/type/common'
44
import type { ChatUserItem } from '@/api/type/systemChatUser'
55
import type { Ref } from 'vue'
66
const prefix = '/system/chat_user'
@@ -22,7 +22,7 @@ const getUserManage: (
2222
page: pageRequest,
2323
username_or_nickname: string,
2424
loading?: Ref<boolean>,
25-
) => Promise<Result<any>> = (page, username_or_nickname, loading) => {
25+
) => Promise<Result<PageList<ChatUserItem[]>>> = (page, username_or_nickname, loading) => {
2626
return get(
2727
`${prefix}/user_manage/${page.current_page}/${page.page_size}`,
2828
username_or_nickname ? { username_or_nickname } : undefined,
@@ -73,12 +73,43 @@ const putUserManagePassword: (
7373
return put(`${prefix}/${user_id}/re_password`, data, undefined, loading)
7474
}
7575

76+
/**
77+
* 设置用户组
78+
*/
79+
const batchAddGroup: (data: any, loading?: Ref<boolean>) => Promise<Result<any>> = (
80+
data,
81+
loading,
82+
) => {
83+
return post(`${prefix}/batch_add_group`, data, undefined, loading)
84+
}
85+
86+
/**
87+
* 批量删除
88+
*/
89+
const batchDelete: (data: string[], loading?: Ref<boolean>) => Promise<Result<any>> = (
90+
data,
91+
loading,
92+
) => {
93+
return post(`${prefix}/batch_delete`, data, undefined, loading)
94+
}
7695

96+
/**
97+
* 同步用户
98+
*/
99+
const batchSync: (sync_type: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
100+
sync_type,
101+
loading,
102+
) => {
103+
return post(`${prefix}/sync/${sync_type}`, undefined, undefined, loading)
104+
}
77105
export default {
78106
getUserManage,
79107
putUserManage,
80108
delUserManage,
81109
postUserManage,
82110
putUserManagePassword,
83-
getChatUserList
111+
getChatUserList,
112+
batchAddGroup,
113+
batchDelete,
114+
batchSync
84115
}

ui/src/api/type/systemChatUser.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,12 @@ interface ChatUserItem {
1212
user_group_names?: string[],
1313
}
1414

15-
// TODO
1615
interface ChatUserGroupUserItem {
1716
id: string,
18-
is_auth: boolean,
1917
email: string,
2018
phone: string,
2119
nick_name: string,
2220
username: string,
23-
password: string,
2421
source: string,
2522
is_active: boolean,
2623
create_time: string,

ui/src/locales/lang/en-US/common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export default {
2+
syncSuccess: 'Successful',
23
create: 'Create',
34
createSuccess: 'Successful',
45
copy: 'Copy',
Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
export default {
2-
title: 'Chat users',
3-
syncUsers: 'Synchronize users',
4-
setUserGroups: 'Configure user groups',
5-
knowledgeTitleTip: 'This configuration will only take effect when the associated application enables chat user login authentication',
2+
title: 'Chat Users',
3+
syncUsers: 'Sync Users',
4+
syncUsersTip: 'Only sync newly added users',
5+
setUserGroups: 'Configure User Groups',
6+
knowledgeTitleTip: 'This configuration will only take effect after enabling chat user login authentication in the associated application',
67
applicationTitleTip: 'This configuration requires login authentication to be enabled in the application',
7-
autoAuthorization: 'Auto authorization',
8+
autoAuthorization: 'Auto Authorization',
89
authorization: 'Authorization',
10+
batchDeleteUser: 'Delete selected {count} users?',
11+
settingMethod: 'Configuration Method',
12+
append: 'Append',
13+
replace: 'Replace',
914
group: {
10-
title: 'User groups',
11-
name: 'User group name',
15+
title: 'User Groups',
16+
name: 'User Group Name',
1217
usernameOrName: 'Username/Name',
1318
delete: {
1419
confirmTitle: 'Confirm to delete user group:',
15-
confirmMessage: 'After deletion, all members in this user group will be removed. Please proceed with caution!',
20+
confirmMessage: 'All members in this group will be removed after deletion. Proceed with caution!',
1621
},
1722
batchDeleteMember: 'Remove selected {count} members?',
1823
}
19-
};
24+
}

ui/src/locales/lang/zh-CN/common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export default {
2+
syncSuccess: '同步成功',
23
create: '创建',
34
createSuccess: '创建成功',
45
copy: '复制',

ui/src/locales/lang/zh-CN/views/chat-user.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
export default {
22
title: '对话用户',
33
syncUsers: '同步用户',
4+
syncUsersTip: '仅同步新增用户',
45
setUserGroups: '设置用户组',
56
knowledgeTitleTip: '该配置需要关联的应用开启对话用户登录认证后才会生效',
67
applicationTitleTip: '该配置需要应用开启登录认证后生效',
78
autoAuthorization: '自动授权',
89
authorization: '授权',
10+
batchDeleteUser: '是否删除选中的 {count} 个用户?',
11+
settingMethod: '设置方式',
12+
append: '追加',
13+
replace: '替换',
914
group: {
1015
title: '用户组',
1116
name: '用户组名称',

ui/src/locales/lang/zh-Hant/common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export default {
2+
syncSuccess: '同步完成',
23
create: '創建',
34
createSuccess: '創建成功',
45
copy: '複製',

ui/src/locales/lang/zh-Hant/views/chat-user.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
export default {
22
title: '對話用戶',
33
syncUsers: '同步用戶',
4+
syncUsersTip: '僅同步新增用戶',
45
setUserGroups: '設定用戶組',
56
knowledgeTitleTip: '該配置需要關聯的應用開啟對話用戶登入認證後才會生效',
67
applicationTitleTip: '該配置需要應用開啟登入認證後生效',
78
autoAuthorization: '自動授權',
89
authorization: '授權',
10+
batchDeleteUser: '是否刪除選中的 {count} 個用戶?',
11+
settingMethod: '設定方式',
12+
append: '追加',
13+
replace: '替換',
914
group: {
1015
title: '用戶組',
1116
name: '用戶組名稱',
@@ -16,4 +21,4 @@ export default {
1621
},
1722
batchDeleteMember: '是否移除選中的 {count} 個成員?',
1823
}
19-
};
24+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ watch(() => current.value?.id, () => {
263263
const createGroupUserDialogRef = ref<InstanceType<typeof CreateGroupUserDialog>>()
264264
265265
function createUser() {
266-
createGroupUserDialogRef.value?.open(current.value?.id);
266+
createGroupUserDialogRef.value?.open(current.value?.id as string);
267267
}
268268
269269
const multipleSelection = ref<any[]>([])
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<template>
2+
<el-dialog width="600" :title="$t('views.chatUser.setUserGroups')" v-model="dialogVisible"
3+
:close-on-click-modal="false" :close-on-press-escape="false" :destroy-on-close="true">
4+
<el-form label-position="top" ref="formRef" :rules="rules" :model="form" require-asterisk-position="right">
5+
<el-form-item :label="$t('views.chatUser.settingMethod')" prop="user_group_ids">
6+
<el-radio-group v-model="form.is_append">
7+
<el-radio :value="true">{{ $t('views.chatUser.append') }}</el-radio>
8+
<el-radio :value="false">{{ $t('views.chatUser.replace') }}</el-radio>
9+
</el-radio-group>
10+
</el-form-item>
11+
<el-form-item :label="$t('views.chatUser.group.title')" prop="user_group_ids">
12+
<el-select v-model="form.user_group_ids" multiple filterable :placeholder="$t('common.selectPlaceholder')"
13+
:loading="props.optionLoading">
14+
<el-option v-for="item in props.chatGroupList" :key="item.id" :label="item.name" :value="item.id">
15+
</el-option>
16+
</el-select>
17+
</el-form-item>
18+
</el-form>
19+
<template #footer>
20+
<span class="dialog-footer">
21+
<el-button @click.prevent="dialogVisible = false"> {{ $t('common.cancel') }} </el-button>
22+
<el-button type="primary" @click="submit(formRef)" :loading="loading">
23+
{{ $t('common.save') }}
24+
</el-button>
25+
</span>
26+
</template>
27+
</el-dialog>
28+
</template>
29+
30+
<script setup lang="ts">
31+
import { ref, reactive } from 'vue'
32+
import type { FormInstance } from 'element-plus'
33+
import { MsgSuccess } from '@/utils/message'
34+
import { t } from '@/locales'
35+
import userManageApi from '@/api/system/chat-user'
36+
import type { ListItem } from '@/api/type/common'
37+
38+
const props = defineProps<{
39+
optionLoading: boolean,
40+
chatGroupList: ListItem[],
41+
}>()
42+
43+
const emit = defineEmits<{
44+
(e: 'refresh'): void;
45+
}>();
46+
47+
const dialogVisible = ref<boolean>(false)
48+
const defaultForm = {
49+
user_group_ids: [],
50+
is_append: true,
51+
ids: []
52+
}
53+
const form = ref<{
54+
ids: string[], user_group_ids: string[], is_append: boolean
55+
}>({
56+
...defaultForm,
57+
})
58+
59+
function open(ids: string[]) {
60+
form.value = { ...defaultForm, ids }
61+
dialogVisible.value = true
62+
}
63+
64+
const formRef = ref<FormInstance>();
65+
66+
const rules = reactive({
67+
user_group_ids: [{ required: true, message: t('common.selectPlaceholder'), trigger: 'blur' }],
68+
is_append: [{ required: true, message: t('common.selectPlaceholder'), trigger: 'blur' }],
69+
})
70+
71+
const loading = ref<boolean>(false)
72+
const submit = async (formEl: FormInstance | undefined) => {
73+
if (!formEl) return
74+
await formEl.validate((valid) => {
75+
if (valid) {
76+
userManageApi.batchAddGroup(form.value, loading).then(() => {
77+
MsgSuccess(t('common.settingSuccess'))
78+
emit('refresh')
79+
dialogVisible.value = false
80+
})
81+
}
82+
})
83+
}
84+
85+
defineExpose({ open })
86+
</script>

0 commit comments

Comments
 (0)