Files
Enterprise-Knowledge-Base/frontend/src/stores/menu.ts
T
wizardchen 991bd29a14 feat: implement image upload and multimodal support
- Added functionality for image uploads in chat, allowing users to attach images for multimodal Q&A.
- Enhanced the input field to handle image selection via drag-and-drop and paste, with validation for file types and sizes.
- Updated the backend to process images alongside text queries, including support for image analysis.
- Introduced new UI components for image previews and management, improving user interaction with uploaded content.
- Added localization strings for image upload features and error messages, enhancing accessibility for users in multiple languages.

These changes significantly improve the chat experience by enabling users to incorporate images into their queries, facilitating richer interactions and responses.
2026-03-16 02:26:47 +08:00

137 lines
3.5 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.knowledgeSearch', icon: 'search', path: 'knowledge-search' },
{ 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 firstImageFiles = ref<any[]>([])
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 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[] = []) => {
firstQuery.value = payload
firstMentionedItems.value = mentionedItems
firstModelId.value = modelId
firstImageFiles.value = imageFiles
}
const setPrefillQuery = (q: string) => {
prefillQuery.value = q
}
const consumePrefillQuery = () => {
const q = prefillQuery.value
prefillQuery.value = ''
return q
}
return {
menuArr,
isFirstSession,
firstQuery,
firstMentionedItems,
firstModelId,
firstImageFiles,
prefillQuery,
clearMenuArr,
updatemenuArr,
updataMenuChildren,
updatasessionTitle,
changeIsFirstSession,
changeFirstQuery,
setPrefillQuery,
consumePrefillQuery
}
})