mirror of
https://github.com/XiaoDaiGua-Ray/ray-template.git
synced 2026-11-22 19:43:37 +08:00
Restore keyboard navigation and fix page refresh, icons, and table interactions. Guard concurrent edits and align Mock persistence with the API contracts.
56 lines
1.6 KiB
TypeScript
56 lines
1.6 KiB
TypeScript
export interface RuntimeState {
|
|
globalSpinning: boolean
|
|
globalDrawerValue: boolean
|
|
refreshingPath: string | null
|
|
globalMainLayoutLoad: boolean
|
|
layoutContentMaximize: boolean
|
|
layoutContentMaximizeVersion: number
|
|
layoutContentSpinning: boolean
|
|
layoutContentMaximizeStyle: {
|
|
zIndex: number
|
|
backgroundColor?: string
|
|
transition?: string
|
|
}
|
|
}
|
|
|
|
export const piniaRuntimeStore = defineStore('runtime', () => {
|
|
const state = reactive<RuntimeState>({
|
|
globalSpinning: false,
|
|
globalDrawerValue: false,
|
|
refreshingPath: null,
|
|
globalMainLayoutLoad: true,
|
|
layoutContentMaximize: false,
|
|
layoutContentMaximizeVersion: 0,
|
|
layoutContentSpinning: false,
|
|
layoutContentMaximizeStyle: { zIndex: 999 },
|
|
})
|
|
let reloadTimer: ReturnType<typeof setTimeout> | undefined
|
|
|
|
const setRuntimeState = <K extends keyof RuntimeState>(
|
|
key: K,
|
|
value: RuntimeState[K],
|
|
) => {
|
|
if (key === 'layoutContentMaximize' && state[key] !== value) {
|
|
state.layoutContentMaximizeVersion += 1
|
|
}
|
|
|
|
state[key] = value
|
|
}
|
|
|
|
// 刷新会卸载发起调用的页面,计时器必须由 store 持有;重复刷新以最后一次为准。
|
|
const reloadContent = (wait = 800, path: string | null = null) => {
|
|
clearTimeout(reloadTimer)
|
|
state.refreshingPath = path
|
|
state.globalMainLayoutLoad = false
|
|
reloadTimer = setTimeout(() => {
|
|
state.globalMainLayoutLoad = true
|
|
state.refreshingPath = null
|
|
reloadTimer = void 0
|
|
}, wait)
|
|
}
|
|
|
|
onScopeDispose(() => clearTimeout(reloadTimer))
|
|
|
|
return { ...toRefs(state), setRuntimeState, reloadContent }
|
|
})
|