From dd3140123117b19d772b0495c81953c0d95ca1c6 Mon Sep 17 00:00:00 2001
From: RainSun
Date: Wed, 2 Sep 2020 22:00:03 +0800
Subject: [PATCH] reset localstorage func
---
src/axios/fetch.js | 4 +--
src/store/index.js | 18 +++++++----
src/utils/getStore.js | 50 +++++++++++++++++++++++++++++++
src/utils/language.js | 2 +-
src/views/Account/Account.vue | 12 +++-----
src/views/Add/Add.vue | 13 ++++----
src/views/Detail/Detail.vue | 12 +++-----
src/views/Generator/Generator.vue | 10 ++-----
src/views/Home/Home.vue | 48 ++++-------------------------
src/views/Settings/Settings.vue | 12 ++++----
src/views/Unlock/Unlock.vue | 17 +++++------
src/views/UpdateLog/UpdateLog.vue | 11 +++----
12 files changed, 105 insertions(+), 104 deletions(-)
create mode 100644 src/utils/getStore.js
diff --git a/src/axios/fetch.js b/src/axios/fetch.js
index 9ffce35..a3da614 100644
--- a/src/axios/fetch.js
+++ b/src/axios/fetch.js
@@ -2,9 +2,9 @@ import axios from 'axios'
export const api = axios.create({
// baseURL: 'https://ccb.canary.moe/api/',
- baseURL: window.location.origin + '/api/',
+ // baseURL: window.location.origin + '/api/',
// baseURL: 'https://canary.lacus.site/api/',
- // baseURL: 'https://canary.lacus.icu/api/',
+ baseURL: 'https://canary.lacus.icu/api/',
// baseURL: 'http://beta.lacus.site/api/',
// baseURL: 'http://152.136.99.231:8001' + '/api/',
headers: {
diff --git a/src/store/index.js b/src/store/index.js
index 3c07444..46f89c3 100644
--- a/src/store/index.js
+++ b/src/store/index.js
@@ -44,36 +44,44 @@ export default new Vuex.Store({
commit
}, arg) {
commit('SET_USERINFO', arg[0]);
- localStorage.setItem("storeState", JSON.stringify(arg[1].$store.state));
+ setItem.call(arg[1])
},
// 设置aes化的密码信息
setRowData({
commit
}, arg) {
commit('SET_ROWDATA', arg[0]);
- localStorage.setItem("storeState", JSON.stringify(arg[1].$store.state));
+ setItem.call(arg[1])
},
// 设置aes化的用户主密码
setRowPwd({
commit
}, arg) {
commit('SET_ROWPWD', arg[0]);
- localStorage.setItem("storeState", JSON.stringify(arg[1].$store.state));
+ setItem.call(arg[1])
},
// 设置配置信息
setSettings({
commit
}, arg) {
commit('SET_SETTINGS', arg[0]);
- localStorage.setItem("storeState", JSON.stringify(arg[1].$store.state));
+ setItem.call(arg[1])
},
// 设置主页状态
setHomeState({
commit
}, arg) {
commit('SET_HOMESTATE', arg[0]);
- localStorage.setItem("storeState", JSON.stringify(arg[1].$store.state));
+ setItem.call(arg[1])
},
},
modules: {}
})
+
+
+function setItem() {
+ let state = this.$store.state
+ for(let key of Object.keys(state)) {
+ localStorage.setItem("canary_" + key , JSON.stringify(state[key]));
+ }
+}
\ No newline at end of file
diff --git a/src/utils/getStore.js b/src/utils/getStore.js
new file mode 100644
index 0000000..689f779
--- /dev/null
+++ b/src/utils/getStore.js
@@ -0,0 +1,50 @@
+export function replaceState() {
+ let state = {}
+ for (let key of Object.keys(this.$store.state)) {
+ let content = JSON.parse(localStorage.getItem("canary_" + key))
+ if (content == null) content = ''
+ state[key] = content
+ }
+ this.$store.replaceState(
+ Object.assign(
+ this.$store.state,
+ state
+ )
+ );
+ // 初始化
+ initUserInfo.call(this);
+ initSettings.call(this);
+}
+
+// 初始化用户信息
+function initUserInfo() {
+ if (Object.keys(this.user_infos).length == 0) {
+ // 初始化用户信息
+ let user_infos = {
+ user_name: "A Little Canary",
+ cid: "Codebook",
+ row_login_pwd: "",
+ drivce: "",
+ cloud_drivce: this.settings.is_chinese ? "暂无" : "unknown",
+ update_time: new Date().getTime(),
+ };
+ this.setUserInfo([user_infos, this]);
+ console.log("用户信息覆写完成");
+ }
+ console.log("用户信息初始化完成");
+}
+
+// 初始化配置信息
+function initSettings() {
+ if (Object.keys(this.settings).length == 0) {
+ // 初始化配置信息
+ let settings = {
+ is_chinese: true,
+ is_dark_mode: false,
+ expired_time: 300000, // 5分钟
+ };
+ this.setSettings([settings, this]);
+ console.log("配置信息覆写完成");
+ }
+ console.log("配置信息初始化完成");
+}
\ No newline at end of file
diff --git a/src/utils/language.js b/src/utils/language.js
index 0820587..5cdec2c 100644
--- a/src/utils/language.js
+++ b/src/utils/language.js
@@ -201,7 +201,7 @@ export function lang() {
submit: '登录'
},
account: {
- label: ['云端信息最后修改时间', '云端信息最后修改设备名', '同步本地密码本至云端', '同步云端密码本至本地'],
+ label: ['云盘信息最后修改时间', '云盘信息最后修改设备名', '同步本地密码本至云盘', '同步云盘密码本至本地'],
logout: '退出登录'
},
cid_errmsg: ['教务账号不能为空'],
diff --git a/src/views/Account/Account.vue b/src/views/Account/Account.vue
index d754254..68e833a 100644
--- a/src/views/Account/Account.vue
+++ b/src/views/Account/Account.vue
@@ -123,6 +123,7 @@ import {
import { syncLocal, syncCloud } from "@/axios/api.js";
import { lang } from "@/utils/language.js";
import { setHtmlFontSize } from "@/utils/px2rem.js";
+import { replaceState } from "@/utils/getStore.js";
export default {
name: "Add",
@@ -152,7 +153,7 @@ export default {
},
},
methods: {
- ...mapActions(["setUserInfo", "setRowData", "setRowPwd"]),
+ ...mapActions(["setRowData", "setRowPwd", "setSettings", "setUserInfo"]),
// 修改md-app的最小高度
changeFixed(clientHeight) {
//动态修改样式
@@ -169,13 +170,8 @@ export default {
},
// 初始化
init() {
- // 刷新vuex
- this.$store.replaceState(
- Object.assign(
- this.$store.state,
- JSON.parse(localStorage.getItem("storeState"))
- )
- );
+ // 刷新本页vuex
+ replaceState.call(this);
this.initLanguage();
// 判断页面类型
if (
diff --git a/src/views/Add/Add.vue b/src/views/Add/Add.vue
index 291ea6f..c17a96b 100644
--- a/src/views/Add/Add.vue
+++ b/src/views/Add/Add.vue
@@ -120,6 +120,8 @@ import {
import { lang } from "@/utils/language.js";
import { setHtmlFontSize } from "@/utils/px2rem.js";
import { generatePassword } from "@/utils/generator.js";
+import { replaceState } from "@/utils/getStore.js";
+
export default {
name: "Add",
data() {
@@ -155,7 +157,7 @@ export default {
...mapState(["row_data", "row_pwd", "settings"]),
},
methods: {
- ...mapActions(["setRowData", "setRowPwd"]),
+ ...mapActions(["setRowData", "setRowPwd", "setSettings", "setUserInfo"]),
// 修改md-app的最小高度
changeFixed(clientHeight) {
//动态修改样式
@@ -172,13 +174,8 @@ export default {
},
// 初始化
init() {
- // 刷新vuex
- this.$store.replaceState(
- Object.assign(
- this.$store.state,
- JSON.parse(localStorage.getItem("storeState"))
- )
- );
+ // 刷新本页vuex
+ replaceState.call(this);
// 判断有无用户密码
if (Object.keys(this.row_pwd).length != 0) {
// 有密码,已经输入过了
diff --git a/src/views/Detail/Detail.vue b/src/views/Detail/Detail.vue
index 217aae2..f7fb223 100644
--- a/src/views/Detail/Detail.vue
+++ b/src/views/Detail/Detail.vue
@@ -106,6 +106,7 @@ import {
} from "@/utils/aes.js";
import { lang } from "@/utils/language.js";
import { setHtmlFontSize } from "@/utils/px2rem.js";
+import { replaceState } from "@/utils/getStore.js";
export default {
name: "Add",
@@ -133,7 +134,7 @@ export default {
},
},
methods: {
- ...mapActions(["setRowData", "setRowPwd"]),
+ ...mapActions(["setRowData", "setRowPwd", "setSettings", "setUserInfo"]),
// 修改md-app的最小高度
changeFixed(clientHeight) {
//动态修改样式
@@ -149,13 +150,8 @@ export default {
},
// 初始化
init() {
- // 刷新vuex
- this.$store.replaceState(
- Object.assign(
- this.$store.state,
- JSON.parse(localStorage.getItem("storeState"))
- )
- );
+ // 刷新本页vuex
+ replaceState.call(this);
// 判断是否有参数
if (this.$route.params.code_content) {
// 判断有无用户密码
diff --git a/src/views/Generator/Generator.vue b/src/views/Generator/Generator.vue
index e5751d9..91e8e6f 100644
--- a/src/views/Generator/Generator.vue
+++ b/src/views/Generator/Generator.vue
@@ -78,6 +78,7 @@ import { mapState, mapActions } from "vuex";
import { lang } from "@/utils/language.js";
import { generatePassword } from "@/utils/generator.js";
import { setHtmlFontSize } from "@/utils/px2rem.js";
+import { replaceState } from "@/utils/getStore.js";
export default {
name: "Add",
@@ -127,13 +128,8 @@ export default {
},
// 初始化
init() {
- // 刷新vuex
- this.$store.replaceState(
- Object.assign(
- this.$store.state,
- JSON.parse(localStorage.getItem("storeState"))
- )
- );
+ // 刷新本页vuex
+ replaceState.call(this);
// 判断有无用户密码
if (Object.keys(this.row_pwd).length != 0) {
// 有密码,已经输入过了
diff --git a/src/views/Home/Home.vue b/src/views/Home/Home.vue
index 30fed49..fc045ee 100644
--- a/src/views/Home/Home.vue
+++ b/src/views/Home/Home.vue
@@ -152,6 +152,7 @@ import {
} from "@/utils/aes.js";
import { lang } from "@/utils/language.js";
import { setHtmlFontSize } from "@/utils/px2rem.js";
+import { replaceState } from "@/utils/getStore.js";
export default {
name: "Home",
@@ -215,16 +216,9 @@ export default {
// 初始化
init() {
- // 刷新vuex
- this.$store.replaceState(
- Object.assign(
- this.$store.state,
- JSON.parse(localStorage.getItem("storeState"))
- )
- );
- // 初始化
- this.initUserInfo();
- this.initSettings();
+ // 刷新本页vuex
+ replaceState.call(this);
+ this.initLanguage();
// 判断有无用户密码
if (Object.keys(this.row_pwd).length != 0) {
// 有密码,已经输入过了
@@ -282,44 +276,14 @@ export default {
console.log(this.unlock ? "已解锁" : "未解锁");
},
- // 初始化用户信息
- initUserInfo() {
- if (Object.keys(this.user_infos).length == 0) {
- // 初始化用户信息
- let user_infos = {
- user_name: "A Little Canary",
- cid: "Codebook",
- row_login_pwd: "",
- drivce: "",
- cloud_drivce: this.settings.is_chinese ? "暂无" : "unknown",
- update_time: new Date().getTime(),
- };
- this.setUserInfo([user_infos, this]);
- console.log("用户信息覆写完成");
- }
- console.log("用户信息初始化完成");
- },
-
- // 初始化配置信息
- initSettings() {
- if (Object.keys(this.settings).length == 0) {
- // 初始化配置信息
- let settings = {
- is_chinese: true,
- is_dark_mode: false,
- expired_time: 300000, // 5分钟
- };
- this.setSettings([settings, this]);
- console.log("配置信息覆写完成");
- }
-
+ // 配置语言
+ initLanguage() {
if (this.settings.is_chinese) {
this.lang = lang().home.CHS;
} else {
this.lang = lang().home.EN;
}
console.log("语言配置完成");
- console.log("配置信息初始化完成");
},
// 修改排序
diff --git a/src/views/Settings/Settings.vue b/src/views/Settings/Settings.vue
index a325fc2..d9145a6 100644
--- a/src/views/Settings/Settings.vue
+++ b/src/views/Settings/Settings.vue
@@ -100,6 +100,8 @@
+
+
此密码本为长理专版,未开启同步密码将加密后存放本地,开启同步密码将加密后存放在您的长理网盘中,请放心使用
- 点我加入用户群
+ 点我加入用户群