🎈 perf: func

This commit is contained in:
m1m1sha
2024-05-08 19:09:39 +08:00
parent da0777293f
commit bf6b46ec8e
2 changed files with 13 additions and 12 deletions

View File

@@ -73,18 +73,19 @@ export const useNetworkStore = defineStore('networkStore', {
},
loadFromLocalStorage() {
const networkList = JSON.parse(localStorage.getItem('networkList') || '[]')
const result = []
for (const cfg of networkList) {
result.push({
...DEFAULT_NETWORK_CONFIG,
...cfg,
let networkList: NetworkConfig[]
try {
networkList = JSON.parse(localStorage.getItem('networkList') || '[]')
networkList = networkList.map((cfg) => {
return { ...DEFAULT_NETWORK_CONFIG(), ...cfg } as NetworkConfig
})
}
if (result.length === 0)
result.push(DEFAULT_NETWORK_CONFIG)
catch {
networkList = [DEFAULT_NETWORK_CONFIG()]
}
this.networkList = result
this.networkList = networkList
this.curNetwork = this.networkList[0]
},