web-core-tcm 0.0.21 → 0.0.23

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-core-tcm",
3
- "version": "0.0.21",
3
+ "version": "0.0.23",
4
4
  "description": "Core",
5
5
  "productName": "Core",
6
6
  "author": "wywywywywywywywywy <qa123456_0714@qq.com>",
package/quasar.config.ts CHANGED
@@ -63,8 +63,6 @@ export default defineConfig((/* ctx */) => {
63
63
  // minify: false,
64
64
  // polyfillModulePreload: true,
65
65
  // distDir
66
-
67
- // extendViteConf (viteConf) {},
68
66
  // viteVuePluginOptions: {},
69
67
 
70
68
  vitePlugins: [
@@ -20,7 +20,4 @@ mountApis(Apis);
20
20
 
21
21
  export default Apis;
22
22
 
23
- export * from './apiDefinitions';
24
- export * from './createApis';
25
- export * from './globals';
26
- export * from './implement/index';
23
+
@@ -20,7 +20,4 @@ mountApis(Apis);
20
20
 
21
21
  export default Apis;
22
22
 
23
- export * from './apiDefinitions';
24
- export * from './createApis';
25
- export * from './globals.d';
26
- export * from './implement/index';
23
+
@@ -20,7 +20,4 @@ mountApis(Apis);
20
20
 
21
21
  export default Apis;
22
22
 
23
- export * from './apiDefinitions';
24
- export * from './createApis';
25
- export * from './globals';
26
- export * from './implement/index';
23
+
@@ -19,7 +19,4 @@ mountApis(Apis);
19
19
 
20
20
  export default Apis;
21
21
 
22
- export * from './apiDefinitions';
23
- export * from './createApis';
24
- export * from './globals';
25
- export * from './implement/index';
22
+
@@ -20,7 +20,4 @@ mountApis(Apis);
20
20
 
21
21
  export default Apis;
22
22
 
23
- export * from './apiDefinitions';
24
- export * from './createApis';
25
- export * from './globals';
26
- export * from './implement/index';
23
+
@@ -20,8 +20,5 @@ mountApis(Apis);
20
20
 
21
21
  export default Apis;
22
22
 
23
- export * from './apiDefinitions';
24
- export * from './createApis';
25
- export * from './globals.d';
26
- export * from './implement/index';
23
+
27
24
 
@@ -20,7 +20,4 @@ mountApis(Apis);
20
20
 
21
21
  export default Apis;
22
22
 
23
- export * from './apiDefinitions';
24
- export * from './createApis';
25
- export * from './globals.d';
26
- export * from './implement/index';
23
+
@@ -20,7 +20,4 @@ mountApis(Apis);
20
20
 
21
21
  export default Apis;
22
22
 
23
- export * from './apiDefinitions';
24
- export * from './createApis';
25
- export * from './globals.d';
26
- export * from './implement/index';
23
+
@@ -0,0 +1,159 @@
1
+ /** 平台类型 */
2
+ type Platform = 'electron' | 'web';
3
+
4
+ /** 存储操作结果接口 */
5
+ interface StorageResult {
6
+ success: boolean;
7
+ error?: Error;
8
+ }
9
+
10
+ /** Token 操作助手对象 */
11
+ export const tokenHelper = {
12
+ /** 设置 token */
13
+ set: (val: string): StorageResult => {
14
+ try {
15
+ if (getPlatform() === 'electron') {
16
+ window.electronAPI!.setStoreItem('token', val);
17
+ } else {
18
+ window.localStorage.setItem('token', val);
19
+ }
20
+ return { success: true };
21
+ } catch (error) {
22
+ console.error('设置 token 失败:', error);
23
+ return { success: false, error: error as Error };
24
+ }
25
+ },
26
+
27
+ /** 获取 token */
28
+ get: (): string | null => {
29
+ try {
30
+ if (getPlatform() === 'electron') {
31
+ return window.electronAPI!.getStoreItem('token');
32
+ } else {
33
+ return window.localStorage.getItem('token');
34
+ }
35
+ } catch (error) {
36
+ console.error('获取 token 失败:', error);
37
+ return null;
38
+ }
39
+ },
40
+
41
+ /** 移除 token */
42
+ remove: (): StorageResult => {
43
+ try {
44
+ if (getPlatform() === 'electron') {
45
+ window.electronAPI!.setStoreItem('token', '');
46
+ } else {
47
+ window.localStorage.removeItem('token');
48
+ }
49
+ return { success: true };
50
+ } catch (error) {
51
+ console.error('移除 token 失败:', error);
52
+ return { success: false, error: error as Error };
53
+ }
54
+ },
55
+
56
+ /** 检查是否存在 token */
57
+ exists: (): boolean => {
58
+ const token = tokenHelper.get();
59
+ return !!token && token !== '';
60
+ },
61
+ };
62
+
63
+ /** 通用存储操作助手对象 */
64
+ export const storageHelper = {
65
+ /** 设置存储项 */
66
+ setItem: (key: string, val: string): StorageResult => {
67
+ try {
68
+ if (getPlatform() === 'electron') {
69
+ window.electronAPI!.setStoreItem(key, val);
70
+ } else {
71
+ window.localStorage.setItem(key, val);
72
+ }
73
+ return { success: true };
74
+ } catch (error) {
75
+ console.error(`设置存储项 ${key} 失败:`, error);
76
+ return { success: false, error: error as Error };
77
+ }
78
+ },
79
+
80
+ /** 获取存储项 */
81
+ getItem: (key: string): string | null => {
82
+ try {
83
+ if (getPlatform() === 'electron') {
84
+ return window.electronAPI!.getStoreItem(key);
85
+ } else {
86
+ return window.localStorage.getItem(key);
87
+ }
88
+ } catch (error) {
89
+ console.error(`获取存储项 ${key} 失败:`, error);
90
+ return null;
91
+ }
92
+ },
93
+
94
+ /** 移除存储项 */
95
+ removeItem: (key: string): StorageResult => {
96
+ try {
97
+ if (getPlatform() === 'electron') {
98
+ window.electronAPI!.removeStoreItem(key);
99
+ } else {
100
+ window.localStorage.removeItem(key);
101
+ }
102
+ return { success: true };
103
+ } catch (error) {
104
+ console.error(`移除存储项 ${key} 失败:`, error);
105
+ return { success: false, error: error as Error };
106
+ }
107
+ },
108
+
109
+ /** 清空所有存储 */
110
+ clear: (): StorageResult => {
111
+ try {
112
+ if (getPlatform() === 'electron') {
113
+ // 如果是 electron,可能需要实现清空逻辑
114
+ window.localStorage.clear();
115
+ } else {
116
+ window.localStorage.clear();
117
+ }
118
+ return { success: true };
119
+ } catch (error) {
120
+ console.error('清空存储失败:', error);
121
+ return { success: false, error: error as Error };
122
+ }
123
+ },
124
+ };
125
+
126
+ /** 获取当前平台类型 */
127
+ export const getPlatform = (): Platform => {
128
+ // 检查是否在 Electron 环境中
129
+ if (typeof window !== 'undefined' && window.electronAPI?.available) {
130
+ try {
131
+ if (window.electronAPI.available()) {
132
+ return 'electron';
133
+ }
134
+ } catch {
135
+ // 忽略错误,继续检查其他环境
136
+ }
137
+ }
138
+
139
+ // 默认返回 web 环境
140
+ return 'web';
141
+ };
142
+
143
+ // 扩展 Window 接口,添加 electronAPI 的类型定义
144
+ declare global {
145
+ interface Window {
146
+ electronAPI?: {
147
+ available: () => boolean;
148
+ setStoreItem: (key: string, value: string) => void;
149
+ getStoreItem: (key: string) => string | null;
150
+ removeStoreItem: (key: string) => void;
151
+ };
152
+ }
153
+ }
154
+
155
+ export default {
156
+ tokenHelper,
157
+ storageHelper,
158
+ getPlatform,
159
+ };
@@ -1,58 +0,0 @@
1
- /** token操作助手对象 */
2
- export const tokenHelper = {
3
- set: (val) => {
4
- //判断是electron还算web
5
- if (getPlatform() === 'electron') {
6
- window.electronAPI.setStoreItem('token', val);
7
- } else {
8
- window.localStorage.setItem('token', val);
9
- }
10
- },
11
- get: () => {
12
- if (getPlatform() === 'electron') {
13
- return window.electronAPI.getStoreItem('token');
14
- } else {
15
- return window.localStorage.getItem('token') ;
16
- }
17
- },
18
- remove: () => {
19
- //判断是不是electron
20
- if (getPlatform() === 'electron') {
21
- window.electronAPI.setStoreItem('token', '');
22
- } else {
23
- window.localStorage.removeItem('token');
24
- }
25
- },
26
- };
27
- export const storageHelper = {
28
- setItem: (key, val) => {
29
- //判断是electron还是spa,目前都是spa,electron也是spa的分离模式,所以第一个判断不会生效,留作后续。
30
- if (getPlatform() === 'electron') {
31
- window.electronAPI.setStoreItem(key, val);
32
- } else {
33
- window.localStorage.setItem(key, val);
34
- }
35
- },
36
- getItem: (key) => {
37
- if (getPlatform() === 'electron') {
38
- return window.electronAPI.getStoreItem(key);
39
- } else {
40
- return window.localStorage.getItem(key);
41
- }
42
- },
43
- removeItem: (key) => {
44
- if (getPlatform() === 'electron') {
45
- return window.electronAPI.removeStoreItem(key);
46
- } else {
47
- return window.localStorage.removeItem(key);
48
- }
49
- },
50
- };
51
- export const getPlatform = () => {
52
- try {
53
- if (window.electronAPI.available()) return 'electron';
54
- // if(window.electronAPI.available()) return process.env.MODE
55
- } catch {
56
- return process.env.MODE;
57
- }
58
- };