feat: set workspace_id
This commit is contained in:
parent
89ad56744b
commit
037431487d
@ -3,13 +3,20 @@ import { Result } from '@/request/Result'
|
|||||||
import { get, put } from '@/request/index'
|
import { get, put } from '@/request/index'
|
||||||
import type { ChatUserGroupItem, ChatUserGroupUserItem, ChatUserResourceParams, putUserGroupUserParams } from '@/api/type/workspaceChatUser'
|
import type { ChatUserGroupItem, ChatUserGroupUserItem, ChatUserResourceParams, putUserGroupUserParams } from '@/api/type/workspaceChatUser'
|
||||||
import type { pageRequest, PageList } from '@/api/type/common'
|
import type { pageRequest, PageList } from '@/api/type/common'
|
||||||
const prefix = '/workspace/' + localStorage.getItem('workspace_id')
|
|
||||||
|
|
||||||
|
import useStore from '@/stores'
|
||||||
|
const prefix: any = { _value: '/workspace/' }
|
||||||
|
Object.defineProperty(prefix, 'value', {
|
||||||
|
get: function () {
|
||||||
|
const { user } = useStore()
|
||||||
|
return this._value + user.getWorkspaceId()
|
||||||
|
},
|
||||||
|
})
|
||||||
/**
|
/**
|
||||||
* 获取用户组列表
|
* 获取用户组列表
|
||||||
*/
|
*/
|
||||||
const getUserGroupList: (resource: ChatUserResourceParams, loading?: Ref<boolean>) => Promise<Result<ChatUserGroupItem[]>> = (resource, loading) => {
|
const getUserGroupList: (resource: ChatUserResourceParams, loading?: Ref<boolean>) => Promise<Result<ChatUserGroupItem[]>> = (resource, loading) => {
|
||||||
return get(`${prefix}/${resource.resource_type}/${resource.resource_id}/user_group`, undefined, loading)
|
return get(`${prefix.value}/${resource.resource_type}/${resource.resource_id}/user_group`, undefined, loading)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,7 +30,7 @@ const getUserGroupUserList: (
|
|||||||
loading?: Ref<boolean>,
|
loading?: Ref<boolean>,
|
||||||
) => Promise<Result<PageList<ChatUserGroupUserItem[]>>> = (resource, user_group_id, page, username_or_nickname, loading) => {
|
) => Promise<Result<PageList<ChatUserGroupUserItem[]>>> = (resource, user_group_id, page, username_or_nickname, loading) => {
|
||||||
return get(
|
return get(
|
||||||
`${prefix}/${resource.resource_type}/${resource.resource_id}/user_group_id/${user_group_id}/${page.current_page}/${page.page_size}`,
|
`${prefix.value}/${resource.resource_type}/${resource.resource_id}/user_group_id/${user_group_id}/${page.current_page}/${page.page_size}`,
|
||||||
username_or_nickname ? { username_or_nickname } : undefined,
|
username_or_nickname ? { username_or_nickname } : undefined,
|
||||||
loading,
|
loading,
|
||||||
)
|
)
|
||||||
@ -38,7 +45,7 @@ const putUserGroupUser: (
|
|||||||
data: putUserGroupUserParams[],
|
data: putUserGroupUserParams[],
|
||||||
loading?: Ref<boolean>,
|
loading?: Ref<boolean>,
|
||||||
) => Promise<Result<boolean>> = (resource, user_group_id, data, loading) => {
|
) => Promise<Result<boolean>> = (resource, user_group_id, data, loading) => {
|
||||||
return put(`${prefix}/${resource.resource_type}/${resource.resource_id}/user_group_id/${user_group_id}`, data, undefined, loading)
|
return put(`${prefix.value}/${resource.resource_type}/${resource.resource_id}/user_group_id/${user_group_id}`, data, undefined, loading)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|||||||
@ -10,7 +10,6 @@ import type {
|
|||||||
import type { FormField } from '@/components/dynamics-form/type'
|
import type { FormField } from '@/components/dynamics-form/type'
|
||||||
|
|
||||||
const prefix = '/system/shared'
|
const prefix = '/system/shared'
|
||||||
const workspace_id = localStorage.getItem('workspace_id') || 'default'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得模型列表
|
* 获得模型列表
|
||||||
|
|||||||
@ -11,13 +11,21 @@
|
|||||||
</el-button>
|
</el-button>
|
||||||
<template #dropdown>
|
<template #dropdown>
|
||||||
<el-dropdown-menu v-loading="loading">
|
<el-dropdown-menu v-loading="loading">
|
||||||
<el-dropdown-item v-for="item in workspaceList" :key="item.id"
|
<el-dropdown-item
|
||||||
:class="item.id === currentWorkspace?.id ? 'active' : ''" @click="changeWorkspace(item)">
|
v-for="item in workspaceList"
|
||||||
|
:key="item.id"
|
||||||
|
:class="item.id === currentWorkspace?.id ? 'active' : ''"
|
||||||
|
@click="changeWorkspace(item)"
|
||||||
|
>
|
||||||
<AppIcon class="mr-8" iconName="app-wordspace" style="font-size: 16px"></AppIcon>
|
<AppIcon class="mr-8" iconName="app-wordspace" style="font-size: 16px"></AppIcon>
|
||||||
<span class="dropdown-item ellipsis">
|
<span class="dropdown-item ellipsis">
|
||||||
{{ item.name }}
|
{{ item.name }}
|
||||||
</span>
|
</span>
|
||||||
<el-icon v-show="item.id === currentWorkspace?.id" class="ml-8" style="font-size: 16px;margin-right: 0;">
|
<el-icon
|
||||||
|
v-show="item.id === currentWorkspace?.id"
|
||||||
|
class="ml-8"
|
||||||
|
style="font-size: 16px; margin-right: 0"
|
||||||
|
>
|
||||||
<Check />
|
<Check />
|
||||||
</el-icon>
|
</el-icon>
|
||||||
</el-dropdown-item>
|
</el-dropdown-item>
|
||||||
@ -30,30 +38,31 @@
|
|||||||
import { onBeforeMount, ref } from 'vue'
|
import { onBeforeMount, ref } from 'vue'
|
||||||
import WorkspaceApi from '@/api/workspace'
|
import WorkspaceApi from '@/api/workspace'
|
||||||
import type { WorkspaceItem } from '@/api/type/workspace'
|
import type { WorkspaceItem } from '@/api/type/workspace'
|
||||||
|
import useStore from '@/stores'
|
||||||
|
const { user } = useStore()
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const workspaceList = ref<WorkspaceItem[]>([])
|
const workspaceList = ref<WorkspaceItem[]>([])
|
||||||
const currentWorkspace = ref()
|
const currentWorkspace = ref()
|
||||||
|
|
||||||
async function getWorkspaceList() {
|
async function getWorkspaceList() {
|
||||||
try {
|
try {
|
||||||
const res = await WorkspaceApi.getWorkspaceListByUser(loading);
|
const res = await WorkspaceApi.getWorkspaceListByUser(loading)
|
||||||
workspaceList.value = res.data
|
workspaceList.value = res.data
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onBeforeMount(async () => {
|
onBeforeMount(async () => {
|
||||||
await getWorkspaceList()
|
await getWorkspaceList()
|
||||||
const id = localStorage.getItem('workspace_id') ?? 'default'
|
const id = user.getWorkspaceId() ?? 'default'
|
||||||
currentWorkspace.value = workspaceList.value.find(item => item.id === id)
|
currentWorkspace.value = workspaceList.value.find((item) => item.id === id)
|
||||||
})
|
})
|
||||||
|
|
||||||
function changeWorkspace(item: WorkspaceItem) {
|
function changeWorkspace(item: WorkspaceItem) {
|
||||||
if (item.id === currentWorkspace.value.id) return
|
if (item.id === currentWorkspace.value.id) return
|
||||||
currentWorkspace.value = item
|
currentWorkspace.value = item
|
||||||
localStorage.setItem('workspace_id', item.id as string)
|
user.setWorkspaceId(item.id || 'default')
|
||||||
window.location.reload()
|
window.location.reload()
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -34,7 +34,7 @@ const useKnowledgeStore = defineStore('knowledg', {
|
|||||||
async asyncGetRootKnowledge(loading?: Ref<boolean>) {
|
async asyncGetRootKnowledge(loading?: Ref<boolean>) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const params = {
|
const params = {
|
||||||
folder_id: localStorage.getItem('workspace_id'),
|
folder_id: 'default',
|
||||||
}
|
}
|
||||||
knowledgeApi
|
knowledgeApi
|
||||||
.getKnowledgeList(params, loading)
|
.getKnowledgeList(params, loading)
|
||||||
|
|||||||
@ -48,15 +48,9 @@ const useUserStore = defineStore('user', {
|
|||||||
changeTheme(data?.['theme'])
|
changeTheme(data?.['theme'])
|
||||||
this.themeInfo = cloneDeep(data)
|
this.themeInfo = cloneDeep(data)
|
||||||
},
|
},
|
||||||
async profile(loading?: Ref<boolean>) {
|
setWorkspaceId(workspace_id: string) {
|
||||||
return UserApi.getUserProfile(loading).then((ok) => {
|
this.workspace_id = workspace_id
|
||||||
this.userInfo = ok.data
|
localStorage.setItem('workspace_id', workspace_id)
|
||||||
useLocalStorage<string>(localeConfigKey, 'en-US').value =
|
|
||||||
ok?.data?.language || this.getLanguage()
|
|
||||||
const theme = useThemeStore()
|
|
||||||
theme.setTheme()
|
|
||||||
return this.asyncGetProfile()
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
getWorkspaceId(): string | null {
|
getWorkspaceId(): string | null {
|
||||||
if (this.workspace_id) {
|
if (this.workspace_id) {
|
||||||
@ -68,28 +62,7 @@ const useUserStore = defineStore('user', {
|
|||||||
}
|
}
|
||||||
return workspace_id
|
return workspace_id
|
||||||
},
|
},
|
||||||
async asyncGetProfile() {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
UserApi.getProfile()
|
|
||||||
.then(async (ok) => {
|
|
||||||
// this.version = ok.data?.version || '-'
|
|
||||||
this.license_is_valid = ok.data.license_is_valid
|
|
||||||
this.edition = ok.data.edition
|
|
||||||
|
|
||||||
if (this.isEE() || this.isPE()) {
|
|
||||||
await this.theme()
|
|
||||||
} else {
|
|
||||||
this.themeInfo = {
|
|
||||||
...defaultPlatformSetting,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
resolve(ok)
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
reject(error)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
},
|
|
||||||
getPermissions() {
|
getPermissions() {
|
||||||
if (this.userInfo) {
|
if (this.userInfo) {
|
||||||
if (this.isEE()) {
|
if (this.isEE()) {
|
||||||
@ -121,16 +94,7 @@ const useUserStore = defineStore('user', {
|
|||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async theme(loading?: Ref<boolean>) {
|
|
||||||
return await ThemeApi.getThemeInfo(loading).then((ok) => {
|
|
||||||
this.setTheme(ok.data)
|
|
||||||
// window.document.title = this.themeInfo['title'] || 'MaxKB'
|
|
||||||
// const link = document.querySelector('link[rel="icon"]') as any
|
|
||||||
// if (link) {
|
|
||||||
// link['href'] = this.themeInfo['icon'] || '/favicon.ico'
|
|
||||||
// }
|
|
||||||
})
|
|
||||||
},
|
|
||||||
showXpack() {
|
showXpack() {
|
||||||
return this.edition != 'CE'
|
return this.edition != 'CE'
|
||||||
},
|
},
|
||||||
@ -154,7 +118,49 @@ const useUserStore = defineStore('user', {
|
|||||||
const login = useLoginStore()
|
const login = useLoginStore()
|
||||||
login.userAccessToken = token || ''
|
login.userAccessToken = token || ''
|
||||||
},
|
},
|
||||||
|
async theme(loading?: Ref<boolean>) {
|
||||||
|
return await ThemeApi.getThemeInfo(loading).then((ok) => {
|
||||||
|
this.setTheme(ok.data)
|
||||||
|
// window.document.title = this.themeInfo['title'] || 'MaxKB'
|
||||||
|
// const link = document.querySelector('link[rel="icon"]') as any
|
||||||
|
// if (link) {
|
||||||
|
// link['href'] = this.themeInfo['icon'] || '/favicon.ico'
|
||||||
|
// }
|
||||||
|
})
|
||||||
|
},
|
||||||
|
async profile(loading?: Ref<boolean>) {
|
||||||
|
return UserApi.getUserProfile(loading).then((ok) => {
|
||||||
|
this.userInfo = ok.data
|
||||||
|
useLocalStorage<string>(localeConfigKey, 'en-US').value =
|
||||||
|
ok?.data?.language || this.getLanguage()
|
||||||
|
const theme = useThemeStore()
|
||||||
|
theme.setTheme()
|
||||||
|
return this.asyncGetProfile()
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
async asyncGetProfile() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
UserApi.getProfile()
|
||||||
|
.then(async (ok) => {
|
||||||
|
// this.version = ok.data?.version || '-'
|
||||||
|
this.license_is_valid = ok.data.license_is_valid
|
||||||
|
this.edition = ok.data.edition
|
||||||
|
|
||||||
|
if (this.isEE() || this.isPE()) {
|
||||||
|
await this.theme()
|
||||||
|
} else {
|
||||||
|
this.themeInfo = {
|
||||||
|
...defaultPlatformSetting,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resolve(ok)
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
reject(error)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
async postUserLanguage(lang: string, loading?: Ref<boolean>) {
|
async postUserLanguage(lang: string, loading?: Ref<boolean>) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
LoginApi.postLanguage({ language: lang }, loading)
|
LoginApi.postLanguage({ language: lang }, loading)
|
||||||
|
|||||||
@ -99,7 +99,7 @@ const props = defineProps({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const emit = defineEmits(['addData', 'refresh'])
|
const emit = defineEmits(['addData', 'refresh'])
|
||||||
const { folder } = useStore()
|
const { folder, user } = useStore()
|
||||||
|
|
||||||
const dialogVisible = ref<boolean>(false)
|
const dialogVisible = ref<boolean>(false)
|
||||||
const checkList = ref([])
|
const checkList = ref([])
|
||||||
@ -188,7 +188,7 @@ function getFolder() {
|
|||||||
|
|
||||||
function getList() {
|
function getList() {
|
||||||
const params = {
|
const params = {
|
||||||
folder_id: currentFolder.value?.id || localStorage.getItem('workspace_id'),
|
folder_id: currentFolder.value?.id || user.getWorkspaceId(),
|
||||||
}
|
}
|
||||||
KnowledgeApi.getKnowledgeList(params, loading).then((res) => {
|
KnowledgeApi.getKnowledgeList(params, loading).then((res) => {
|
||||||
searchDate.value = res.data
|
searchDate.value = res.data
|
||||||
|
|||||||
@ -301,7 +301,7 @@ import { PermissionConst, RoleConst } from '@/utils/permission/data'
|
|||||||
import { hasPermission } from '@/utils/permission/index'
|
import { hasPermission } from '@/utils/permission/index'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const { folder } = useStore()
|
const { folder, user } = useStore()
|
||||||
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
|
|
||||||
@ -365,9 +365,8 @@ const search_type_change = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getList() {
|
function getList() {
|
||||||
console.log(currentFolder.value?.id)
|
|
||||||
const params = {
|
const params = {
|
||||||
folder_id: currentFolder.value?.id || localStorage.getItem('workspace_id'),
|
folder_id: currentFolder.value?.id || user.getWorkspaceId(),
|
||||||
[search_type.value]: search_form.value[search_type.value],
|
[search_type.value]: search_form.value[search_type.value],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -312,7 +312,7 @@ function openCreateDialog(data?: any) {
|
|||||||
|
|
||||||
function getList() {
|
function getList() {
|
||||||
const params = {
|
const params = {
|
||||||
folder_id: currentFolder.value?.id || localStorage.getItem('workspace_id'),
|
folder_id: currentFolder.value?.id || user.getWorkspaceId(),
|
||||||
scope: 'WORKSPACE',
|
scope: 'WORKSPACE',
|
||||||
}
|
}
|
||||||
ToolApi.getToolListPage(paginationConfig, params, loading).then((res) => {
|
ToolApi.getToolListPage(paginationConfig, params, loading).then((res) => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user