Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.$refs[formName].validate(async (valid) => {
if (valid) {
const res = await this.userLogin(this.ruleForm);
this.showMessage('登录成功!');
// 关联模态框
Vue.ls.set('BOBLOG_FE_TOKEN', res.data.token);
this.$store.commit('user/SHOW_USER_MANAGER_MODEL', false);
// 登录
const BOBLOG_FE_TOKEN = Vue.ls.get('BOBLOG_FE_TOKEN');
await this.$store.dispatch('user/getUserInfo', {
username: BOBLOG_FE_TOKEN
});
} else {
this.showMessage('请完善表单', 'error');
return false;
}
});
},
export const getTokenFromStorage = (req) => {
if (process.server) {
const cookie = require('cookie') // request parser for the cookie
const cookies = cookie.parse(req.headers.cookie || '')
return {
user: cookies.user_credentials && JSON.parse(cookies.user_credentials)
}
}
const user = Vue.ls.get('user_credentials')
return {
user
}
}
router.beforeEach(async (to, from, next) => {
iView.LoadingBar.start();
Util.title(to.meta.title)
let token = Vue.ls.get("token");
if (token) {
store.dispatch('admin/auth').then(() => {
next()
}).catch(err => {
Vue.prototype.$Message.error(err.data.msg || '权限未授权')
setTimeout(() => {
next('/login')
}, 1500);
})
} else {
// 判断是否需要登录
if (!!to.meta.noAuth) {
next()
utils.ajax.interceptors.request.use((config) => {
const isLoading = config.isLoading || config.isLoading === undefined
if (isLoading) {
// 开启loading
store.dispatch('loading/openLoading')
}
// 获取token
config.headers.common.Authorization = `Bearer ${Vue.ls.get('WATCH_CHECK_TOKEN')}`
return config
}, error => Promise.reject(error))
test('Add/Remove event', (t) => {
t.plan(2);
Vue.ls.on('item_one_test', () => {});
Vue.ls.on('item_two_test', () => {});
Vue.ls.on('item_two_test', () => {});
Vue.ls.on('item_three_test', (val, oldVal) => {
t.is(val, 'val');
t.is(oldVal, 'old_val');
});
Vue.ls.off('item_two_test', () => {});
Vue.ls.off('item_one_test', () => {});
StorageEvent.emit({
key: 'item_three_test',
newValue: JSON.stringify({ value: 'val', expire: null }),
oldValue: JSON.stringify({ value: 'old_val', expire: null }),
});
StorageEvent.emit({
key: 'item_undefined_test',
newValue: JSON.stringify({ value: 'val', expire: null }),
test('Add/Remove event', (t) => {
t.plan(4);
Vue.ls.on('item_one_test', () => {});
Vue.ls.on('item_two_test', () => {});
Vue.ls.on('item_two_test', () => {});
Vue.ls.on('item_three_test', (val, oldVal) => {
t.is(val, 'val');
t.is(oldVal, 'old_val');
});
Vue.ls.off('item_two_test', () => {});
Vue.ls.off('item_one_test', () => {});
Vue.ls.off('item_one_test', () => {});
StorageEvent.emit({
key: 'item_three_test',
newValue: JSON.stringify({ value: 'val', expire: null }),
oldValue: JSON.stringify({ value: 'old_val', expire: null }),
});
StorageEvent.emit({
login(userInfo).then(response => {
Vue.ls.set(ACCESS_TOKEN, response.token, 7 * 24 * 60 * 60 * 1000)
commit('SET_TOKEN', response.token)
resolve()
}).catch(error => {
reject(error)
SET_SIDEBAR_TYPE: (state, type) => {
state.sidebar = type
Vue.ls.set(SIDEBAR_TYPE, type)
},
CLOSE_SIDEBAR: (state) => {
store.dispatch('Logout').then(() => {
Vue.ls.remove(ACCESS_TOKEN)
window.location.reload()
})
}
TOGGLE_FIXED_SIDERBAR: (state, fixed) => {
Vue.ls.set(DEFAULT_FIXED_SIDEMENU, fixed)
state.fixSiderbar = fixed
},
TOGGLE_FIXED_HEADER_HIDDEN: (state, show) => {