(set: (s: Partial<BootstrapState>) => void)
| 22 | } |
| 23 | |
| 24 | async function loadOnce(set: (s: Partial<BootstrapState>) => void) { |
| 25 | set({ loading: true, error: null }); |
| 26 | try { |
| 27 | const info = await fetchBootstrap(); |
| 28 | set({ info, loading: false, error: null }); |
| 29 | // 同步站点标题到 document |
| 30 | if (info?.site_title) { |
| 31 | try { |
| 32 | document.title = info.site_title; |
| 33 | } catch { |
| 34 | /* SSR safe */ |
| 35 | } |
| 36 | } |
| 37 | } catch (e: any) { |
| 38 | set({ |
| 39 | info: null, |
| 40 | loading: false, |
| 41 | error: e?.message ?? '获取系统状态失败', |
| 42 | }); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | export const useBootstrapStore = create<BootstrapState>((set, get) => ({ |
| 47 | info: null, |
no test coverage detected