XiaoDaiGua-Ray 403fdd589a feat!: rebuild Ray Template as a monorepo
Share workspace packages between Ray Admin and the interactive docs.

BREAKING CHANGE: v6 is a new major line. v5 stays on legacy/v5.
2026-11-04 14:01:28 +08:00

52 lines
1.4 KiB
TypeScript

export interface RuntimeState {
globalSpinning: boolean
globalDrawerValue: boolean
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,
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) => {
clearTimeout(reloadTimer)
state.globalMainLayoutLoad = false
reloadTimer = setTimeout(() => {
state.globalMainLayoutLoad = true
reloadTimer = void 0
}, wait)
}
onScopeDispose(() => clearTimeout(reloadTimer))
return { ...toRefs(state), setRuntimeState, reloadContent }
})