mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 01:33:05 +00:00
fix: workspace (#3320)
Some checks are pending
sync2gitee / repo-sync (push) Waiting to run
Some checks are pending
sync2gitee / repo-sync (push) Waiting to run
This commit is contained in:
parent
7acdd887bf
commit
f40e625ee1
|
|
@ -11,7 +11,6 @@ import os
|
|||
import random
|
||||
import re
|
||||
from collections import defaultdict
|
||||
from itertools import product
|
||||
|
||||
from django.core.cache import cache
|
||||
from django.core.mail.backends.smtp import EmailBackend
|
||||
|
|
@ -71,6 +70,14 @@ def is_workspace_manage(user_id: str, workspace_id: str):
|
|||
return QuerySet(User).filter(id=user_id, role=RoleConstants.ADMIN.value.__str__()).exists()
|
||||
|
||||
|
||||
def get_workspace_list_by_user(user_id):
|
||||
get_workspace_list = DatabaseModelManage.get_model('get_workspace_list_by_user')
|
||||
license_is_valid = DatabaseModelManage.get_model('license_is_valid') or (lambda: False)
|
||||
if get_workspace_list is not None and license_is_valid():
|
||||
return get_workspace_list(user_id)
|
||||
return [{'id': 'default', 'name': 'default'}]
|
||||
|
||||
|
||||
class UserProfileSerializer(serializers.Serializer):
|
||||
@staticmethod
|
||||
def profile(user: User, auth: Auth):
|
||||
|
|
@ -80,6 +87,7 @@ class UserProfileSerializer(serializers.Serializer):
|
|||
@param auth: 认证对象
|
||||
@return:
|
||||
"""
|
||||
workspace_list = get_workspace_list_by_user(user.id)
|
||||
return {
|
||||
'id': user.id,
|
||||
'username': user.username,
|
||||
|
|
@ -89,6 +97,7 @@ class UserProfileSerializer(serializers.Serializer):
|
|||
'permissions': auth.permission_list,
|
||||
'is_edit_password': user.role == RoleConstants.ADMIN.name and user.password == 'd880e722c47a34d8e9fce789fc62389d',
|
||||
'language': user.language,
|
||||
'workspace_list': workspace_list
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ interface User {
|
|||
IS_XPACK?: boolean
|
||||
XPACK_LICENSE_IS_VALID?: boolean
|
||||
language?: string
|
||||
workspace_list?: Array<any>
|
||||
}
|
||||
|
||||
interface LoginRequest {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
<template #dropdown>
|
||||
<el-dropdown-menu v-loading="loading">
|
||||
<el-dropdown-item
|
||||
v-for="item in workspaceList"
|
||||
v-for="item in user.workspace_list"
|
||||
:key="item.id"
|
||||
:class="item.id === currentWorkspace?.id ? 'active' : ''"
|
||||
@click="changeWorkspace(item)"
|
||||
|
|
@ -35,33 +35,20 @@
|
|||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onBeforeMount, ref } from 'vue'
|
||||
import WorkspaceApi from '@/api/workspace/workspace'
|
||||
import { computed, ref } from 'vue'
|
||||
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)
|
||||
workspaceList.value = res.data
|
||||
} catch (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 currentWorkspace = computed(() => {
|
||||
return user.workspace_list.find((w) => w.id == user.workspace_id)
|
||||
})
|
||||
|
||||
function changeWorkspace(item: WorkspaceItem) {
|
||||
if (item.id === currentWorkspace.value.id) return
|
||||
currentWorkspace.value = item
|
||||
if (item.id === user.workspace_id) return
|
||||
|
||||
user.setWorkspaceId(item.id || 'default')
|
||||
window.location.reload()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ export interface userStateTypes {
|
|||
edition: 'CE' | 'PE' | 'EE'
|
||||
themeInfo: any
|
||||
workspace_id: string
|
||||
workspace_list: Array<any>
|
||||
}
|
||||
|
||||
const useUserStore = defineStore('user', {
|
||||
|
|
@ -33,6 +34,7 @@ const useUserStore = defineStore('user', {
|
|||
edition: 'CE',
|
||||
themeInfo: null,
|
||||
workspace_id: '',
|
||||
workspace_list: [],
|
||||
}),
|
||||
actions: {
|
||||
getLanguage() {
|
||||
|
|
@ -125,6 +127,15 @@ const useUserStore = defineStore('user', {
|
|||
async profile(loading?: Ref<boolean>) {
|
||||
return UserApi.getUserProfile(loading).then((ok) => {
|
||||
this.userInfo = ok.data
|
||||
const workspace_list =
|
||||
ok.data.workspace_list && ok.data.workspace_list.length > 0
|
||||
? ok.data.workspace_list
|
||||
: [{ id: 'default', name: 'default' }]
|
||||
const workspace_id = this.getWorkspaceId()
|
||||
if (!workspace_id || !workspace_list.some((w) => w.id == workspace_id)) {
|
||||
this.setWorkspaceId(workspace_list[0].id)
|
||||
}
|
||||
this.workspace_list = workspace_list
|
||||
useLocalStorage<string>(localeConfigKey, 'en-US').value =
|
||||
ok?.data?.language || this.getLanguage()
|
||||
const theme = useThemeStore()
|
||||
|
|
|
|||
Loading…
Reference in New Issue