Socket
Socket
Sign inDemoInstall

@midcu/vue-auth

Package Overview
Dependencies
24
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.0.1

51

api/index.js
export default {
requestInter: null,
responseInter: null,
init (request, store) {
init (request) {
this.request = request;
this.requestInter = request.interceptors.request.use(function (config) {
config.headers.Authorization = 'Bearer ' + store.state.user.token;
return config;
}, function (error) {
return Promise.reject(error);
});
// Todo
// 获取菜单应该永远返回403或者200 不管登陆或着没登录
// 支持匿名用户 如果没有登录 1:返回403禁止访问 2:返回200,返回匿名的菜单 (token过期也应该返回匿名的菜单或者403)
this.responseInter = request.interceptors.response.use(function (response) {
return response.data;
}, function (error) {
if (error.response.status === 403) {
// 403代表token过期和未登录禁止访问
// 401代表无权限访问
// 403则清空登录凭据 然后
store.commit('USER_LOGOUT');
} else {
// Message({ message: res.message, type: 'error', center: true, duration: 5 * 1000 });
}
return Promise.reject(error);
});
},
ejectInterceptors () {
this.request.interceptors.request.eject(this.requestInter);
this.request.interceptors.response.eject(this.responseInter);
},
request: function () {

@@ -41,3 +10,3 @@

return this.request({
url: '/users/init',
url: '/init',
method: 'get'

@@ -72,3 +41,3 @@ })

},
LoginIn: function (data) {
Login: function (data) {
return this.request({

@@ -80,2 +49,16 @@ url: '/login',

},
Logout: function () {
return this.request({
url: '/logout',
method: 'get'
})
},
FormLogin: function (data) {
return this.request({
url: '/login',
method: 'post',
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' },
data: data
})
},
GetUserInfo: function () {

@@ -82,0 +65,0 @@ return this.request({

{
"name": "@midcu/vue-auth",
"version": "1.0.0",
"version": "1.0.1",
"description": "一个基于vue的前端权限框架依赖包,包括菜单用户角色权限管理",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -16,3 +16,3 @@ // withoutlogin 不需要登陆(登录不可查看)

*/
function initRouterMenus (router, store, loader, to, next) {
function initRouterMenus (router, store, loader, to, from, next) {
AuthApi.InitProject().then(({ menus, user, permissions }) => {

@@ -33,8 +33,9 @@ // 构建菜单

store.commit('SET_MENUS', routerMenus || []);
store.commit('SET_USER', user);
store.commit('SET_PERMISSIONS', permissions || []);
store.commit('USER_LOGIN', user);
next({ path: to.fullPath })
}).catch((e) => {
console.log('系统接口出现问题:请联系后台开发人员!', e)
}).catch(() => {
// 获取菜单失败 跳转至登陆页面
next({ name: 'login', redirect: from.fullPath });
})

@@ -52,6 +53,6 @@ }

router.beforeEach((to, from, next) => {
if (to.meta && to.meta.withoutLogin) {
// 不需要登录
if (store.getters.hasAuthed) {
// 已经登陆后跳转到首页
if (store.getters.hasAuthed) {
// 已经登陆
if (to.meta && to.meta.withoutLogin) {
// 不需要登陆 如:login 跳转到首页
next({ path: '/', replace: true })

@@ -61,16 +62,12 @@ } else {

}
} else if (store.getters.hasAuthed) {
// 已经登陆
if (store.getters.hasMenus) {
// 已经获取过菜单
next();
} else {
if (to.meta && to.meta.withoutLogin) {
// 不需要登陆 如:login 跳转到首页
next()
} else {
// 为获取 获取菜单
initRouterMenus(router, store, loader, to, next);
// 获取菜单!
initRouterMenus(router, store, loader, to, from, next);
}
} else {
// 未登录跳转到登录
next({ name: 'login', redirect: from.fullPath })
}
});
}

@@ -1,16 +0,5 @@

const TOKEN_NAME = 'vue-auth-token'
const userToken = {
getToken () {
return window.localStorage.getItem(TOKEN_NAME)
},
setToken (val) {
window.localStorage.setItem(TOKEN_NAME, val)
}
}
const user = {
state: {
user: { id: 1, name: '匿名用户', tag: 'anonymous' },
token: userToken.getToken(),
hasAuthed: !!userToken.getToken(),
hasAuthed: false,
permissions: []

@@ -23,3 +12,4 @@ },

mutations: {
'SET_USER' (state, user) {
'USER_LOGIN' (state, user) {
state.hasAuthed = true;
state.user = user;

@@ -30,17 +20,8 @@ },

},
'USER_TOKEN' (state, token) {
state.token = token;
state.hasAuthed = true;
userToken.setToken(token);
},
'USER_LOGOUT' (state) {
state.user = { };
userToken.setToken('');
state.hasAuthed = false;
window.location.href = '/';
},
'USER_TOLOGIN' (state) {
userToken.setToken('');
window.location.href = '/#/login';

@@ -47,0 +28,0 @@ },

@@ -12,8 +12,8 @@ /*

*/
var hex_chr = '0123456789abcdef';
var hexChr = '0123456789abcdef';
function rhex (num) {
var str = '';
for (var j = 0; j <= 3; j++) {
str += hex_chr.charAt((num >> (j * 8 + 4)) & 0x0F) +
hex_chr.charAt((num >> (j * 8)) & 0x0F);
str += hexChr.charAt((num >> (j * 8 + 4)) & 0x0F) +
hexChr.charAt((num >> (j * 8)) & 0x0F);
}

@@ -27,7 +27,7 @@ return str;

*/
function str2blks_MD5 (str) {
function str2blksMD5 (str) {
var nblk = ((str.length + 8) >> 6) + 1;
var blks = new Array(nblk * 16);
for (var i = 0; i < nblk * 16; i++) blks[i] = 0;
for (var i = 0; i < str.length; i++) { blks[i >> 2] |= str.charCodeAt(i) << ((i % 4) * 8); }
for (i = 0; i < str.length; i++) { blks[i >> 2] |= str.charCodeAt(i) << ((i % 4) * 8); }
blks[i >> 2] |= 0x80 << ((i % 4) * 8);

@@ -79,3 +79,3 @@ blks[nblk * 16 - 2] = str.length * 8;

function calcMD5 (str) {
var x = str2blks_MD5(str);
var x = str2blksMD5(str);
var a = 1732584193;

@@ -82,0 +82,0 @@ var b = -271733879;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc