Skip to content

Commit

Permalink
v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
q2316367743 committed Sep 5, 2022
1 parent cf45efb commit 290b254
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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, () => {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/loading/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/site/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default defineComponent({
id: 0,
key: '',
value: ''
}).id;
}).id!;
this.sites = settingService.getSite().history;
},
methods: {
Expand Down
30 changes: 16 additions & 14 deletions src/utils/LocalStorageUtil.ts
Original file line number Diff line number Diff line change
@@ -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<T>(name: string, defaultValue: T | string | number): T | string | number {
getOrDefault<T>(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;
}
}
Expand All @@ -39,7 +41,7 @@ export default {
set<T>(name: string, value: T) {
if (typeof value === 'object') {
localStorage.setItem(name, JSON.stringify(value));
}else {
} else {
localStorage.setItem(name, value as any);
}
}
Expand Down

0 comments on commit 290b254

Please sign in to comment.