Skip to content

Commit fef2357

Browse files
committed
refactor: chat user
1 parent f2f6f82 commit fef2357

File tree

4 files changed

+39
-18
lines changed

4 files changed

+39
-18
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ const getUserGroupList: (resource: ChatUserResourceParams, loading?: Ref<boolean
1919
return get(`${prefix.value}/${resource.resource_type}/${resource.resource_id}/user_group`, undefined, loading)
2020
}
2121

22+
/**
23+
* 修改用户组列表授权
24+
*/
25+
const editUserGroupList: (resource: ChatUserResourceParams, data: { user_group_id: string, is_auth: boolean }[], loading?: Ref<boolean>) => Promise<Result<any>> = (resource, data, loading) => {
26+
return put(`${prefix}/${resource.resource_type}/${resource.resource_id}/user_group`, data, undefined, loading)
27+
}
28+
2229
/**
2330
* 获取用户组的用户列表
2431
*/
@@ -50,6 +57,7 @@ const putUserGroupUser: (
5057

5158
export default {
5259
getUserGroupList,
60+
editUserGroupList,
5361
getUserGroupUserList,
5462
putUserGroupUser
5563
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const postAddMember: (
5555
*/
5656
const postRemoveMember: (
5757
user_group_id: string,
58-
body: string[],
58+
body: any,
5959
loading?: Ref<boolean>,
6060
) => Promise<Result<any>> = (user_group_id, body, loading) => {
6161
return post(`${prefix}/${user_group_id}/remove_member`, body, {}, loading)

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

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
{{ paginationConfig.total }}
4141
</span>
4242
</div>
43-
<el-button type="primary" @click="handleSave">
43+
<el-button type="primary" :disabled="current?.is_auth" @click="handleSave">
4444
{{ t('common.save') }}
4545
</el-button>
4646
</div>
@@ -50,12 +50,13 @@
5050
<el-select class="complex-search__left" v-model="searchType" style="width: 120px">
5151
<el-option :label="$t('views.login.loginForm.username.label')" value="name" />
5252
</el-select>
53-
<el-input v-if="searchType === 'name'" v-model="searchForm.name"
54-
@change="getList" :placeholder="$t('common.inputPlaceholder')" style="width: 220px" clearable />
53+
<el-input v-if="searchType === 'name'" v-model="searchForm.name" @change="getList"
54+
:placeholder="$t('common.inputPlaceholder')" style="width: 220px" clearable />
5555
</div>
5656
<div class="flex align-center">
5757
<div class="color-secondary mr-8">{{ $t('views.chatUser.autoAuthorization') }}</div>
58-
<el-switch size="small" v-model="automaticAuthorization"></el-switch>
58+
<el-switch size="small" :model-value="current?.is_auth" @click="changeAuth"
59+
:loading="loading"></el-switch>
5960
</div>
6061
</div>
6162

@@ -82,11 +83,12 @@
8283
</el-table-column>
8384
<el-table-column :width="140" align="center">
8485
<template #header>
85-
<el-checkbox :model-value="allChecked" :indeterminate="allIndeterminate" :disabled="disabled"
86-
@change="handleCheckAll">{{ $t('views.chatUser.authorization') }}</el-checkbox>
86+
<el-checkbox :model-value="allChecked" :indeterminate="allIndeterminate" :disabled="current?.is_auth"
87+
@change="handleCheckAll">{{ $t('views.chatUser.authorization')
88+
}}</el-checkbox>
8789
</template>
8890
<template #default="{ row }">
89-
<el-checkbox v-model="row.enable" :indeterminate="row.indeterminate" :disabled="disabled"
91+
<el-checkbox v-model="row.is_auth" :indeterminate="row.indeterminate" :disabled="current?.is_auth"
9092
@change="(value: boolean) => handleRowChange(value, row)" />
9193
</template>
9294
</el-table-column>
@@ -104,12 +106,11 @@ import { t } from '@/locales'
104106
import type { ChatUserGroupItem, ChatUserResourceParams, ChatUserGroupUserItem } from '@/api/type/workspaceChatUser'
105107
import { useRoute } from 'vue-router'
106108
import { ChatUserResourceEnum } from '@/enums/workspaceChatUser'
109+
import { MsgSuccess } from '@/utils/message'
107110
108111
const route = useRoute()
109112
const resource: ChatUserResourceParams = { resource_id: route.params.id as string, resource_type: route.meta.resourceType as ChatUserResourceEnum }
110113
111-
const disabled = computed(() => false) // TODO
112-
113114
const filterText = ref('')
114115
const loading = ref(false)
115116
const list = ref<ChatUserGroupItem[]>([])
@@ -148,13 +149,24 @@ function clickUserGroup(item: ChatUserGroupItem) {
148149
current.value = item
149150
}
150151
152+
async function changeAuth() {
153+
const params = [{ user_group_id: current.value?.id as string, is_auth: !current.value?.is_auth }]
154+
try {
155+
await ChatUserApi.editUserGroupList(resource, params, loading)
156+
await getUserGroupList()
157+
current.value = { name: current.value?.name as string, id: current.value?.id as string, is_auth: !current.value?.is_auth }
158+
getList()
159+
} catch (error) {
160+
console.error(error)
161+
}
162+
}
163+
151164
const rightLoading = ref(false)
152165
153166
const searchType = ref('name')
154167
const searchForm = ref<Record<string, any>>({
155168
name: '',
156169
})
157-
const automaticAuthorization = ref(false)
158170
const paginationConfig = reactive({
159171
current_page: 1,
160172
page_size: 20,
@@ -205,6 +217,7 @@ async function handleSave() {
205217
try {
206218
const params = tableData.value.map(item => ({ chat_user_id: item.id, is_auth: item.is_auth }))
207219
await ChatUserApi.putUserGroupUser(resource, current.value?.id as string, params, rightLoading)
220+
MsgSuccess(t('common.saveSuccess'))
208221
} catch (error) {
209222
console.error(error)
210223
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
<div class="flex-between mb-16" style="margin-top: 20px;">
7979
<div>
8080
<el-button type="primary" @click="createUser()">
81-
{{ t('views.userManage.createUser') }}
81+
{{ t('views.role.member.add') }}
8282
</el-button>
8383
<el-button :disabled="multipleSelection.length === 0" @click="handleDeleteUser()">
8484
{{ $t('common.delete') }}
@@ -132,7 +132,7 @@
132132
</el-card>
133133
</ContentContainer>
134134
<CreateOrUpdateGroupDialog ref="createOrUpdateGroupDialogRef" @refresh="refresh" />
135-
<CreateGroupUserDialog ref="createGroupUserDialogRef" @refresh="getUserGroupList" />
135+
<CreateGroupUserDialog ref="createGroupUserDialogRef" @refresh="getList" />
136136
</template>
137137

138138
<script lang="ts" setup>
@@ -256,22 +256,22 @@ function createUser() {
256256
createGroupUserDialogRef.value?.open(current.value?.id);
257257
}
258258
259-
const multipleSelection = ref<string[]>([])
260-
function handleSelectionChange(val: string[]) {
259+
const multipleSelection = ref<any[]>([])
260+
function handleSelectionChange(val: any[]) {
261261
multipleSelection.value = val
262262
}
263263
264264
function handleDeleteUser(item?: ChatUserGroupUserItem) {
265265
MsgConfirm(
266-
item ? `${t('views.workspace.member.delete.confirmTitle')}${item.nick_name} ?` : '',
267-
t('views.chatUser.group.batchDeleteMember', { number: multipleSelection.value.length }),
266+
item ? `${t('views.workspace.member.delete.confirmTitle')}${item.nick_name} ?` : t('views.chatUser.group.batchDeleteMember', { count: multipleSelection.value.length }),
267+
'',
268268
{
269269
confirmButtonText: t('common.confirm'),
270270
confirmButtonClass: 'danger',
271271
},
272272
)
273273
.then(() => {
274-
SystemGroupApi.postRemoveMember(current.value?.id as string, item ? [item.id] : multipleSelection.value, loading).then(async () => {
274+
SystemGroupApi.postRemoveMember(current.value?.id as string, { group_relation_ids: item ? [item.id] : multipleSelection.value.map(item => (item.id)) }, loading).then(async () => {
275275
MsgSuccess(t('common.deleteSuccess'))
276276
await getList()
277277
})

0 commit comments

Comments
 (0)