reset localstorage func

This commit is contained in:
RainSun 2020-09-02 22:00:03 +08:00
parent f53442594f
commit dd31401231
12 changed files with 105 additions and 104 deletions

View File

@ -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: {

View File

@ -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]));
}
}

50
src/utils/getStore.js Normal file
View File

@ -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("配置信息初始化完成");
}

View File

@ -201,7 +201,7 @@ export function lang() {
submit: '登录'
},
account: {
label: ['云端信息最后修改时间', '云端信息最后修改设备名', '同步本地密码本至云端', '同步云端密码本至本地'],
label: ['云盘信息最后修改时间', '云盘信息最后修改设备名', '同步本地密码本至云盘', '同步云盘密码本至本地'],
logout: '退出登录'
},
cid_errmsg: ['教务账号不能为空'],

View File

@ -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 (

View File

@ -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) {
//

View File

@ -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) {
//

View File

@ -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) {
//

View File

@ -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("配置信息初始化完成");
},
//

View File

@ -100,6 +100,8 @@
</md-list-item>
</md-list>
<div style="height: 1rem;"></div>
<md-dialog-prompt
:md-active.sync="reset_row_data_active"
v-model="new_row_data"
@ -152,6 +154,7 @@ import {
import { login, activation, 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",
@ -209,13 +212,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) {
//

View File

@ -30,7 +30,10 @@
<p class="center tips">
此密码本为长理专版未开启同步密码将加密后存放本地开启同步密码将加密后存放在您的长理网盘中请放心使用
<span class="qq-link" @click="openQQ()">点我加入用户群</span>
<span
class="qq-link"
@click="openQQ()"
>点我加入用户群</span>
</p>
<md-dialog-confirm
@ -59,6 +62,7 @@ import {
decryptMainCode,
} from "@/utils/aes.js";
import { lang } from "@/utils/language.js";
import { replaceState } from "@/utils/getStore.js";
export default {
name: "Unlock",
@ -92,17 +96,12 @@ export default {
},
},
methods: {
...mapActions(["setRowPwd", "setUserInfo"]),
...mapActions(["setRowPwd", "setSettings", "setUserInfo"]),
//
init() {
// vuex
this.$store.replaceState(
Object.assign(
this.$store.state,
JSON.parse(localStorage.getItem("storeState"))
)
);
// vuex
replaceState.call(this);
this.initLanguage();
//
this.is_create = !this.row_data && !this.user_infos.drivce;

View File

@ -35,6 +35,7 @@
import { mapState } from "vuex";
import { lang } from "@/utils/language.js";
import { setHtmlFontSize } from "@/utils/px2rem.js";
import { replaceState } from "@/utils/getStore.js";
export default {
name: "UpdateLog",
@ -50,6 +51,7 @@ export default {
...mapState(["row_pwd", "settings"]),
},
methods: {
...mapActions(["setSettings", "setUserInfo"]),
// md-app
changeFixed(clientHeight) {
//
@ -67,13 +69,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) {
//