deploy-hxtesting / build-and-deploy (push) Successful in 1m20s
2.知识库中的企业培训(课件)、企业培训(试题)、配置中心、组织架构、共享空间如图三所示可查看权限归属到超级管理员权限中!如何对
180 lines
5.5 KiB
TypeScript
180 lines
5.5 KiB
TypeScript
import { reactive, ref, computed, watch } from 'vue'
|
|
import { defineStore } from 'pinia'
|
|
import i18n from '@/i18n'
|
|
import { useAuthStore } from '@/stores/auth'
|
|
import { useDeploymentCapabilitiesStore } from '@/stores/deploymentCapabilities'
|
|
import type { DeploymentCapabilityKey } from '@/config/deploymentCapabilities'
|
|
import type { QuestionOrigin } from '@/utils/questionOrigin'
|
|
|
|
type MenuChild = Record<string, any>
|
|
|
|
interface MenuItem {
|
|
title: string
|
|
titleKey?: string
|
|
icon: string
|
|
path: string
|
|
childrenPath?: string
|
|
children?: MenuChild[]
|
|
requiredCapability?: DeploymentCapabilityKey
|
|
}
|
|
|
|
const createMenuChildren = () => reactive<MenuChild[]>([])
|
|
|
|
export const useMenuStore = defineStore('menuStore', () => {
|
|
const menuArr = reactive<MenuItem[]>([
|
|
{
|
|
title: '',
|
|
titleKey: 'menu.overview',
|
|
icon: 'overview',
|
|
path: 'overview'
|
|
},
|
|
{
|
|
title: '',
|
|
titleKey: 'menu.newChat',
|
|
icon: 'prefixIcon',
|
|
path: 'creatChat',
|
|
childrenPath: 'chat',
|
|
children: createMenuChildren()
|
|
},
|
|
{ title: '', titleKey: 'menu.knowledgeBase', icon: 'zhishiku', path: 'knowledge-bases' },
|
|
// Artifacts only exist where skills run in a sandbox.
|
|
{ title: '', titleKey: 'menu.artifacts', icon: 'artifact', path: 'artifacts', requiredCapability: 'settings.sandbox' },
|
|
{ title: '', titleKey: 'menu.agents', icon: 'agent', path: 'agents', requiredCapability: 'agents' },
|
|
{ title: '', titleKey: 'menu.automations', icon: 'automation', path: 'automations' },
|
|
{ title: '', titleKey: 'menu.training', icon: 'training', path: 'training' },
|
|
{ title: '', titleKey: 'toolbox.title', icon: 'toolbox', path: 'toolbox' },
|
|
{ title: '', titleKey: 'menu.organizations', icon: 'organization', path: 'organizations', requiredCapability: 'organizations' },
|
|
{ title: '', titleKey: 'menu.settings', icon: 'setting', path: 'settings' },
|
|
{ title: '', titleKey: 'menu.logout', icon: 'logout', path: 'logout' }
|
|
])
|
|
|
|
const isFirstSession = ref(false)
|
|
const firstQuery = ref('')
|
|
const firstMentionedItems = ref<any[]>([])
|
|
const firstModelId = ref('')
|
|
const firstImageFiles = ref<any[]>([])
|
|
const firstAttachmentFiles = ref<any[]>([])
|
|
const firstQuestionOrigin = ref<QuestionOrigin | null>(null)
|
|
const prefillQuery = ref('')
|
|
|
|
const applyMenuTranslations = () => {
|
|
menuArr.forEach(item => {
|
|
if (item.titleKey) {
|
|
item.title = i18n.global.t(item.titleKey)
|
|
}
|
|
})
|
|
}
|
|
|
|
applyMenuTranslations()
|
|
|
|
watch(
|
|
() => i18n.global.locale.value,
|
|
() => {
|
|
applyMenuTranslations()
|
|
}
|
|
)
|
|
|
|
const liteHiddenPaths = new Set(['logout', 'organizations'])
|
|
|
|
// 共享空间 (organizations) 仅对平台超级管理员暴露入口(000163 权限收口:
|
|
// 原为空间 admin/owner 可见)。后端 RBAC 才是权限的最终来源(见 middleware/rbac.go)。
|
|
const visibleMenuArr = computed(() => {
|
|
const authStore = useAuthStore()
|
|
const deploymentCapabilities = useDeploymentCapabilitiesStore()
|
|
return menuArr.filter(item => {
|
|
if (authStore.isLiteMode && liteHiddenPaths.has(item.path)) {
|
|
return false
|
|
}
|
|
if (item.path === 'organizations' && !authStore.isSystemAdmin) {
|
|
return false
|
|
}
|
|
if (!deploymentCapabilities.isSupported(item.requiredCapability)) {
|
|
return false
|
|
}
|
|
return true
|
|
})
|
|
})
|
|
|
|
const chatMenuIndex = menuArr.findIndex(item => item.path === 'creatChat')
|
|
|
|
const clearMenuArr = () => {
|
|
const chatMenu = menuArr[chatMenuIndex]
|
|
if (chatMenu && chatMenu.children) {
|
|
chatMenu.children = createMenuChildren()
|
|
}
|
|
}
|
|
|
|
const updatemenuArr = (obj: any) => {
|
|
const chatMenu = menuArr[chatMenuIndex]
|
|
if (!chatMenu.children) {
|
|
chatMenu.children = createMenuChildren()
|
|
}
|
|
const exists = chatMenu.children.some((item: MenuChild) => item.id === obj.id)
|
|
if (!exists) {
|
|
chatMenu.children.push(obj)
|
|
}
|
|
}
|
|
|
|
const updataMenuChildren = (item: MenuChild) => {
|
|
const chatMenu = menuArr[chatMenuIndex]
|
|
if (!chatMenu.children) {
|
|
chatMenu.children = createMenuChildren()
|
|
}
|
|
chatMenu.children.unshift(item)
|
|
}
|
|
|
|
const updatasessionTitle = (sessionId: string, title: string) => {
|
|
const chatMenu = menuArr[chatMenuIndex]
|
|
chatMenu.children?.forEach((item: MenuChild) => {
|
|
if (item.id === sessionId) {
|
|
item.title = title
|
|
item.isNoTitle = false
|
|
}
|
|
})
|
|
}
|
|
|
|
const changeIsFirstSession = (payload: boolean) => {
|
|
isFirstSession.value = payload
|
|
}
|
|
|
|
const changeFirstQuery = (payload: string, mentionedItems: any[] = [], modelId: string = '', imageFiles: any[] = [], attachmentFiles: any[] = [], questionOrigin: QuestionOrigin | null = null) => {
|
|
firstQuery.value = payload
|
|
firstMentionedItems.value = mentionedItems
|
|
firstModelId.value = modelId
|
|
firstImageFiles.value = imageFiles
|
|
firstAttachmentFiles.value = attachmentFiles
|
|
firstQuestionOrigin.value = questionOrigin
|
|
}
|
|
|
|
const setPrefillQuery = (q: string) => {
|
|
prefillQuery.value = q
|
|
}
|
|
|
|
const consumePrefillQuery = () => {
|
|
const q = prefillQuery.value
|
|
prefillQuery.value = ''
|
|
return q
|
|
}
|
|
|
|
return {
|
|
menuArr,
|
|
visibleMenuArr,
|
|
isFirstSession,
|
|
firstQuery,
|
|
firstMentionedItems,
|
|
firstModelId,
|
|
firstImageFiles,
|
|
firstAttachmentFiles,
|
|
firstQuestionOrigin,
|
|
prefillQuery,
|
|
clearMenuArr,
|
|
updatemenuArr,
|
|
updataMenuChildren,
|
|
updatasessionTitle,
|
|
changeIsFirstSession,
|
|
changeFirstQuery,
|
|
setPrefillQuery,
|
|
consumePrefillQuery
|
|
}
|
|
})
|