提交 a18fe6e8 编写于 作者: guangjun.yang's avatar guangjun.yang

保存登陆状态

上级 9ad988a9
...@@ -145,7 +145,7 @@ export default { ...@@ -145,7 +145,7 @@ export default {
this.vid = `video_${this._uid}`; this.vid = `video_${this._uid}`;
this.playTime = 0; this.playTime = 0;
const ua = navigator.userAgent; const ua = navigator.userAgent;
// this.isWechat = ua.match(/(MicroMessenger)\/([\d.]+)/); this.isWechat = ua.match(/(MicroMessenger)\/([\d.]+)/);
this.isAndroid = ua.match(/(Android);?[\s\/]+([\d.]+)?/); this.isAndroid = ua.match(/(Android);?[\s\/]+([\d.]+)?/);
}, },
mounted() { mounted() {
......
...@@ -3,6 +3,7 @@ import fetch from '@/utils/fetch'; ...@@ -3,6 +3,7 @@ import fetch from '@/utils/fetch';
import { getBaseUrl } from '@/utils/index' import { getBaseUrl } from '@/utils/index'
import { preLoadImg } from '@/utils/index'; import { preLoadImg } from '@/utils/index';
import { envConfig } from '@/utils/env-config' import { envConfig } from '@/utils/env-config'
import { setCookie, delCookie } from '@/utils/index';
const user = { const user = {
state: { state: {
...@@ -22,6 +23,7 @@ const user = { ...@@ -22,6 +23,7 @@ const user = {
setToken({ commit, dispatch }, params) { setToken({ commit, dispatch }, params) {
commit('SET_TOKEN', params); commit('SET_TOKEN', params);
localStorage.setItem('token', params); localStorage.setItem('token', params);
setCookie('token', params)
dispatch('getUserInfo'); dispatch('getUserInfo');
}, },
// 获取用户信息 // 获取用户信息
...@@ -73,6 +75,7 @@ const user = { ...@@ -73,6 +75,7 @@ const user = {
commit('SET_TOKEN', ''); commit('SET_TOKEN', '');
commit('SET_USER_INFO', {}); commit('SET_USER_INFO', {});
localStorage.removeItem('token'); localStorage.removeItem('token');
delCookie('token')
}, },
}, },
} }
......
...@@ -183,3 +183,29 @@ export function formatLeftTimeObj(time, hasZero = true) { ...@@ -183,3 +183,29 @@ export function formatLeftTimeObj(time, hasZero = true) {
s: hasZero ? formatNum(s) : s, s: hasZero ? formatNum(s) : s,
} }
} }
export const setCookie = (cname, cvalue, exdays = 30, domain = '.yunqueyi.com') => { //yunqueyi.com
let d = new Date(), expires = '';
if (NUXT_ENV_APP === 'dev') {
domain = window.location.hostname;
}
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
expires = `expires=${d.toUTCString()}`;
document.cookie = `${cname}=${cvalue};path=/;${expires};domain=${domain}`;
}
export const getCookie = (cname) => {
const reg = new RegExp('(^| )' + cname + '=([^;]*)(;|$)');
const arr = document.cookie.match(reg);
return arr ? unescape(arr[2]) : null;
}
export const delCookie = (cname) => {
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval = getCookie(cname);
if (cval != null) {
document.cookie = 'token=; path=/; expires=' + new Date(0).toUTCString();
document.cookie = 'token=; path=/; domain=.yunqueyi.com; expires=' + new Date(0).toUTCString();
}
}
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册