Skip to content

Commit 10eac10

Browse files
feat: chat user
1 parent 746fbe8 commit 10eac10

File tree

3 files changed

+171
-67
lines changed

3 files changed

+171
-67
lines changed
File renamed without changes.

ui/src/utils/dynamics-api/shared-api.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import paragraphWorkspaceApi from '@/api/knowledge/paragraph'
44
import problemWorkspaceApi from '@/api/knowledge/problem'
55
import modelWorkspaceApi from '@/api/model/model'
66
import toolWorkspaceApi from '@/api/tool/tool'
7+
import chatUserWorkspaceApi from '@/api/chat-user/chat-user'
78
import sharedWorkspaceApi from '@/api/shared-workspace'
89
import toolSystemShareApi from '@/api/system-shared/tool'
910
import modelSystemShareApi from '@/api/system-shared/model'
1011
import knowledgeSystemShareApi from '@/api/system-shared/knowledge'
1112
import documentSystemShareApi from '@/api/system-shared/document'
1213
import paragraphSystemShareApi from '@/api/system-shared/paragraph'
1314
import problemSystemShareApi from '@/api/system-shared/problem'
15+
import chatUserSystemShareApi from '@/api/system-shared/chat-user'
1416

1517
// 普通 API
1618
const workspaceApiMap = {
@@ -20,6 +22,7 @@ const workspaceApiMap = {
2022
document: documentWorkspaceApi,
2123
paragraph: paragraphWorkspaceApi,
2224
problem: problemWorkspaceApi,
25+
chatUser: chatUserWorkspaceApi,
2326
} as any
2427

2528
// 系统分享 API
@@ -30,6 +33,7 @@ const systemShareApiMap = {
3033
document: documentSystemShareApi,
3134
paragraph: paragraphSystemShareApi,
3235
problem: problemSystemShareApi,
36+
chatUser: chatUserSystemShareApi,
3337
} as any
3438

3539
// 资源管理 API

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

Lines changed: 167 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
33
<template #header>
44
<div>
55
<h2>{{ $t('views.chatUser.title') }}</h2>
6-
<div class="color-secondary">{{ resource.resource_type === SourceTypeEnum.APPLICATION ?
7-
$t('views.chatUser.applicationTitleTip') : $t('views.chatUser.knowledgeTitleTip') }}</div>
6+
<div class="color-secondary">
7+
{{
8+
resource.resource_type === SourceTypeEnum.APPLICATION
9+
? $t('views.chatUser.applicationTitleTip')
10+
: $t('views.chatUser.knowledgeTitleTip')
11+
}}
12+
</div>
813
</div>
914
</template>
1015
<el-card style="--el-card-padding: 0" class="user-card">
@@ -14,7 +19,12 @@
1419
<h4 class="medium">{{ $t('views.chatUser.group.title') }}</h4>
1520
</div>
1621
<div class="p-8">
17-
<el-input v-model="filterText" :placeholder="$t('common.search')" prefix-icon="Search" clearable />
22+
<el-input
23+
v-model="filterText"
24+
:placeholder="$t('common.search')"
25+
prefix-icon="Search"
26+
clearable
27+
/>
1828
</div>
1929
<div class="list-height-left">
2030
<el-scrollbar v-loading="loading">
@@ -36,39 +46,81 @@
3646
<div class="flex align-center">
3747
<h4 class="medium">{{ current?.name }}</h4>
3848
<el-divider direction="vertical" class="mr-8 ml-8" />
39-
<AppIcon iconName="app-workspace" style="font-size: 16px" class="color-input-placeholder"></AppIcon>
49+
<AppIcon
50+
iconName="app-workspace"
51+
style="font-size: 16px"
52+
class="color-input-placeholder"
53+
></AppIcon>
4054
<span class="color-input-placeholder ml-4">
4155
{{ paginationConfig.total }}
4256
</span>
4357
</div>
44-
<el-button type="primary" :disabled="current?.is_auth" @click="handleSave"
45-
v-if="hasPermission(permissionObj[route.path.includes('shared')?'SHAREDKNOWLEDGE':(route.meta?.resourceType as string)],'OR')"
58+
<el-button
59+
type="primary"
60+
:disabled="current?.is_auth"
61+
@click="handleSave"
62+
v-if="
63+
hasPermission(
64+
permissionObj[
65+
route.path.includes('shared')
66+
? 'SHAREDKNOWLEDGE'
67+
: (route.meta?.resourceType as string)
68+
],
69+
'OR',
70+
)
71+
"
4672
>
4773
{{ t('common.save') }}
4874
</el-button>
4975
</div>
5076

51-
<div class="flex-between mb-16" style="margin-top: 18px;">
77+
<div class="flex-between mb-16" style="margin-top: 18px">
5278
<div class="flex complex-search">
5379
<el-select class="complex-search__left" v-model="searchType" style="width: 120px">
5480
<el-option :label="$t('views.login.loginForm.username.label')" value="name" />
5581
</el-select>
56-
<el-input v-if="searchType === 'name'" v-model="searchForm.name" @change="getList"
57-
:placeholder="$t('common.inputPlaceholder')" style="width: 220px" clearable />
82+
<el-input
83+
v-if="searchType === 'name'"
84+
v-model="searchForm.name"
85+
@change="getList"
86+
:placeholder="$t('common.inputPlaceholder')"
87+
style="width: 220px"
88+
clearable
89+
/>
5890
</div>
59-
<div class="flex align-center"
60-
v-if="hasPermission(permissionObj[route.path.includes('shared')?'SHAREDKNOWLEDGE':(route.meta?.resourceType as string)],'OR')"
91+
<div
92+
class="flex align-center"
93+
v-if="
94+
hasPermission(
95+
permissionObj[
96+
route.path.includes('shared')
97+
? 'SHAREDKNOWLEDGE'
98+
: (route.meta?.resourceType as string)
99+
],
100+
'OR',
101+
)
102+
"
61103
>
62104
<div class="color-secondary mr-8">{{ $t('views.chatUser.autoAuthorization') }}</div>
63-
<el-switch size="small" :model-value="current?.is_auth" @click="changeAuth"
105+
<el-switch
106+
size="small"
107+
:model-value="current?.is_auth"
108+
@click="changeAuth"
64109
:loading="loading"
65-
></el-switch>
110+
></el-switch>
66111
</div>
67112
</div>
68113

69-
<app-table :data="tableData" :pagination-config="paginationConfig" @sizeChange="handleSizeChange"
70-
@changePage="getList">
71-
<el-table-column prop="nick_name" :label="$t('views.userManage.userForm.nick_name.label')" />
114+
<app-table
115+
:data="tableData"
116+
:pagination-config="paginationConfig"
117+
@sizeChange="handleSizeChange"
118+
@changePage="getList"
119+
>
120+
<el-table-column
121+
prop="nick_name"
122+
:label="$t('views.userManage.userForm.nick_name.label')"
123+
/>
72124
<el-table-column prop="username" :label="$t('views.login.loginForm.username.label')" />
73125
<el-table-column prop="source" :label="$t('views.userManage.source.label')">
74126
<template #default="{ row }">
@@ -89,13 +141,21 @@
89141
</el-table-column>
90142
<el-table-column :width="140" align="center">
91143
<template #header>
92-
<el-checkbox :model-value="allChecked" :indeterminate="allIndeterminate" :disabled="current?.is_auth"
93-
@change="handleCheckAll">{{ $t('views.chatUser.authorization')
94-
}}</el-checkbox>
144+
<el-checkbox
145+
:model-value="allChecked"
146+
:indeterminate="allIndeterminate"
147+
:disabled="current?.is_auth"
148+
@change="handleCheckAll"
149+
>{{ $t('views.chatUser.authorization') }}</el-checkbox
150+
>
95151
</template>
96152
<template #default="{ row }">
97-
<el-checkbox v-model="row.is_auth" :indeterminate="row.indeterminate" :disabled="current?.is_auth"
98-
@change="(value: boolean) => handleRowChange(value, row)" />
153+
<el-checkbox
154+
v-model="row.is_auth"
155+
:indeterminate="row.indeterminate"
156+
:disabled="current?.is_auth"
157+
@change="(value: boolean) => handleRowChange(value, row)"
158+
/>
99159
</template>
100160
</el-table-column>
101161
</app-table>
@@ -108,60 +168,76 @@
108168
<script lang="ts" setup>
109169
import { onMounted, ref, watch, reactive, computed } from 'vue'
110170
import ChatUserApi from '@/api/chat-user/chat-user'
111-
import SharedChatUserApi from "@/api/system-shared/knowledge-chat-user"
171+
import SharedChatUserApi from '@/api/system-shared/chat-user'
112172
import { t } from '@/locales'
113173
import type { ChatUserGroupItem, ChatUserGroupUserItem } from '@/api/type/workspaceChatUser'
114174
import { useRoute } from 'vue-router'
115175
import { SourceTypeEnum } from '@/enums/common'
116176
import { MsgSuccess } from '@/utils/message'
117-
import permissionMap from '@/permission'
118177
import { ComplexPermission } from '@/utils/permission/type'
119178
import { EditionConst, RoleConst, PermissionConst } from '@/utils/permission/data'
120179
import { hasPermission } from '@/utils/permission/index'
121-
122-
180+
import { loadSharedApi } from '@/utils/dynamics-api/shared-api'
123181
124182
const route = useRoute()
125183
126-
const apiType = computed<'workspace'>(() => {
127-
return 'workspace'
128-
})
129-
const permissionPrecise = computed(() => {
130-
return permissionMap['application'][apiType.value]
131-
})
132-
133184
const {
134185
params: { id },
135186
} = route as any
136-
137-
const permissionObj=ref<any>({
138-
"APPLICATION": new ComplexPermission([RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE.getWorkspaceRole],
139-
[PermissionConst.APPLICATION_CHAT_USER_EDIT,
140-
PermissionConst.APPLICATION_CHAT_USER_EDIT.getApplicationWorkspaceResourcePermission(id)],[],'OR'),
141-
"KNOWLEDGE": new ComplexPermission([RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE.getWorkspaceRole],
142-
[PermissionConst.KNOWLEDGE_CHAT_USER_EDIT,
143-
PermissionConst.KNOWLEDGE_CHAT_USER_EDIT.getKnowledgeWorkspaceResourcePermission(id)],[],'OR'),
144-
"SHAREDKNOWLEDGE": new ComplexPermission([RoleConst.ADMIN],[PermissionConst.SHARED_KNOWLEDGE_CHAT_USER_EDIT],[],'OR')
187+
188+
const permissionObj = ref<any>({
189+
APPLICATION: new ComplexPermission(
190+
[RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE.getWorkspaceRole],
191+
[
192+
PermissionConst.APPLICATION_CHAT_USER_EDIT,
193+
PermissionConst.APPLICATION_CHAT_USER_EDIT.getApplicationWorkspaceResourcePermission(id),
194+
],
195+
[],
196+
'OR',
197+
),
198+
KNOWLEDGE: new ComplexPermission(
199+
[RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE.getWorkspaceRole],
200+
[
201+
PermissionConst.KNOWLEDGE_CHAT_USER_EDIT,
202+
PermissionConst.KNOWLEDGE_CHAT_USER_EDIT.getKnowledgeWorkspaceResourcePermission(id),
203+
],
204+
[],
205+
'OR',
206+
),
207+
SHAREDKNOWLEDGE: new ComplexPermission(
208+
[RoleConst.ADMIN],
209+
[PermissionConst.SHARED_KNOWLEDGE_CHAT_USER_EDIT],
210+
[],
211+
'OR',
212+
),
145213
})
146214
147-
const resource = reactive({ resource_id: route.params.id as string, resource_type: route.meta.resourceType as string })
215+
const resource = reactive({
216+
resource_id: route.params.id as string,
217+
resource_type: route.meta.resourceType as string,
218+
})
148219
149220
const filterText = ref('')
150221
const loading = ref(false)
151222
const list = ref<ChatUserGroupItem[]>([])
152223
const filterList = ref<ChatUserGroupItem[]>([]) // 搜索过滤后列表
153224
const current = ref<ChatUserGroupItem>()
154-
const chatUserAuthAPI=computed(()=>{
155-
if(route.path.includes('shared')){
156-
return SharedChatUserApi
157-
}else{
158-
return ChatUserApi
225+
const apiType = computed(() => {
226+
if (route.path.includes('shared')) {
227+
return 'systemShare'
228+
} else if (route.path.includes('resource-management')) {
229+
return 'systemManage'
230+
} else {
231+
return 'workspace'
159232
}
160233
})
161234
162235
async function getUserGroupList() {
163236
try {
164-
const res = await chatUserAuthAPI.value.getUserGroupList(resource, loading)
237+
const res = await loadSharedApi({
238+
type: 'chatUser',
239+
systemType: apiType.value,
240+
}).getUserGroupList(resource, loading)
165241
list.value = res.data
166242
filterList.value = filter(list.value, filterText.value)
167243
} catch (error) {
@@ -194,9 +270,16 @@ function clickUserGroup(item: ChatUserGroupItem) {
194270
async function changeAuth() {
195271
const params = [{ user_group_id: current.value?.id as string, is_auth: !current.value?.is_auth }]
196272
try {
197-
await chatUserAuthAPI.value.editUserGroupList(resource, params, loading)
273+
await loadSharedApi({
274+
type: 'chatUser',
275+
systemType: apiType.value,
276+
}).editUserGroupList(resource, params, loading)
198277
await getUserGroupList()
199-
current.value = { name: current.value?.name as string, id: current.value?.id as string, is_auth: !current.value?.is_auth }
278+
current.value = {
279+
name: current.value?.name as string,
280+
id: current.value?.id as string,
281+
is_auth: !current.value?.is_auth,
282+
}
200283
getList()
201284
} catch (error) {
202285
console.error(error)
@@ -220,7 +303,16 @@ const tableData = ref<ChatUserGroupUserItem[]>([])
220303
async function getList() {
221304
if (!current.value?.id) return
222305
try {
223-
const res = await chatUserAuthAPI.value.getUserGroupUserList(resource, current.value?.id, paginationConfig, searchForm.value.name, rightLoading)
306+
const res = await loadSharedApi({
307+
type: 'chatUser',
308+
systemType: apiType.value,
309+
}).getUserGroupUserList(
310+
resource,
311+
current.value?.id,
312+
paginationConfig,
313+
searchForm.value.name,
314+
rightLoading,
315+
)
224316
tableData.value = res.data.records
225317
paginationConfig.total = res.data.total
226318
} catch (error) {
@@ -233,32 +325,40 @@ function handleSizeChange() {
233325
getList()
234326
}
235327
236-
watch(() => current.value?.id, () => {
237-
getList()
238-
})
328+
watch(
329+
() => current.value?.id,
330+
() => {
331+
getList()
332+
},
333+
)
239334
240-
const allChecked = computed(() =>
241-
tableData.value.length > 0 && tableData.value.every((item: ChatUserGroupUserItem) => item.is_auth)
242-
);
335+
const allChecked = computed(
336+
() =>
337+
tableData.value.length > 0 &&
338+
tableData.value.every((item: ChatUserGroupUserItem) => item.is_auth),
339+
)
243340
244-
const allIndeterminate = computed(() =>
245-
!allChecked.value && tableData.value.some((item: ChatUserGroupUserItem) => item.is_auth)
246-
);
341+
const allIndeterminate = computed(
342+
() => !allChecked.value && tableData.value.some((item: ChatUserGroupUserItem) => item.is_auth),
343+
)
247344
248345
const handleCheckAll = (checked: boolean) => {
249346
tableData.value.forEach((item: ChatUserGroupUserItem) => {
250-
item.is_auth = checked;
251-
});
252-
};
347+
item.is_auth = checked
348+
})
349+
}
253350
254351
const handleRowChange = (value: boolean, row: ChatUserGroupUserItem) => {
255-
row.is_auth = value;
256-
};
352+
row.is_auth = value
353+
}
257354
258355
async function handleSave() {
259356
try {
260-
const params = tableData.value.map(item => ({ chat_user_id: item.id, is_auth: item.is_auth }))
261-
await chatUserAuthAPI.value.putUserGroupUser(resource, current.value?.id as string, params, rightLoading)
357+
const params = tableData.value.map((item) => ({ chat_user_id: item.id, is_auth: item.is_auth }))
358+
await loadSharedApi({
359+
type: 'chatUser',
360+
systemType: apiType.value,
361+
}).putUserGroupUser(resource, current.value?.id as string, params, rightLoading)
262362
MsgSuccess(t('common.saveSuccess'))
263363
} catch (error) {
264364
console.error(error)

0 commit comments

Comments
 (0)