Skip to content

Commit 6c48e80

Browse files
committed
feat: createGroupUserDialog
1 parent 2e24409 commit 6c48e80

File tree

4 files changed

+115
-37
lines changed

4 files changed

+115
-37
lines changed

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,32 +41,21 @@ const delUserGroup: (user_group_id: string, loading?: Ref<boolean>) => Promise<R
4141

4242
/**
4343
* 给用户组添加用户
44-
* @param 参数
45-
* {
46-
"additionalProp1": "string",
47-
"additionalProp2": "string",
48-
"additionalProp3": "string"
49-
}
5044
*/
5145
const postAddMember: (
5246
user_group_id: string,
53-
body: Record<string, any>,
47+
body: string[],
5448
loading?: Ref<boolean>,
5549
) => Promise<Result<any>> = (user_group_id, body, loading) => {
5650
return post(`${prefix}/${user_group_id}/add_member`, body, {}, loading)
5751
}
5852

5953
/**
6054
* 从用户组删除用户
61-
* @param 参数 {
62-
"additionalProp1": "string",
63-
"additionalProp2": "string",
64-
"additionalProp3": "string"
65-
}
6655
*/
6756
const postRemoveMember: (
6857
user_group_id: string,
69-
body: Record<string, any>,
58+
body: string[],
7059
loading?: Ref<boolean>,
7160
) => Promise<Result<any>> = (user_group_id, body, loading) => {
7261
return post(`${prefix}/${user_group_id}/remove_member`, body, {}, loading)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ export default {
77
group: {
88
title: '用户组',
99
name: '用户组名称',
10+
usernameOrName: '用户名/姓名',
1011
delete: {
1112
confirmTitle: '是否删除用户组:',
1213
confirmMessage: '删除后,该用户组下的成员将全部移除,请谨慎操作!',
1314
},
15+
batchDeleteMember: '是否移除选中的 {count} 个成员?',
1416
}
1517
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<template>
2+
<el-dialog :title="$t('views.role.member.add')" v-model="dialogVisible" :close-on-click-modal="false"
3+
: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.group.usernameOrName')" prop="user">
6+
<el-select v-model="form.user" multiple filterable :placeholder="$t('common.selectPlaceholder')"
7+
:loading="optionLoading">
8+
<el-option v-for="item in chatUserList" :key="item.id" :label="item.nick_name" :value="item.id">
9+
</el-option>
10+
</el-select>
11+
</el-form-item>
12+
</el-form>
13+
<template #footer>
14+
<span class="dialog-footer">
15+
<el-button @click.prevent="dialogVisible = false"> {{ $t('common.cancel') }} </el-button>
16+
<el-button type="primary" @click="submit(formRef)" :loading="loading">
17+
{{ $t('common.create') }}
18+
</el-button>
19+
</span>
20+
</template>
21+
</el-dialog>
22+
</template>
23+
24+
<script setup lang="ts">
25+
import { ref, reactive, onBeforeMount } from 'vue'
26+
import type { FormInstance } from 'element-plus'
27+
import { MsgSuccess } from '@/utils/message'
28+
import { t } from '@/locales'
29+
import SystemGroupApi from '@/api/system/user-group'
30+
import userManageApi from '@/api/system/chat-user'
31+
import type { ChatUserItem } from '@/api/type/systemChatUser'
32+
33+
const emit = defineEmits<{
34+
(e: 'refresh'): void;
35+
}>();
36+
37+
const dialogVisible = ref<boolean>(false)
38+
const defaultForm = {
39+
user: []
40+
}
41+
const form = ref<{ user: string[] }>({
42+
...defaultForm,
43+
})
44+
45+
const optionLoading = ref(false)
46+
const chatUserList = ref<ChatUserItem[]>([])
47+
async function getChatUserList() {
48+
try {
49+
const res = await userManageApi.getChatUserList(optionLoading)
50+
chatUserList.value = res.data
51+
} catch (e) {
52+
console.error(e)
53+
}
54+
}
55+
56+
onBeforeMount(() => {
57+
getChatUserList()
58+
})
59+
60+
const groupId = ref('');
61+
function open(id: string) {
62+
form.value = { ...defaultForm }
63+
groupId.value = id
64+
dialogVisible.value = true
65+
}
66+
67+
const formRef = ref<FormInstance>();
68+
69+
const rules = reactive({
70+
user: [{ required: true, message: t('common.selectPlaceholder'), trigger: 'blur' }],
71+
})
72+
73+
const loading = ref<boolean>(false)
74+
const submit = async (formEl: FormInstance | undefined) => {
75+
if (!formEl) return
76+
await formEl.validate((valid) => {
77+
if (valid) {
78+
SystemGroupApi.postAddMember(groupId.value, form.value.user, loading).then(() => {
79+
MsgSuccess(t('common.createSuccess'))
80+
emit('refresh')
81+
dialogVisible.value = false
82+
})
83+
}
84+
})
85+
}
86+
87+
defineExpose({ open })
88+
</script>

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

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
<el-table-column :label="$t('common.operation')" width="100" fixed="right">
119119
<template #default="{ row }">
120120
<el-tooltip effect="dark" :content="`${$t('views.role.member.delete.button')}`" placement="top">
121-
<el-button type="primary" text @click.stop="handleDeleteUser([row.id])">
121+
<el-button type="primary" text @click.stop="handleDeleteUser(row)">
122122
<el-icon>
123123
<EditPen />
124124
</el-icon>
@@ -132,21 +132,19 @@
132132
</el-card>
133133
</ContentContainer>
134134
<CreateOrUpdateGroupDialog ref="createOrUpdateGroupDialogRef" @refresh="refresh" />
135-
<!-- <CreateGroupUserDialog ref="createGroupUserDialogRef" @refresh="getUserGroupList" /> -->
135+
<CreateGroupUserDialog ref="createGroupUserDialogRef" @refresh="getUserGroupList" />
136136
</template>
137137

138138
<script lang="ts" setup>
139-
import { onMounted, ref, watch, reactive, onBeforeMount } from 'vue'
139+
import { onMounted, ref, watch, reactive } from 'vue'
140140
import SystemGroupApi from '@/api/system/user-group'
141-
import userManageApi from '@/api/system/chat-user'
142141
import { t } from '@/locales'
143142
import type { ChatUserGroupUserItem } from '@/api/type/systemChatUser'
144143
import iconMap from '@/components/app-icon/icons/common'
145144
import CreateOrUpdateGroupDialog from './component/CreateOrUpdateGroupDialog.vue'
146-
// import CreateGroupUserDialog from './component/CreateGroupUserDialog.vue'
145+
import CreateGroupUserDialog from './component/CreateGroupUserDialog.vue'
147146
import type { ListItem } from '@/api/type/common'
148147
import { MsgSuccess, MsgConfirm } from '@/utils/message'
149-
import type { ChatUserItem } from '@/api/type/systemChatUser'
150148
151149
const filterText = ref('')
152150
const loading = ref(false)
@@ -253,32 +251,33 @@ watch(() => current.value?.id, () => {
253251
getList()
254252
})
255253
256-
const chatUserList = ref<ChatUserItem[]>([])
257-
async function getChatUserList() {
258-
try {
259-
const res = await userManageApi.getChatUserList()
260-
chatUserList.value = res.data
261-
} catch (e) {
262-
console.error(e)
263-
}
264-
}
265-
266-
onBeforeMount(() => {
267-
getChatUserList()
268-
})
269-
270-
// const createGroupUserDialogRef = ref<InstanceType<typeof CreateGroupUserDialog>>()
254+
const createGroupUserDialogRef = ref<InstanceType<typeof CreateGroupUserDialog>>()
271255
function createUser() {
272-
// createGroupUserDialogRef.value?.open();
256+
createGroupUserDialogRef.value?.open(current.value?.id);
273257
}
274258
275259
const multipleSelection = ref<string[]>([])
276260
function handleSelectionChange(val: string[]) {
277261
multipleSelection.value = val
278262
}
279263
280-
function handleDeleteUser(ids?: string[]) {
281-
// TODO
264+
function handleDeleteUser(item?: ChatUserGroupUserItem) {
265+
MsgConfirm(
266+
item ? `${t('views.workspace.member.delete.confirmTitle')}${item.nick_name} ?` : '',
267+
t('views.chatUser.group.batchDeleteMember', { number: multipleSelection.value.length }),
268+
{
269+
confirmButtonText: t('common.confirm'),
270+
confirmButtonClass: 'danger',
271+
},
272+
)
273+
.then(() => {
274+
SystemGroupApi.postRemoveMember(current.value?.id as string, item ? [item.id] : multipleSelection.value, loading).then(async () => {
275+
MsgSuccess(t('common.deleteSuccess'))
276+
await getList()
277+
})
278+
})
279+
.catch(() => {
280+
})
282281
}
283282
</script>
284283

0 commit comments

Comments
 (0)