4158773849
- Introduced a new API for organization management, including creation, updating, and deletion of organizations. - Implemented organization sharing functionality for knowledge bases, allowing users to share knowledge bases with specific organizations and set permissions. - Added UI components for organization selection and sharing dialogs. - Enhanced existing components to support organization-related features, including shared knowledge base handling and organization role management. This update enhances collaboration capabilities within the application by allowing users to manage and share knowledge bases across different organizations.
117 lines
2.9 KiB
TypeScript
117 lines
2.9 KiB
TypeScript
import { reactive, ref, watch } from 'vue'
|
|
import { defineStore } from 'pinia'
|
|
import i18n from '@/i18n'
|
|
|
|
type MenuChild = Record<string, any>
|
|
|
|
interface MenuItem {
|
|
title: string
|
|
titleKey?: string
|
|
icon: string
|
|
path: string
|
|
childrenPath?: string
|
|
children?: MenuChild[]
|
|
}
|
|
|
|
const createMenuChildren = () => reactive<MenuChild[]>([])
|
|
|
|
export const useMenuStore = defineStore('menuStore', () => {
|
|
const menuArr = reactive<MenuItem[]>([
|
|
{ title: '', titleKey: 'menu.knowledgeBase', icon: 'zhishiku', path: 'knowledge-bases' },
|
|
{ title: '', titleKey: 'menu.agents', icon: 'agent', path: 'agents' },
|
|
{ title: '', titleKey: 'menu.organizations', icon: 'organization', path: 'organizations' },
|
|
{
|
|
title: '',
|
|
titleKey: 'menu.chat',
|
|
icon: 'prefixIcon',
|
|
path: 'creatChat',
|
|
childrenPath: 'chat',
|
|
children: createMenuChildren()
|
|
},
|
|
{ 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 applyMenuTranslations = () => {
|
|
menuArr.forEach(item => {
|
|
if (item.titleKey) {
|
|
item.title = i18n.global.t(item.titleKey)
|
|
}
|
|
})
|
|
}
|
|
|
|
applyMenuTranslations()
|
|
|
|
watch(
|
|
() => i18n.global.locale.value,
|
|
() => {
|
|
applyMenuTranslations()
|
|
}
|
|
)
|
|
|
|
const clearMenuArr = () => {
|
|
const chatMenu = menuArr[3]
|
|
if (chatMenu && chatMenu.children) {
|
|
chatMenu.children = createMenuChildren()
|
|
}
|
|
}
|
|
|
|
const updatemenuArr = (obj: any) => {
|
|
const chatMenu = menuArr[3]
|
|
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[3]
|
|
if (!chatMenu.children) {
|
|
chatMenu.children = createMenuChildren()
|
|
}
|
|
chatMenu.children.unshift(item)
|
|
}
|
|
|
|
const updatasessionTitle = (sessionId: string, title: string) => {
|
|
const chatMenu = menuArr[3]
|
|
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 = '') => {
|
|
firstQuery.value = payload
|
|
firstMentionedItems.value = mentionedItems
|
|
firstModelId.value = modelId
|
|
}
|
|
|
|
return {
|
|
menuArr,
|
|
isFirstSession,
|
|
firstQuery,
|
|
firstMentionedItems,
|
|
firstModelId,
|
|
clearMenuArr,
|
|
updatemenuArr,
|
|
updataMenuChildren,
|
|
updatasessionTitle,
|
|
changeIsFirstSession,
|
|
changeFirstQuery
|
|
}
|
|
})
|