鉴权登录

master
zhangdi 3 months ago
parent 14efd9eebb
commit 68c8e0a8b0
  1. 9
      src/api/authorization.js
  2. 45
      src/page/login/authorization.vue
  3. 10
      src/page/login/userlogin.vue
  4. 138
      src/router/page/index.js
  5. 1
      src/store/getters.js
  6. 31
      src/store/modules/user.js

@ -0,0 +1,9 @@
import request from '@/router/axios';
export const getUserinfo = params => {
return request({
url: '/smartpark/user/getUserInfo',
method: 'get',
params: params
})
}

@ -0,0 +1,45 @@
<template>
<div></div>
</template>
<script>
import { getUserinfo } from "@/api/authorization";
import { mapGetters } from "vuex";
export default {
name: "authorization",
data() {
return {};
},
mounted() {
this.getUserinfo();
},
methods: {
getUserinfo() {
getUserinfo().then((res) => {
this.$store.dispatch("user/setUserInfo", res);
// console.log("", res.data.result);
const loading = this.$loading({
lock: true,
text: "登录中,请稍后。。。",
spinner: "el-icon-loading",
});
this.$store
.dispatch("AuthLoginByUsername", res.data.result)
.then(() => {
console.log("登录成功");
this.$router.push({ path: '/firstOrder/list' });
loading.close();
})
.catch(() => {
loading.close();
this.refreshCode();
});
});
},
},
};
</script>
<style></style>

@ -334,15 +334,7 @@
if (this.website.switchMode) {
const deptId = this.userInfo.dept_id;
const roleId = this.userInfo.role_id;
if (deptId.includes(",") || roleId.includes(",")) {
this.loginForm.deptId = deptId;
this.loginForm.roleId = roleId;
this.userBox = true;
this.$store.dispatch("LogOut").then(() => {
loading.close();
});
return false;
}
}
this.$router.push({path: this.tagWel.value});
loading.close();

@ -10,72 +10,82 @@ export default [{
isTab: false,
isAuth: false
}
},{
path: '/authorization',
name: '鉴权页面',
component: () =>
import( /* webpackChunkName: "page" */ '@/page/login/authorization'),
meta: {
keepAlive: true,
isTab: false,
isAuth: false
}
},
{
path: '/lock',
name: '锁屏页',
component: () =>
import( /* webpackChunkName: "page" */ '@/page/lock/index'),
meta: {
keepAlive: true,
isTab: false,
isAuth: false
}
},
{
path: '/404',
component: () =>
import( /* webpackChunkName: "page" */ '@/components/error-page/404'),
name: '404',
meta: {
keepAlive: true,
isTab: false,
isAuth: false
}
{
path: '/lock',
name: '锁屏页',
component: () =>
import( /* webpackChunkName: "page" */ '@/page/lock/index'),
meta: {
keepAlive: true,
isTab: false,
isAuth: false
}
},
{
path: '/404',
component: () =>
import( /* webpackChunkName: "page" */ '@/components/error-page/404'),
name: '404',
meta: {
keepAlive: true,
isTab: false,
isAuth: false
}
},
{
path: '/403',
component: () =>
import( /* webpackChunkName: "page" */ '@/components/error-page/403'),
name: '403',
meta: {
keepAlive: true,
isTab: false,
isAuth: false
}
},
{
path: '/500',
},
{
path: '/403',
component: () =>
import( /* webpackChunkName: "page" */ '@/components/error-page/403'),
name: '403',
meta: {
keepAlive: true,
isTab: false,
isAuth: false
}
},
{
path: '/500',
component: () =>
import( /* webpackChunkName: "page" */ '@/components/error-page/500'),
name: '500',
meta: {
keepAlive: true,
isTab: false,
isAuth: false
}
},
{
path: '/',
name: '主页',
redirect: '/wel'
},
{
path: '/myiframe',
component: Layout,
redirect: '/myiframe',
children: [{
path: ":routerPath",
name: 'iframe',
component: () =>
import( /* webpackChunkName: "page" */ '@/components/error-page/500'),
name: '500',
meta: {
keepAlive: true,
isTab: false,
isAuth: false
}
},
{
path: '/',
name: '主页',
redirect: '/wel'
},
{
path: '/myiframe',
component: Layout,
redirect: '/myiframe',
children: [{
path: ":routerPath",
name: 'iframe',
component: () =>
import( /* webpackChunkName: "page" */ '@/components/iframe/main'),
props: true
}]
import( /* webpackChunkName: "page" */ '@/components/iframe/main'),
props: true
}]
},
{
path: '*',
redirect: '/404'
}
},
{
path: '*',
redirect: '/404'
}
]

@ -3,6 +3,7 @@ const getters = {
language: state => state.common.language,
website: state => state.common.website,
userInfo: state => state.user.userInfo,
userAuthInfo: state => state.user.userAuthInfo,
colorName: state => state.common.colorName,
themeName: state => state.common.themeName,
isShade: state => state.common.isShade,

@ -53,6 +53,7 @@ const user = {
menuAll: getStore({name: 'menuAll'}) || [],
token: getStore({name: 'token'}) || '',
refreshToken: getStore({name: 'refreshToken'}) || '',
userAuthInfo:getStore({name: 'userAuthInfo'}) || [],
},
actions: {
//根据用户名登录
@ -78,6 +79,31 @@ const user = {
reject(error);
})
})
},
//获取用户信息之后进行存储
AuthLoginByUsername({commit}, userInfo) {
return new Promise((resolve, reject) => {
// loginByUsername(userInfo.tenantId, userInfo.deptId, userInfo.roleId, userInfo.username, encrypt(userInfo.password), userInfo.type, userInfo.key, userInfo.code).then(res => {
// const data = res.data;
// if (data.error_description) {
// Message({
// message: data.error_description,
// type: 'error'
// })
// } else {
// commit('SET_TOKEN', data.access_token);
// commit('SET_REFRESH_TOKEN', data.refresh_token);
// commit('SET_TENANT_ID', data.tenant_id);
console.log('userInfo',userInfo);
commit('SET_USER_AUTH_INFO', userInfo);
// commit('DEL_ALL_TAG');
// commit('CLEAR_LOCK');
// }
resolve();
// }).catch(error => {
// reject(error);
// })
})
},
//根据手机信息登录
LoginByPhone({ commit }, userInfo) {
@ -326,6 +352,11 @@ const user = {
}
setStore({name: 'userInfo', content: state.userInfo})
},
SET_USER_AUTH_INFO: (state, userInfo) => {
console.log('userInfo')
state.userInfo = userInfo;
setStore({name: 'userInfo', content: state.userInfo})
},
SET_ROLES: (state, roles) => {
state.roles = roles;
},

Loading…
Cancel
Save