Files
Enterprise-Knowledge-Base/frontend/src/stores/ui.ts
T
wizardchen 5d90019fd0 feat: enhance sidebar functionality and UI responsiveness
- Implemented sidebar collapse and expand functionality, allowing users to toggle the sidebar visibility for a more streamlined interface.
- Updated the `uiStore` to manage sidebar state, persisting the collapsed state in local storage for user preference.
- Enhanced the `menu.vue` and `UserMenu.vue` components to adapt their layout based on the sidebar state, improving usability.
- Added corresponding translations for sidebar actions in English, Korean, Russian, and Chinese, ensuring accessibility for diverse users.
- Refined CSS styles to support the new sidebar behavior, enhancing overall UI consistency and responsiveness.

These changes significantly improve the user experience by providing a more flexible and user-friendly navigation system.
2026-03-05 18:14:14 +08:00

131 lines
4.2 KiB
TypeScript

import { defineStore } from 'pinia'
export const useUIStore = defineStore('ui', {
state: () => ({
showSettingsModal: false,
showKBEditorModal: false,
kbEditorMode: 'create' as 'create' | 'edit',
currentKBId: null as string | null,
kbEditorType: 'document' as 'document' | 'faq',
// 当前选中的分类ID,用于文件上传时传递
selectedTagId: '__untagged__' as string,
kbEditorInitialSection: null as string | null,
settingsInitialSection: null as string | null,
settingsInitialSubSection: null as string | null,
manualEditorVisible: false,
manualEditorMode: 'create' as 'create' | 'edit',
manualEditorKBId: null as string | null,
manualEditorKnowledgeId: null as string | null,
manualEditorInitialTitle: '',
manualEditorInitialContent: '',
manualEditorInitialStatus: 'draft' as 'draft' | 'publish',
manualEditorOnSuccess: null as null | ((payload: { kbId: string; knowledgeId: string; status: 'draft' | 'publish' }) => void),
sidebarCollapsed: localStorage.getItem('sidebar_collapsed') === 'true'
}),
actions: {
openSettings(section?: string, subSection?: string) {
this.settingsInitialSection = section || null
this.settingsInitialSubSection = subSection || null
this.showSettingsModal = true
},
closeSettings() {
this.showSettingsModal = false
this.settingsInitialSection = null
this.settingsInitialSubSection = null
},
toggleSettings() {
this.showSettingsModal = !this.showSettingsModal
},
openKBSettings(kbId: string, initialSection?: string) {
this.currentKBId = kbId
this.kbEditorMode = 'edit'
this.kbEditorType = 'document'
this.kbEditorInitialSection = initialSection || null
this.showKBEditorModal = true
},
openEditKB(kbId: string, initialSection?: string) {
this.openKBSettings(kbId, initialSection)
},
openCreateKB(type: 'document' | 'faq' = 'document') {
this.currentKBId = null
this.kbEditorMode = 'create'
this.kbEditorType = type
this.kbEditorInitialSection = null
this.showKBEditorModal = true
},
closeKBEditor() {
this.showKBEditorModal = false
this.currentKBId = null
this.kbEditorInitialSection = null
this.kbEditorType = 'document'
},
openManualEditor(options: {
mode?: 'create' | 'edit'
kbId?: string | null
knowledgeId?: string | null
title?: string
content?: string
status?: 'draft' | 'publish'
onSuccess?: (payload: { kbId: string; knowledgeId: string; status: 'draft' | 'publish' }) => void
} = {}) {
this.manualEditorMode = options.mode || 'create'
this.manualEditorKBId = options.kbId ?? null
this.manualEditorKnowledgeId = options.knowledgeId ?? null
this.manualEditorInitialTitle = options.title || ''
this.manualEditorInitialContent = options.content || ''
this.manualEditorInitialStatus = options.status || 'draft'
this.manualEditorOnSuccess = options.onSuccess || null
this.manualEditorVisible = true
},
closeManualEditor() {
this.manualEditorVisible = false
this.manualEditorKnowledgeId = null
this.manualEditorInitialContent = ''
this.manualEditorInitialTitle = ''
this.manualEditorInitialStatus = 'draft'
this.manualEditorOnSuccess = null
},
notifyManualEditorSuccess(payload: { kbId: string; knowledgeId: string; status: 'draft' | 'publish' }) {
if (typeof this.manualEditorOnSuccess === 'function') {
try {
this.manualEditorOnSuccess(payload)
} catch (err) {
console.error('Manual editor success callback error:', err)
}
}
this.manualEditorOnSuccess = null
},
// 设置当前选中的分类ID
setSelectedTagId(tagId: string) {
this.selectedTagId = tagId
},
toggleSidebar() {
this.sidebarCollapsed = !this.sidebarCollapsed
localStorage.setItem('sidebar_collapsed', String(this.sidebarCollapsed))
},
collapseSidebar() {
this.sidebarCollapsed = true
localStorage.setItem('sidebar_collapsed', 'true')
},
expandSidebar() {
this.sidebarCollapsed = false
localStorage.setItem('sidebar_collapsed', 'false')
}
}
})