@minilo/utils 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/config.d.ts +3 -3
- package/dist/config/config.js +20 -20
- package/dist/config/guider.d.ts +51 -67
- package/dist/config/guider.js +55 -52
- package/dist/config/index.d.ts +6 -6
- package/dist/config/index.js +6 -6
- package/dist/config/storageManager.d.ts +41 -41
- package/dist/config/storageManager.js +100 -92
- package/dist/config/types.d.ts +18 -18
- package/dist/config/types.js +2 -2
- package/dist/config/updateCssVariables.d.ts +11 -14
- package/dist/config/updateCssVariables.js +77 -79
- package/dist/constrant/index.d.ts +5 -5
- package/dist/constrant/index.js +11 -11
- package/dist/func/color.d.ts +5 -5
- package/dist/func/color.js +10 -10
- package/dist/func/common.d.ts +8 -15
- package/dist/func/common.js +58 -54
- package/dist/func/index.d.ts +4 -4
- package/dist/func/index.js +4 -4
- package/dist/func/merge.d.ts +2 -2
- package/dist/func/merge.js +2 -2
- package/dist/hooks/helper.d.ts +6 -0
- package/dist/hooks/helper.d.ts.map +1 -0
- package/dist/hooks/helper.js +45 -0
- package/dist/hooks/helper.js.map +1 -0
- package/dist/hooks/index.d.ts +4 -4
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +4 -4
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/useChartResize.d.ts +20 -0
- package/dist/hooks/useChartResize.d.ts.map +1 -0
- package/dist/hooks/useChartResize.js +67 -0
- package/dist/hooks/useChartResize.js.map +1 -0
- package/dist/hooks/useCountDown.d.ts +9 -0
- package/dist/hooks/useCountDown.d.ts.map +1 -0
- package/dist/hooks/useCountDown.js +42 -0
- package/dist/hooks/useCountDown.js.map +1 -0
- package/dist/hooks/useFormAutoSave.d.ts +2 -0
- package/dist/hooks/useFormAutoSave.d.ts.map +1 -0
- package/dist/hooks/useFormAutoSave.js +73 -0
- package/dist/hooks/useFormAutoSave.js.map +1 -0
- package/dist/hooks/useRouteCache.d.ts +2 -0
- package/dist/hooks/useRouteCache.d.ts.map +1 -0
- package/dist/hooks/useRouteCache.js +92 -0
- package/dist/hooks/useRouteCache.js.map +1 -0
- package/dist/hooks/useScroll.d.ts +15 -0
- package/dist/hooks/useScroll.d.ts.map +1 -0
- package/dist/hooks/useScroll.js +71 -0
- package/dist/hooks/useScroll.js.map +1 -0
- package/dist/hooks/useUpload.d.ts +17 -0
- package/dist/hooks/useUpload.d.ts.map +1 -0
- package/dist/hooks/useUpload.js +87 -0
- package/dist/hooks/useUpload.js.map +1 -0
- package/dist/index.d.ts +6 -6
- package/dist/index.js +6 -6
- package/dist/request/index.d.ts +34 -16
- package/dist/request/index.d.ts.map +1 -1
- package/dist/request/index.js +131 -132
- package/dist/request/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -3
- package/dist/hooks/useButtonPermission.d.ts +0 -9
- package/dist/hooks/useButtonPermission.d.ts.map +0 -1
- package/dist/hooks/useButtonPermission.js +0 -38
- package/dist/hooks/useButtonPermission.js.map +0 -1
- package/dist/hooks/useGuider.d.ts +0 -2
- package/dist/hooks/useGuider.d.ts.map +0 -1
- package/dist/hooks/useGuider.js +0 -5
- package/dist/hooks/useGuider.js.map +0 -1
- package/dist/hooks/useInitGlobalStyle.d.ts +0 -2
- package/dist/hooks/useInitGlobalStyle.d.ts.map +0 -1
- package/dist/hooks/useInitGlobalStyle.js +0 -80
- package/dist/hooks/useInitGlobalStyle.js.map +0 -1
package/dist/config/config.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { Config } from './types'
|
|
2
|
-
export declare const config: Config
|
|
3
|
-
//# sourceMappingURL=config.d.ts.map
|
|
1
|
+
import type { Config } from './types';
|
|
2
|
+
export declare const config: Config;
|
|
3
|
+
//# sourceMappingURL=config.d.ts.map
|
package/dist/config/config.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
export const config = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=config.js.map
|
|
2
|
+
theme: {
|
|
3
|
+
colorDestructive: 'hsl(348 100% 61%)',
|
|
4
|
+
colorPrimary: 'hsl(212 100% 45%)',
|
|
5
|
+
colorSuccess: 'hsl(144 57% 58%)',
|
|
6
|
+
colorWarning: 'hsl(42 84% 61%)'
|
|
7
|
+
},
|
|
8
|
+
sidebar: {
|
|
9
|
+
collapse: false
|
|
10
|
+
},
|
|
11
|
+
app: {
|
|
12
|
+
locale: 'zh-CN',
|
|
13
|
+
name: 'Minilo Adminss',
|
|
14
|
+
logo: '',
|
|
15
|
+
defaultHomePath: '/'
|
|
16
|
+
},
|
|
17
|
+
transition: {
|
|
18
|
+
progress: true
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=config.js.map
|
package/dist/config/guider.d.ts
CHANGED
|
@@ -1,70 +1,54 @@
|
|
|
1
|
-
import type { Config, InitialOptions } from './types'
|
|
1
|
+
import type { Config, InitialOptions } from './types';
|
|
2
2
|
declare class Guider {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
| undefined
|
|
33
|
-
readonly transition?:
|
|
34
|
-
| {
|
|
35
|
-
readonly progress: boolean
|
|
36
|
-
}
|
|
37
|
-
| undefined
|
|
38
|
-
}
|
|
3
|
+
private cache;
|
|
4
|
+
private isInitialized;
|
|
5
|
+
private state;
|
|
6
|
+
constructor();
|
|
7
|
+
initConfig({ config, namespace }: InitialOptions): void;
|
|
8
|
+
updateConfig(config?: Partial<Config>): void;
|
|
9
|
+
saveConfig(config: Config): void;
|
|
10
|
+
private loadConfig;
|
|
11
|
+
getConfig(): {
|
|
12
|
+
readonly app?: {
|
|
13
|
+
readonly locale?: string | undefined;
|
|
14
|
+
readonly name?: string | undefined;
|
|
15
|
+
readonly defaultHomePath?: string | undefined;
|
|
16
|
+
readonly logo?: string | undefined;
|
|
17
|
+
} | undefined;
|
|
18
|
+
readonly theme?: {
|
|
19
|
+
readonly colorDestructive?: string | undefined;
|
|
20
|
+
readonly colorPrimary?: string | undefined;
|
|
21
|
+
readonly colorSuccess?: string | undefined;
|
|
22
|
+
readonly colorWarning?: string | undefined;
|
|
23
|
+
} | undefined;
|
|
24
|
+
readonly sidebar?: {
|
|
25
|
+
readonly collapse: boolean;
|
|
26
|
+
} | undefined;
|
|
27
|
+
readonly transition?: {
|
|
28
|
+
readonly progress: boolean;
|
|
29
|
+
} | undefined;
|
|
30
|
+
};
|
|
39
31
|
}
|
|
40
|
-
declare const guider: Guider
|
|
32
|
+
declare const guider: Guider;
|
|
41
33
|
declare const userConfig: {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
readonly
|
|
45
|
-
readonly
|
|
46
|
-
readonly
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
readonly
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
readonly
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
readonly transition?:
|
|
64
|
-
| {
|
|
65
|
-
readonly progress: boolean
|
|
66
|
-
}
|
|
67
|
-
| undefined
|
|
68
|
-
}
|
|
69
|
-
export { Guider, userConfig, guider }
|
|
70
|
-
//# sourceMappingURL=guider.d.ts.map
|
|
34
|
+
readonly app?: {
|
|
35
|
+
readonly locale?: string | undefined;
|
|
36
|
+
readonly name?: string | undefined;
|
|
37
|
+
readonly defaultHomePath?: string | undefined;
|
|
38
|
+
readonly logo?: string | undefined;
|
|
39
|
+
} | undefined;
|
|
40
|
+
readonly theme?: {
|
|
41
|
+
readonly colorDestructive?: string | undefined;
|
|
42
|
+
readonly colorPrimary?: string | undefined;
|
|
43
|
+
readonly colorSuccess?: string | undefined;
|
|
44
|
+
readonly colorWarning?: string | undefined;
|
|
45
|
+
} | undefined;
|
|
46
|
+
readonly sidebar?: {
|
|
47
|
+
readonly collapse: boolean;
|
|
48
|
+
} | undefined;
|
|
49
|
+
readonly transition?: {
|
|
50
|
+
readonly progress: boolean;
|
|
51
|
+
} | undefined;
|
|
52
|
+
};
|
|
53
|
+
export { Guider, userConfig, guider };
|
|
54
|
+
//# sourceMappingURL=guider.d.ts.map
|
package/dist/config/guider.js
CHANGED
|
@@ -1,57 +1,60 @@
|
|
|
1
|
-
import { markRaw, reactive, readonly } from 'vue'
|
|
2
|
-
import { StorageManager } from './storageManager'
|
|
3
|
-
import { config as defaultConfig } from './config'
|
|
4
|
-
import { merge } from '../func'
|
|
5
|
-
import { updateCSSVariables } from './updateCssVariables'
|
|
6
|
-
const STORAGE_KEY = 'config'
|
|
1
|
+
import { markRaw, reactive, readonly } from 'vue';
|
|
2
|
+
import { StorageManager } from './storageManager';
|
|
3
|
+
import { config as defaultConfig } from './config';
|
|
4
|
+
import { merge } from '../func';
|
|
5
|
+
import { updateCSSVariables } from './updateCssVariables';
|
|
6
|
+
const STORAGE_KEY = 'config';
|
|
7
7
|
// 用户配置引导类
|
|
8
8
|
class Guider {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
constructor() {
|
|
10
|
+
this.isInitialized = false;
|
|
11
|
+
this.state = reactive({
|
|
12
|
+
...this.loadConfig()
|
|
13
|
+
});
|
|
14
|
+
// SSR 兼容性检查:仅在浏览器中创建 StorageManager
|
|
15
|
+
if (typeof window !== 'undefined') {
|
|
16
|
+
this.cache = new StorageManager();
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
this.cache = null;
|
|
20
|
+
}
|
|
19
21
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
// 初始化配置
|
|
23
|
+
initConfig({ config, namespace }) {
|
|
24
|
+
if (this.isInitialized) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
this.cache = new StorageManager({ prefix: namespace });
|
|
28
|
+
const mergeDefaultConfig = merge({}, config, defaultConfig);
|
|
29
|
+
const state = merge({}, this.loadConfig(), mergeDefaultConfig);
|
|
30
|
+
this.updateConfig(state);
|
|
31
|
+
this.isInitialized = true;
|
|
32
|
+
}
|
|
33
|
+
// 更新配置
|
|
34
|
+
updateConfig(config) {
|
|
35
|
+
const cacheState = merge({}, config, markRaw(this.state));
|
|
36
|
+
Object.assign(this.state, cacheState);
|
|
37
|
+
updateCSSVariables(this.state);
|
|
38
|
+
this.saveConfig(this.state);
|
|
39
|
+
}
|
|
40
|
+
// 保存配置
|
|
41
|
+
saveConfig(config) {
|
|
42
|
+
if (!this.cache)
|
|
43
|
+
return;
|
|
44
|
+
this.cache.setItem(STORAGE_KEY, config);
|
|
45
|
+
}
|
|
46
|
+
// 加载配置
|
|
47
|
+
loadConfig() {
|
|
48
|
+
if (!this.cache)
|
|
49
|
+
return undefined;
|
|
50
|
+
return this.cache.getItem(STORAGE_KEY);
|
|
51
|
+
}
|
|
52
|
+
// 获取配置
|
|
53
|
+
getConfig() {
|
|
54
|
+
return readonly(this.state);
|
|
25
55
|
}
|
|
26
|
-
this.cache = new StorageManager({ prefix: namespace })
|
|
27
|
-
const mergeDefaultConfig = merge({}, config, defaultConfig)
|
|
28
|
-
const state = merge({}, this.loadConfig(), mergeDefaultConfig)
|
|
29
|
-
this.updateConfig(state)
|
|
30
|
-
this.isInitialized = true
|
|
31
|
-
}
|
|
32
|
-
// 更新配置
|
|
33
|
-
updateConfig(config) {
|
|
34
|
-
const cacheState = merge({}, config, markRaw(this.state))
|
|
35
|
-
Object.assign(this.state, cacheState)
|
|
36
|
-
updateCSSVariables(this.state)
|
|
37
|
-
this.saveConfig(this.state)
|
|
38
|
-
}
|
|
39
|
-
// 保存配置
|
|
40
|
-
saveConfig(config) {
|
|
41
|
-
if (!this.cache) return
|
|
42
|
-
this.cache.setItem(STORAGE_KEY, config)
|
|
43
|
-
}
|
|
44
|
-
// 加载配置
|
|
45
|
-
loadConfig() {
|
|
46
|
-
if (!this.cache) return undefined
|
|
47
|
-
return this.cache.getItem(STORAGE_KEY)
|
|
48
|
-
}
|
|
49
|
-
// 获取配置
|
|
50
|
-
getConfig() {
|
|
51
|
-
return readonly(this.state)
|
|
52
|
-
}
|
|
53
56
|
}
|
|
54
|
-
const guider = new Guider()
|
|
55
|
-
const userConfig = guider.getConfig()
|
|
56
|
-
export { Guider, userConfig, guider }
|
|
57
|
-
//# sourceMappingURL=guider.js.map
|
|
57
|
+
const guider = new Guider();
|
|
58
|
+
const userConfig = guider.getConfig();
|
|
59
|
+
export { Guider, userConfig, guider };
|
|
60
|
+
//# sourceMappingURL=guider.js.map
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from './config'
|
|
2
|
-
export * from './guider'
|
|
3
|
-
export * from './updateCssVariables'
|
|
4
|
-
export * from './storageManager'
|
|
5
|
-
export * from './types'
|
|
6
|
-
//# sourceMappingURL=index.d.ts.map
|
|
1
|
+
export * from './config';
|
|
2
|
+
export * from './guider';
|
|
3
|
+
export * from './updateCssVariables';
|
|
4
|
+
export * from './storageManager';
|
|
5
|
+
export * from './types';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/config/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from './config'
|
|
2
|
-
export * from './guider'
|
|
3
|
-
export * from './updateCssVariables'
|
|
4
|
-
export * from './storageManager'
|
|
5
|
-
export * from './types'
|
|
6
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export * from './config';
|
|
2
|
+
export * from './guider';
|
|
3
|
+
export * from './updateCssVariables';
|
|
4
|
+
export * from './storageManager';
|
|
5
|
+
export * from './types';
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
type StorageType = 'localStorage' | 'sessionStorage'
|
|
1
|
+
type StorageType = 'localStorage' | 'sessionStorage';
|
|
2
2
|
interface StorageManagerOptions {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
prefix?: string;
|
|
4
|
+
storageType?: StorageType;
|
|
5
5
|
}
|
|
6
6
|
declare class StorageManager {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
7
|
+
private prefix;
|
|
8
|
+
private storage;
|
|
9
|
+
constructor({ prefix, storageType }?: StorageManagerOptions);
|
|
10
|
+
/**
|
|
11
|
+
* 清除所有带前缀的存储项
|
|
12
|
+
*/
|
|
13
|
+
clear(): void;
|
|
14
|
+
/**
|
|
15
|
+
* 清除所有过期的存储项
|
|
16
|
+
*/
|
|
17
|
+
clearExpiredItems(): void;
|
|
18
|
+
/**
|
|
19
|
+
* 获取存储项
|
|
20
|
+
* @param key 键
|
|
21
|
+
* @param defaultValue 当项不存在或已过期时返回的默认值
|
|
22
|
+
* @returns 值,如果项已过期或解析错误则返回默认值
|
|
23
|
+
*/
|
|
24
|
+
getItem<T>(key: string, defaultValue?: null | T): null | T;
|
|
25
|
+
/**
|
|
26
|
+
* 移除存储项
|
|
27
|
+
* @param key 键
|
|
28
|
+
*/
|
|
29
|
+
removeItem(key: string): void;
|
|
30
|
+
/**
|
|
31
|
+
* 设置存储项
|
|
32
|
+
* @param key 键
|
|
33
|
+
* @param value 值
|
|
34
|
+
* @param ttl 存活时间(毫秒)
|
|
35
|
+
*/
|
|
36
|
+
setItem<T>(key: string, value: T, ttl?: number): void;
|
|
37
|
+
/**
|
|
38
|
+
* 获取完整的存储键
|
|
39
|
+
* @param key 原始键
|
|
40
|
+
* @returns 带前缀的完整键
|
|
41
|
+
*/
|
|
42
|
+
private getFullKey;
|
|
43
43
|
}
|
|
44
|
-
export { StorageManager }
|
|
45
|
-
//# sourceMappingURL=storageManager.d.ts.map
|
|
44
|
+
export { StorageManager };
|
|
45
|
+
//# sourceMappingURL=storageManager.d.ts.map
|
|
@@ -1,100 +1,108 @@
|
|
|
1
1
|
class StorageManager {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
constructor({ prefix = '', storageType = 'localStorage' } = {}) {
|
|
3
|
+
this.prefix = prefix;
|
|
4
|
+
// SSR 兼容性检查
|
|
5
|
+
if (typeof window !== 'undefined') {
|
|
6
|
+
this.storage = storageType === 'localStorage' ? window.localStorage : window.sessionStorage;
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
this.storage = null;
|
|
10
|
+
}
|
|
9
11
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
/**
|
|
13
|
+
* 清除所有带前缀的存储项
|
|
14
|
+
*/
|
|
15
|
+
clear() {
|
|
16
|
+
if (!this.storage)
|
|
17
|
+
return;
|
|
18
|
+
const keysToRemove = [];
|
|
19
|
+
for (let i = 0; i < this.storage.length; i++) {
|
|
20
|
+
const key = this.storage.key(i);
|
|
21
|
+
if (key && key.startsWith(this.prefix)) {
|
|
22
|
+
keysToRemove.push(key);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
keysToRemove.forEach((key) => this.storage?.removeItem(key));
|
|
22
26
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
27
|
+
/**
|
|
28
|
+
* 清除所有过期的存储项
|
|
29
|
+
*/
|
|
30
|
+
clearExpiredItems() {
|
|
31
|
+
if (!this.storage)
|
|
32
|
+
return;
|
|
33
|
+
for (let i = 0; i < this.storage.length; i++) {
|
|
34
|
+
const key = this.storage.key(i);
|
|
35
|
+
if (key && key.startsWith(this.prefix)) {
|
|
36
|
+
const shortKey = key.replace(this.prefix, '');
|
|
37
|
+
this.getItem(shortKey); // 调用 getItem 方法检查并移除过期项
|
|
38
|
+
}
|
|
39
|
+
}
|
|
36
40
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
/**
|
|
42
|
+
* 获取存储项
|
|
43
|
+
* @param key 键
|
|
44
|
+
* @param defaultValue 当项不存在或已过期时返回的默认值
|
|
45
|
+
* @returns 值,如果项已过期或解析错误则返回默认值
|
|
46
|
+
*/
|
|
47
|
+
getItem(key, defaultValue = null) {
|
|
48
|
+
if (!this.storage)
|
|
49
|
+
return defaultValue;
|
|
50
|
+
const fullKey = this.getFullKey(key);
|
|
51
|
+
const itemStr = this.storage.getItem(fullKey);
|
|
52
|
+
if (!itemStr) {
|
|
53
|
+
return defaultValue;
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
const item = JSON.parse(itemStr);
|
|
57
|
+
if (item.expiry && Date.now() > item.expiry) {
|
|
58
|
+
this.storage.removeItem(fullKey);
|
|
59
|
+
return defaultValue;
|
|
60
|
+
}
|
|
61
|
+
return item.value;
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
console.error(`Error parsing item with key "${fullKey}":`, error);
|
|
65
|
+
this.storage.removeItem(fullKey); // 如果解析失败,删除该项
|
|
66
|
+
return defaultValue;
|
|
67
|
+
}
|
|
50
68
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
this.storage.removeItem(fullKey) // 如果解析失败,删除该项
|
|
61
|
-
return defaultValue
|
|
69
|
+
/**
|
|
70
|
+
* 移除存储项
|
|
71
|
+
* @param key 键
|
|
72
|
+
*/
|
|
73
|
+
removeItem(key) {
|
|
74
|
+
if (!this.storage)
|
|
75
|
+
return;
|
|
76
|
+
const fullKey = this.getFullKey(key);
|
|
77
|
+
this.storage.removeItem(fullKey);
|
|
62
78
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
79
|
+
/**
|
|
80
|
+
* 设置存储项
|
|
81
|
+
* @param key 键
|
|
82
|
+
* @param value 值
|
|
83
|
+
* @param ttl 存活时间(毫秒)
|
|
84
|
+
*/
|
|
85
|
+
setItem(key, value, ttl) {
|
|
86
|
+
if (!this.storage)
|
|
87
|
+
return;
|
|
88
|
+
const fullKey = this.getFullKey(key);
|
|
89
|
+
const expiry = ttl ? Date.now() + ttl : undefined;
|
|
90
|
+
const item = { expiry, value };
|
|
91
|
+
try {
|
|
92
|
+
this.storage.setItem(fullKey, JSON.stringify(item));
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
console.error(`Error setting item with key "${fullKey}":`, error);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* 获取完整的存储键
|
|
100
|
+
* @param key 原始键
|
|
101
|
+
* @returns 带前缀的完整键
|
|
102
|
+
*/
|
|
103
|
+
getFullKey(key) {
|
|
104
|
+
return `${this.prefix}-${key}`;
|
|
88
105
|
}
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* 获取完整的存储键
|
|
92
|
-
* @param key 原始键
|
|
93
|
-
* @returns 带前缀的完整键
|
|
94
|
-
*/
|
|
95
|
-
getFullKey(key) {
|
|
96
|
-
return `${this.prefix}-${key}`
|
|
97
|
-
}
|
|
98
106
|
}
|
|
99
|
-
export { StorageManager }
|
|
100
|
-
//# sourceMappingURL=storageManager.js.map
|
|
107
|
+
export { StorageManager };
|
|
108
|
+
//# sourceMappingURL=storageManager.js.map
|
package/dist/config/types.d.ts
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
interface InitialOptions {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
namespace: string;
|
|
3
|
+
config?: Partial<Config>;
|
|
4
4
|
}
|
|
5
5
|
interface ThemeConfig {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
colorDestructive?: string;
|
|
7
|
+
colorPrimary?: string;
|
|
8
|
+
colorSuccess?: string;
|
|
9
|
+
colorWarning?: string;
|
|
10
10
|
}
|
|
11
11
|
interface SidebarConfig {
|
|
12
|
-
|
|
12
|
+
collapse: boolean;
|
|
13
13
|
}
|
|
14
14
|
interface TransitionConfig {
|
|
15
|
-
|
|
15
|
+
progress: boolean;
|
|
16
16
|
}
|
|
17
17
|
interface AppConfig {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
locale?: string;
|
|
19
|
+
name?: string;
|
|
20
|
+
defaultHomePath?: string;
|
|
21
|
+
logo?: string;
|
|
22
22
|
}
|
|
23
23
|
interface Config {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
app?: AppConfig;
|
|
25
|
+
theme?: ThemeConfig;
|
|
26
|
+
sidebar?: SidebarConfig;
|
|
27
|
+
transition?: TransitionConfig;
|
|
28
28
|
}
|
|
29
|
-
export type { Config, InitialOptions }
|
|
30
|
-
//# sourceMappingURL=types.d.ts.map
|
|
29
|
+
export type { Config, InitialOptions };
|
|
30
|
+
//# sourceMappingURL=types.d.ts.map
|
package/dist/config/types.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {}
|
|
2
|
-
//# sourceMappingURL=types.js.map
|
|
1
|
+
export {};
|
|
2
|
+
//# sourceMappingURL=types.js.map
|