From 290b254cd8c4c65ce0e39f57a482e0b2d617f016 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=BD=E9=9B=A8=E4=B8=8D=E6=82=94?= Date: Mon, 5 Sep 2022 19:58:32 +0800 Subject: [PATCH] v0.3.0 --- src/App.vue | 2 +- src/pages/loading/index.vue | 2 +- src/pages/site/index.vue | 2 +- src/utils/LocalStorageUtil.ts | 30 ++++++++++++++++-------------- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/App.vue b/src/App.vue index 432abe5..313a541 100644 --- a/src/App.vue +++ b/src/App.vue @@ -337,7 +337,7 @@ export default defineComponent({ id: 0, key: this.$t('app.project_name'), value: '' - }) as Entry; + }); this.initEnvironment(); }); emitter.on(MessageEventEnum.TERMINAL_OPEN, () => { diff --git a/src/pages/loading/index.vue b/src/pages/loading/index.vue index 666adc9..c450269 100644 --- a/src/pages/loading/index.vue +++ b/src/pages/loading/index.vue @@ -109,7 +109,7 @@ export default defineComponent({ console.log('4.3 服务初始化') await imageStrategyContext.init(); await settingService.init(); - environmentService.setId(localStorageUtil.getOrDefault(Constant.LOCALSTORAGE.ENVIRONMENT, 0) as number); + environmentService.setId(localStorageUtil.getOrDefault(Constant.LOCALSTORAGE.ENVIRONMENT, 0)); // 5. 发送消息 console.log('5. 发送消息'); emitter.emit(MessageEventEnum.APP_LAUNCH); diff --git a/src/pages/site/index.vue b/src/pages/site/index.vue index c976266..9c5f912 100644 --- a/src/pages/site/index.vue +++ b/src/pages/site/index.vue @@ -56,7 +56,7 @@ export default defineComponent({ id: 0, key: '', value: '' - }).id; + }).id!; this.sites = settingService.getSite().history; }, methods: { diff --git a/src/utils/LocalStorageUtil.ts b/src/utils/LocalStorageUtil.ts index 634c29c..f30281b 100644 --- a/src/utils/LocalStorageUtil.ts +++ b/src/utils/LocalStorageUtil.ts @@ -1,36 +1,38 @@ export default { - get(name: string): any | undefined{ + get(name: string): any | undefined { let value = localStorage.getItem(name); if (value) { try { return JSON.parse(value); - }catch (e) { + } catch (e) { return value; } - }else { + } else { return undefined; } }, - getOrDefault(name: string, defaultValue: T | string | number): T | string | number { + getOrDefault(name: string, defaultValue: T | string | number): T { let value = localStorage.getItem(name); if (!value) { - return defaultValue; - }else { + return defaultValue as any; + } else { try { - if (typeof defaultValue === 'object') { + if (typeof defaultValue as any === 'object') { return JSON.parse(value); - }else if (typeof defaultValue === "string") { - return value; - }else { + } else if (typeof defaultValue as any === "string") { + return value as any; + } else if (typeof defaultValue as any === "number") { if (value.indexOf('.') > -1) { - return parseFloat(value); + return parseFloat(value) as any; } else { - return parseInt(value) + return parseInt(value) as any; } + } else { + return defaultValue as any; } - }catch (e) { + } catch (e) { return value as any; } } @@ -39,7 +41,7 @@ export default { set(name: string, value: T) { if (typeof value === 'object') { localStorage.setItem(name, JSON.stringify(value)); - }else { + } else { localStorage.setItem(name, value as any); } }