Files
Enterprise-Knowledge-Base/frontend/src/components/NewUserGuide.vue
T
wizardchen 26895aadc9 feat(user-guide): update NewUserGuide and UserMenu for improved onboarding experience
- Refactored the NewUserGuide component to utilize a new event for opening the guide, enhancing event handling.
- Updated UserMenu to include a button for reopening the guide, improving accessibility for users.
- Enhanced localization strings to provide clearer instructions on accessing the guide from the user menu.
- Introduced a new command in the Global Command Palette to open the product tour, streamlining user onboarding.
- Added styles for new guide-related elements to improve visual consistency and user interaction.
2026-06-04 15:48:04 +08:00

100 lines
2.4 KiB
Vue

<template>
<SpotlightGuide v-model:active="active" :steps="steps" step-i18n-prefix="newUserGuide.steps"
labels-prefix="newUserGuide" @finish="onFinish" @step-change="onStepChange" />
</template>
<script setup lang="ts">
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
import SpotlightGuide from '@/components/SpotlightGuide.vue'
import { GLOBAL_USER_GUIDE_KEY, OPEN_NEW_USER_GUIDE_EVENT } from '@/config/contextualGuides'
import { useUIStore } from '@/stores/ui'
import type { SpotlightGuideStep } from '@/types/spotlightGuide'
const uiStore = useUIStore()
let settingsOpenedByGuide = false
const steps = computed<SpotlightGuideStep[]>(() => [
{ key: 'welcome' },
{
key: 'knowledge',
target: '[data-guide="nav-knowledge-bases"]',
placement: 'right',
before: () => uiStore.expandSidebar(),
},
{
key: 'agents',
target: '[data-guide="nav-agents"]',
placement: 'right',
optional: true,
before: () => uiStore.expandSidebar(),
},
{
key: 'chat',
target: '[data-guide="nav-creatChat"]',
placement: 'right',
before: () => uiStore.expandSidebar(),
},
{
key: 'settings',
target: '[data-guide="user-menu"]',
placement: 'right',
before: () => uiStore.expandSidebar(),
},
{
key: 'models',
target: '[data-guide="settings-add-model"], [data-guide="settings-models"]',
placement: 'left',
before: () => {
uiStore.openSettings('models')
settingsOpenedByGuide = true
},
},
{ key: 'done' },
])
const active = ref(false)
const closeGuideSettings = () => {
if (settingsOpenedByGuide) {
uiStore.closeSettings()
settingsOpenedByGuide = false
}
}
const onFinish = () => {
localStorage.setItem(GLOBAL_USER_GUIDE_KEY, '1')
closeGuideSettings()
}
const onStepChange = ({ toKey }: { toKey: string }) => {
if (toKey !== 'models') {
closeGuideSettings()
}
}
const open = () => {
active.value = true
}
const handleOpenEvent = () => {
if (active.value) return
open()
}
onMounted(() => {
window.addEventListener(OPEN_NEW_USER_GUIDE_EVENT, handleOpenEvent)
if (localStorage.getItem(GLOBAL_USER_GUIDE_KEY) !== '1') {
window.setTimeout(() => {
if (localStorage.getItem(GLOBAL_USER_GUIDE_KEY) !== '1') {
open()
}
}, 700)
}
})
onBeforeUnmount(() => {
window.removeEventListener(OPEN_NEW_USER_GUIDE_EVENT, handleOpenEvent)
closeGuideSettings()
})
</script>