Commit 6cadec98 authored by 郭志伟's avatar 郭志伟

fix: 登录态未存储问题修复

parent 107fbb91
import cookies from "js-cookie"; import Cookies from "js-cookie";
export default { export default {
get(key) { get(key) {
let result = window.localStorage.getItem(key); let result = window.localStorage.getItem(key);
// 如果本地存储拿不到tokenn,那就去cookies拿 // 如果本地存储拿不到tokenn,那就去Cookies拿
if (!result && key === "mongoToken") { if (!result && key === "mongoToken") {
return cookies.get(key) || ""; return Cookies.get(key) || "";
} }
try { try {
return JSON.parse(result); return JSON.parse(result);
...@@ -19,15 +19,16 @@ export default { ...@@ -19,15 +19,16 @@ export default {
if (toString.call(value) === "[object Array]" || toString.call(value) === "[object Object]") { if (toString.call(value) === "[object Array]" || toString.call(value) === "[object Object]") {
value = JSON.stringify(value); value = JSON.stringify(value);
} }
// token存cookies一份,做备份 // token存Cookies一份,做备份
if (key === "mongoToken") { if (key === "mongoToken") {
cookies.set(key, value, { expires: "01/01/2030" }); Cookies.set(key, value, { expires: 3650 });
} }
console.log(value);
return window.localStorage.setItem(key, value); return window.localStorage.setItem(key, value);
}, },
remove(key) { remove(key) {
if (key === "mongoToken") { if (key === "mongoToken") {
cookies.remove(key); Cookies.remove(key);
} }
return window.localStorage.removeItem(key); return window.localStorage.removeItem(key);
}, },
......
...@@ -262,6 +262,12 @@ export default { ...@@ -262,6 +262,12 @@ export default {
}, },
async goPay() { async goPay() {
this.isPayWait = true; this.isPayWait = true;
function getOrderInfo() {
setTimeout(() => {
this.isPayWait = false;
this.$parent.getOrderInfo(true);
}, 1000);
}
try { try {
const res = await goPay({ tradeType: this.tradeType, openId: this.openId }); const res = await goPay({ tradeType: this.tradeType, openId: this.openId });
if (res) { if (res) {
...@@ -296,23 +302,14 @@ export default { ...@@ -296,23 +302,14 @@ export default {
} }
payByWay(this.tradeType, payInfo) payByWay(this.tradeType, payInfo)
.then(() => { .then(() => {
setTimeout(() => { getOrderInfo();
this.isPayWait = false;
this.$parent.getOrderInfo(true);
}, 1000);
}) })
.catch(() => { .catch(() => {
setTimeout(() => { getOrderInfo();
this.isPayWait = false;
this.$parent.getOrderInfo(true);
}, 1000);
}); });
} }
} catch (error) { } catch (error) {
this.isPayWait = false; getOrderInfo();
setTimeout(() => {
this.$parent.getOrderInfo(true);
}, 1000);
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment