Skip to content

Commit 0374314

Browse files
feat: set workspace_id
1 parent 89ad567 commit 0374314

File tree

8 files changed

+82
-62
lines changed

8 files changed

+82
-62
lines changed

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,20 @@ import { Result } from '@/request/Result'
33
import { get, put } from '@/request/index'
44
import type { ChatUserGroupItem, ChatUserGroupUserItem, ChatUserResourceParams, putUserGroupUserParams } from '@/api/type/workspaceChatUser'
55
import type { pageRequest, PageList } from '@/api/type/common'
6-
const prefix = '/workspace/' + localStorage.getItem('workspace_id')
76

7+
import useStore from '@/stores'
8+
const prefix: any = { _value: '/workspace/' }
9+
Object.defineProperty(prefix, 'value', {
10+
get: function () {
11+
const { user } = useStore()
12+
return this._value + user.getWorkspaceId()
13+
},
14+
})
815
/**
916
* 获取用户组列表
1017
*/
1118
const getUserGroupList: (resource: ChatUserResourceParams, loading?: Ref<boolean>) => Promise<Result<ChatUserGroupItem[]>> = (resource, loading) => {
12-
return get(`${prefix}/${resource.resource_type}/${resource.resource_id}/user_group`, undefined, loading)
19+
return get(`${prefix.value}/${resource.resource_type}/${resource.resource_id}/user_group`, undefined, loading)
1320
}
1421

