mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 10:02:46 +00:00
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 type { ChatUserGroupItem, ChatUserGroupUserItem, ChatUserResourceParams, putUserGroupUserParams } from '@/api/type/workspaceChatUser'
|
||||
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) => {
|
||||
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>,
|
||||
) => Promise<Result<PageList<ChatUserGroupUserItem[]>>> = (resource, user_group_id, page, username_or_nickname, loading) => {
|
||||
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,
|
||||
loading,
|
||||
)
|
||||
|
|
@ -38,11 +45,11 @@ const putUserGroupUser: (
|
|||
data: putUserGroupUserParams[],
|
||||
loading?: Ref<boolean>,
|
||||
) => 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 {
|
||||
getUserGroupList,
|
||||
getUserGroupUserList,
|
||||
putUserGroupUser
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import type {
|
|||
import type { FormField } from '@/components/dynamics-form/type'
|
||||
|
||||
const prefix = '/system/shared'
|
||||
const workspace_id = localStorage.getItem('workspace_id') || 'default'
|
||||
|
||||
/**
|
||||
* 获得模型列表
|
||||
|
|
|
|||
|
|
@ -11,13 +11,21 @@
|
|||
</el-button>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu v-loading="loading">
|
||||
<el-dropdown-item v-for="item in workspaceList" :key="item.id"
|
||||
:class="item.id === currentWorkspace?.id ? 'active' : ''" @click="changeWorkspace(item)">
|
||||
<el-dropdown-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>
|
||||
<span class="dropdown-item ellipsis">
|
||||
{{ item.name }}
|
||||
</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 />
|
||||
</el-icon>
|
||||
</el-dropdown-item>
|
||||
|
|
@ -30,30 +38,31 @@
|
|||
import { onBeforeMount, ref } from 'vue'
|
||||
import WorkspaceApi from '@/api/workspace'
|
||||
import type { WorkspaceItem } from '@/api/type/workspace'
|
||||
|
||||
import useStore from '@/stores'
|
||||
const { user } = useStore()
|
||||
const loading = ref(false)
|
||||
const workspaceList = ref<WorkspaceItem[]>([])
|
||||
const currentWorkspace = ref()
|
||||
|
||||
async function getWorkspaceList() {
|
||||
try {
|
||||
const res = await WorkspaceApi.getWorkspaceListByUser(loading);
|
||||
const res = await WorkspaceApi.getWorkspaceListByUser(loading)
|
||||
workspaceList.value = res.data
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
|
||||
onBeforeMount(async () => {
|
||||
await getWorkspaceList()
|
||||
const id = localStorage.getItem('workspace_id') ?? 'default'
|
||||
currentWorkspace.value = workspaceList.value.find(item => item.id === id)
|
||||
const id = user.getWorkspaceId() ?? 'default'
|
||||
currentWorkspace.value = workspaceList.value.find((item) => item.id === id)
|
||||
})
|
||||
|
||||
function changeWorkspace(item: WorkspaceItem) {
|
||||
if (item.id === currentWorkspace.value.id) return
|
||||
currentWorkspace.value = item
|
||||
localStorage.setItem('workspace_id', item.id as string)
|
||||
user.setWorkspaceId(item.id || 'default')
|
||||
window.location.reload()
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ const useKnowledgeStore = defineStore('knowledg', {
|
|||
async asyncGetRootKnowledge(loading?: Ref<boolean>) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const params = {
|
||||
folder_id: localStorage.getItem('workspace_id'),
|
||||
folder_id: 'default',
|
||||
}
|
||||
knowledgeApi
|
||||
.getKnowledgeList(params, loading)
|
||||
|
|
|
|||
|
|
@ -48,15 +48,9 @@ const useUserStore = defineStore('user', {
|
|||
changeTheme(data?.['theme'])
|
||||
this.themeInfo = cloneDeep(data)
|
||||
},
|
||||
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()
|
||||
})
|
||||
setWorkspaceId(workspace_id: string) {
|
||||
this.workspace_id = workspace_id
|
||||
localStorage.setItem('workspace_id', workspace_id)
|
||||
},
|
||||
getWorkspaceId(): string | null {
|
||||
if (this.workspace_id) {
|
||||
|
|
@ -68,28 +62,7 @@ const useUserStore = defineStore('user', {
|
|||
}
|
||||
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() {
|
||||
if (this.userInfo) {
|
||||
if (this.isEE()) {
|
||||
|
|
@ -121,16 +94,7 @@ const useUserStore = defineStore('user', {
|
|||
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() {
|
||||
return this.edition != 'CE'
|
||||
},
|
||||
|
|
@ -154,7 +118,49 @@ const useUserStore = defineStore('user', {
|
|||
const login = useLoginStore()
|
||||
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>) {
|
||||
return new Promise((resolve, reject) => {
|
||||
LoginApi.postLanguage({ language: lang }, loading)
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ const props = defineProps({
|
|||
})
|
||||
|
||||
const emit = defineEmits(['addData', 'refresh'])
|
||||
const { folder } = useStore()
|
||||
const { folder, user } = useStore()
|
||||
|
||||
const dialogVisible = ref<boolean>(false)
|
||||
const checkList = ref([])
|
||||
|
|
@ -188,7 +188,7 @@ function getFolder() {
|
|||
|
||||
function getList() {
|
||||
const params = {
|
||||
folder_id: currentFolder.value?.id || localStorage.getItem('workspace_id'),
|
||||
folder_id: currentFolder.value?.id || user.getWorkspaceId(),
|
||||
}
|
||||
KnowledgeApi.getKnowledgeList(params, loading).then((res) => {
|
||||
searchDate.value = res.data
|
||||
|
|
|
|||
|
|
@ -301,7 +301,7 @@ import { PermissionConst, RoleConst } from '@/utils/permission/data'
|
|||
import { hasPermission } from '@/utils/permission/index'
|
||||
|
||||
const router = useRouter()
|
||||
const { folder } = useStore()
|
||||
const { folder, user } = useStore()
|
||||
|
||||
const loading = ref(false)
|
||||
|
||||
|
|
@ -365,9 +365,8 @@ const search_type_change = () => {
|
|||
}
|
||||
|
||||
function getList() {
|
||||
console.log(currentFolder.value?.id)
|
||||
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],
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -312,7 +312,7 @@ function openCreateDialog(data?: any) {
|
|||
|
||||
function getList() {
|
||||
const params = {
|
||||
folder_id: currentFolder.value?.id || localStorage.getItem('workspace_id'),
|
||||
folder_id: currentFolder.value?.id || user.getWorkspaceId(),
|
||||
scope: 'WORKSPACE',
|
||||
}
|
||||
ToolApi.getToolListPage(paginationConfig, params, loading).then((res) => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue