xyyd-fatfox/src/useRouterStore.ts

45 lines
924 B
TypeScript

import { defineStore } from 'pinia'
import { computed, ref, watch } from 'vue'
export type GlobalStr = 'search' | 'block' | 'adder' | 'login' | 'background'
export type SettingStr =
| 'user'
| 'background'
| 'block'
| 'search'
| 'time'
| 'sider'
| 'ai'
| 'dock'
| 'reset'
| 'fallback'
export type CustomStr = 'background'
export type RouteStr = '' | `widget-${string}` | `global-${GlobalStr}` | `settings-${SettingStr}`
export default defineStore('router', () => {
const his = ref<RouteStr[]>([])
const go = (p: RouteStr) => {
his.value.unshift(p)
if (his.value.length > 10) {
his.value.pop()
}
}
const back = () => {
if (his.value.length > 0) {
his.value.shift()
}
}
const path = computed(() => {
return his.value[0] || ''
})
const replace = (path: RouteStr) => {
his.value = [path]
}
return {
path,
go,
back,
replace
}
})