1522
/**
@@ -23,7 +30,7 @@ const getUserGroupUserList: (
2330
loading?: Ref<boolean>,
2431
) => Promise<Result<PageList<ChatUserGroupUserItem[]>>> = (resource, user_group_id, page, username_or_nickname, loading) => {
2532
return get(
26-
`${prefix}/${resource.resource_type}/${resource.resource_id}/user_group_id/${user_group_id}/${page.current_page}/${page.page_size}`,
33+
`${prefix.value}/${resource.resource_type}/${resource.resource_id}/user_group_id/${user_group_id}/${page.current_page}/${page.page_size}`,
2734
username_or_nickname ? { username_or_nickname } : undefined,
2835
loading,
2936
)
@@ -38,11 +45,11 @@ const putUserGroupUser: (
3845
data: putUserGroupUserParams[],
3946
loading?: Ref<boolean>,
4047
) => Promise<Result<boolean>> = (resource, user_group_id, data, loading) => {
41-
return put(`${prefix}/${resource.resource_type}/${resource.resource_id}/user_group_id/${user_group_id}`, data, undefined, loading)
48+
return put(`${prefix.value}/${resource.resource_type}/${resource.resource_id}/user_group_id/${user_group_id}`, data, undefined, loading)
4249
}
4350

4451
export default {
4552
getUserGroupList,
4653
getUserGroupUserList,
4754
putUserGroupUser
48-
}
55+
}

ui/src/api/shared/model.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import type {
1010
import type { FormField } from '@/components/dynamics-form/type'
1111

1212
const prefix = '/system/shared'
13-
const workspace_id = localStorage.getItem('workspace_id') || 'default'
1413

1514
/**
1615
* 获得模型列表

ui/src/layout/layout-header/workspace-dropdown/index.vue

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,21 @@
1111
</el-button>
1212
<template #dropdown>
1313
<el-dropdown-menu v-loading="loading">
14-
<el-dropdown-item v-for="item in workspaceList" :key="item.id"
15-
:class="item.id === currentWorkspace?.id ? 'active' : ''" @click="changeWorkspace(item)">
14+
<el-dropdown-item
15+
v-for="item in workspaceList"
16+
:key="item.id"
17+
:class="item.id === currentWorkspace?.id ? 'active' : ''"
18+
@click="changeWorkspace(item)"
19+
>
1620
<AppIcon class="mr-8" iconName="app-wordspace" style="font-size: 16px"></AppIcon>
1721
<span class="dropdown-item ellipsis">
1822
{{ item.name }}
1923
</span>
20-
<el-icon v-show="item.id === currentWorkspace?.id" class="ml-8" style="font-size: 16px;margin-right: 0;">
24+
<el-icon
25+
v-show="item.id === currentWorkspace?.id"
26+
class="ml-8"
27+
style="font-size: 16px; margin-right: 0"
28+
>
2129
<Check />
2230
</el-icon>
2331
</el-dropdown-item>
@@ -30,30 +38,31 @@
3038
import { onBeforeMount, ref } from 'vue'
3139
import WorkspaceApi from '@/api/workspace'
3240
import type { WorkspaceItem } from '@/api/type/workspace'
33-
41+
import useStore from '@/stores'
42+
const { user } = useStore()
3443
const loading = ref(false)
3544
const workspaceList = ref<WorkspaceItem[]>([])
3645
const currentWorkspace = ref()
3746
3847
async function getWorkspaceList() {
3948
try {
40-
const res = await WorkspaceApi.getWorkspaceListByUser(loading);
49+
const res = await WorkspaceApi.getWorkspaceListByUser(loading)
4150
workspaceList.value = res.data
4251
} catch (e) {
43-
console.error(e);
52+
console.error(e)
4453
}
4554
}
4655
4756
onBeforeMount(async () => {
4857
await getWorkspaceList()
49-
const id = localStorage.getItem('workspace_id') ?? 'default'
50-
currentWorkspace.value = workspaceList.value.find(item => item.id === id)
58+
const id = user.getWorkspaceId() ?? 'default'
59+
currentWorkspace.value = workspaceList.value.find((item) => item.id === id)
5160
})
5261
5362
function changeWorkspace(item: WorkspaceItem) {
5463
if (item.id === currentWorkspace.value.id) return
5564
currentWorkspace.value = item
56-
localStorage.setItem('workspace_id', item.id as string)
65+
user.setWorkspaceId(item.id || 'default')
5766
window.location.reload()
5867
}
5968
</script>

ui/src/stores/modules-shared-system/knowledge.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const useKnowledgeStore = defineStore('knowledg', {
3434
async asyncGetRootKnowledge(loading?: Ref<boolean>) {
3535
return new Promise((resolve, reject) => {
3636
const params = {
37-
folder_id: localStorage.getItem('workspace_id'),
37+
folder_id: 'default',
3838
}
3939
knowledgeApi
4040
.getKnowledgeList(params, loading)

ui/src/stores/modules/user.ts

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,9 @@ const useUserStore = defineStore('user', {
4848
changeTheme(data?.['theme'])
4949
this.themeInfo = cloneDeep(data)
5050
},
51-
async profile(loading?: Ref<boolean>) {
52-
return UserApi.getUserProfile(loading).then((ok) => {
53-
this.userInfo = ok.data
54-
useLocalStorage<string>(localeConfigKey, 'en-US').value =
55-
ok?.data?.language || this.getLanguage()
56-
const theme = useThemeStore()
57-
theme.setTheme()
58-
return this.asyncGetProfile()
59-
})
51+
setWorkspaceId(workspace_id: string) {
52+
this.workspace_id = workspace_id
53+
localStorage.setItem('workspace_id', workspace_id)
6054
},
6155
getWorkspaceId(): string | null {
6256
if (this.workspace_id) {
@@ -68,28 +62,7 @@ const useUserStore = defineStore('user', {
6862
}
6963
return workspace_id
7064
},
71-
async asyncGetProfile() {
72-
return new Promise((resolve, reject) => {
73-
UserApi.getProfile()
74-
.then(async (ok) => {
75-
// this.version = ok.data?.version || '-'
76-
this.license_is_valid = ok.data.license_is_valid
77-
this.edition = ok.data.edition
7865

79-
if (this.isEE() || this.isPE()) {
80-
await this.theme()
81-
} else {
82-
this.themeInfo = {
83-
...defaultPlatformSetting,
84-
}
85-
}
86-
resolve(ok)
87-
})
88-
.catch((error) => {
89-
reject(error)
90-
})
91-
})
92-
},
9366
getPermissions() {
9467
if (this.userInfo) {
9568
if (this.isEE()) {
@@ -121,16 +94,7 @@ const useUserStore = defineStore('user', {
12194
return []
12295
}
12396
},
124-
async theme(loading?: Ref<boolean>) {
125-
return await ThemeApi.getThemeInfo(loading).then((ok) => {
126-
this.setTheme(ok.data)
127-
// window.document.title = this.themeInfo['title'] || 'MaxKB'
128-
// const link = document.querySelector('link[rel="icon"]') as any
129-
// if (link) {
130-
// link['href'] = this.themeInfo['icon'] || '/favicon.ico'
131-
// }
132-
})
133-
},
97+
13498
showXpack() {
13599
return this.edition != 'CE'
136100
},
@@ -154,7 +118,49 @@ const useUserStore = defineStore('user', {
154118
const login = useLoginStore()
155119
login.userAccessToken = token || ''
156120
},
121+
async theme(loading?: Ref<boolean>) {
122+
return await ThemeApi.getThemeInfo(loading).then((ok) => {
123+
this.setTheme(ok.data)
124+
// window.document.title = this.themeInfo['title'] || 'MaxKB'
125+
// const link = document.querySelector('link[rel="icon"]') as any
126+
// if (link) {
127+
// link['href'] = this.themeInfo['icon'] || '/favicon.ico'
128+
// }
129+
})
130+
},
131+
async profile(loading?: Ref<boolean>) {
132+
return UserApi.getUserProfile(loading).then((ok) => {
133+
this.userInfo = ok.data
134+
useLocalStorage<string>(localeConfigKey, 'en-US').value =
135+
ok?.data?.language || this.getLanguage()
136+
const theme = useThemeStore()
137+
theme.setTheme()
138+
return this.asyncGetProfile()
139+
})
140+
},
157141

142+
async asyncGetProfile() {
143+
return new Promise((resolve, reject) => {
144+
UserApi.getProfile()
145+
.then(async (ok) => {
146+
// this.version = ok.data?.version || '-'
147+
this.license_is_valid = ok.data.license_is_valid
148+
this.edition = ok.data.edition
149+
150+
if (this.isEE() || this.isPE()) {
151+
await this.theme()
152+
} else {
153+
this.themeInfo = {
154+
...defaultPlatformSetting,
155+
}
156+
}
157+
resolve(ok)
158+
})
159+
.catch((error) => {
160+
reject(error)
161+
})
162+
})
163+
},
158164
async postUserLanguage(lang: string, loading?: Ref<boolean>) {
159165
return new Promise((resolve, reject) => {
160166
LoginApi.postLanguage({ language: lang }, loading)

ui/src/views/application/component/AddKnowledgeDialog.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ const props = defineProps({
9999
})
100100
101101
const emit = defineEmits(['addData', 'refresh'])
102-
const { folder } = useStore()
102+
const { folder, user } = useStore()
103103
104104
const dialogVisible = ref<boolean>(false)
105105
const checkList = ref([])
@@ -188,7 +188,7 @@ function getFolder() {
188188
189189
function getList() {
190190
const params = {
191-
folder_id: currentFolder.value?.id || localStorage.getItem('workspace_id'),
191+
folder_id: currentFolder.value?.id || user.getWorkspaceId(),
192192
}
193193
KnowledgeApi.getKnowledgeList(params, loading).then((res) => {
194194
searchDate.value = res.data

ui/src/views/knowledge/index.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ import { PermissionConst, RoleConst } from '@/utils/permission/data'
301301
import { hasPermission } from '@/utils/permission/index'
302302
303303
const router = useRouter()
304-
const { folder } = useStore()
304+
const { folder, user } = useStore()
305305
306306
const loading = ref(false)
307307
@@ -365,9 +365,8 @@ const search_type_change = () => {
365365
}
366366
367367
function getList() {
368-
console.log(currentFolder.value?.id)
369368
const params = {
370-
folder_id: currentFolder.value?.id || localStorage.getItem('workspace_id'),
369+
folder_id: currentFolder.value?.id || user.getWorkspaceId(),
371370
[search_type.value]: search_form.value[search_type.value],
372371
}
373372

ui/src/views/tool/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ function openCreateDialog(data?: any) {
312312
313313
function getList() {
314314
const params = {
315-
folder_id: currentFolder.value?.id || localStorage.getItem('workspace_id'),
315+
folder_id: currentFolder.value?.id || user.getWorkspaceId(),
316316
scope: 'WORKSPACE',
317317
}
318318
ToolApi.getToolListPage(paginationConfig, params, loading).then((res) => {

0 commit comments

Comments
 (0)