refactor: 重构项目结构
- 优化 `车站-设备-告警` 轮询机制 - 改进设备卡片的布局 - 支持修改设备 - 告警轮询中获取完整告警数据 - 车站告警详情支持导出完整的 `今日告警列表` - 支持将状态持久化到 `IndexedDB` - 新增轮询控制 (调试模式) - 新增离线开发模式 (调试模式) - 新增 `IndexedDB` 数据控制 (调试模式)
This commit is contained in:
1
src/plugins/index.ts
Normal file
1
src/plugins/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './pinia';
|
||||
8
src/plugins/pinia/index.ts
Normal file
8
src/plugins/pinia/index.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
declare module 'pinia' {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export interface DefineStoreOptionsBase<S extends StateTree, Store> {
|
||||
persistToIndexedDB?: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
export * from './persist-to-indexeddb';
|
||||
31
src/plugins/pinia/persist-to-indexeddb.ts
Normal file
31
src/plugins/pinia/persist-to-indexeddb.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { useDebounceFn } from '@vueuse/core';
|
||||
import destr from 'destr';
|
||||
import localforage from 'localforage';
|
||||
import type { PiniaPlugin } from 'pinia';
|
||||
|
||||
export const persistToIndexedDB: PiniaPlugin = (context) => {
|
||||
const { options, store } = context;
|
||||
const { persistToIndexedDB } = options;
|
||||
|
||||
if (!persistToIndexedDB) return;
|
||||
|
||||
localforage.getItem<any>(store.$id).then((value) => {
|
||||
if (value) {
|
||||
// store.$patch(value);
|
||||
store.$state = value;
|
||||
}
|
||||
});
|
||||
|
||||
const setItemToIndexedDB = useDebounceFn((state) => {
|
||||
localforage.setItem(store.$id, destr<any>(JSON.stringify(state)));
|
||||
}, 1000);
|
||||
|
||||
store.$subscribe(
|
||||
(mutation, state) => {
|
||||
setItemToIndexedDB(state);
|
||||
},
|
||||
{
|
||||
detached: true,
|
||||
},
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user