Browse Source

【接口看板-暂存】外链默认没有密码登录功能

faster_AG_grid
安虹睿 1 year ago
parent
commit
eba1e2a37b
  1. 5
      PC/InterFace.Dash/public/config.js
  2. 2
      PC/InterFace.Dash/src/App.vue
  3. 93
      PC/InterFace.Dash/src/permission.js
  4. 7
      PC/InterFace.Dash/src/store/modules/definition.js
  5. 18
      PC/InterFace.Dash/src/store/modules/permission.js
  6. 100
      PC/InterFace.Dash/src/store/modules/user.js

5
PC/InterFace.Dash/public/config.js

@ -2,11 +2,16 @@
window.SITE_CONFIG['baseApi'] = 'http://dev.ccwin-in.com:60068'
// window.SITE_CONFIG['baseApi'] = 'http://192.168.0.190:60068'
window.SITE_CONFIG['authApi'] = 'http://dev.ccwin-in.com:60068'
// window.SITE_CONFIG['authApi'] = 'http://192.168.0.190:60068'
window.SITE_CONFIG['loginApi'] = 'http://dev.ccwin-in.com:60065'
// window.SITE_CONFIG['loginApi'] = 'http://192.168.0.190:60065'
window.SITE_CONFIG['businessApi'] = 'http://dev.ccwin-in.com:10097'
//是否登录配置信息【loginName】
window.SITE_CONFIG['isConfigLogin'] = false
//如果【isConfigLogin】为true则使用【loginName】登录
window.SITE_CONFIG['configLoginName'] = 'admin'
// 默认登录密码(isConfigLogin为true或者链接参数存在loginName使用)
window.SITE_CONFIG['configLoginPass'] = '1q2w3E*'
// 是否单页面(不显示菜单头部等部分)
window.SITE_CONFIG['isSinglePage'] = false
// 项目配置

2
PC/InterFace.Dash/src/App.vue

@ -10,10 +10,12 @@ export default {
}
localStorage.setItem('baseApi',window.SITE_CONFIG['baseApi'])
localStorage.setItem('authApi',window.SITE_CONFIG['authApi'])
localStorage.setItem('loginApi',window.SITE_CONFIG['loginApi'])
// localStorage.setItem('userApi',window.SITE_CONFIG['userApi'])
localStorage.setItem('businessApi',window.SITE_CONFIG['businessApi'])
localStorage.setItem('isConfigLogin',window.SITE_CONFIG['isConfigLogin'])
localStorage.setItem('configLoginName',window.SITE_CONFIG['configLoginName'])
localStorage.setItem('configLoginPass',window.SITE_CONFIG['configLoginPass'])
localStorage.setItem('isSinglePage',window.SITE_CONFIG['isSinglePage'])
localStorage.setItem('appClientId',window.SITE_CONFIG['appClientId'])
localStorage.setItem('appClientScope',window.SITE_CONFIG['appClientScope'])

93
PC/InterFace.Dash/src/permission.js

@ -14,7 +14,7 @@ NProgress.configure({
const whiteList = ['/login','/callback'] // no redirect whitelist
const noUserMsg = '获取用户信息失败,请重新登录 !'
const getErrMsg = '数据获取失败 !'
const hasToken = getToken()
// 跳转登录页
const pageToLogin = (to, from, next) => {
@ -24,7 +24,8 @@ const pageToLogin = (to, from, next) => {
NProgress.done()
} else {
// other pages that do not have permission to access are redirected to the login page.
removeToken()
// removeToken()
store.dispatch('user/resetToken')
next(`/login?redirect=${to.path}`)
NProgress.done()
}
@ -32,27 +33,32 @@ const pageToLogin = (to, from, next) => {
// 首次进入页面加载数据处理
const toPageInit = async (to, from, next) => {
// 获取用户信息
// let _userName = localStorage.getItem("isLoginTokenName")//使用用户名获取
// if(_userName && _userName != null && (!store.getters.currentUserInfo || store.getters.currentUserInfo.length <= 0)){
// await store.dispatch('user/getUserInfo',_userName)//使用用户名获取
let _user_access = hasToken.substring(hasToken.indexOf(" ") + 1,hasToken.length)
if(hasToken && hasToken != null && (!store.getters.currentUserInfo || store.getters.currentUserInfo.length <= 0)){
await store.dispatch('user/getUserInfoByToken',_user_access)
.then(()=>{
toNextHandle(to, from, next)
})
.catch(()=>{
// todo-fast:接口恢复后更改
// const hasToken = getToken()
// // 获取用户信息
// // let _userName = localStorage.getItem("isLoginTokenName")//使用用户名获取
// // if(_userName && _userName != null && (!store.getters.currentUserInfo || store.getters.currentUserInfo.length <= 0)){
// // await store.dispatch('user/getUserInfo',_userName)//使用用户名获取
// let _user_access = hasToken.substring(hasToken.indexOf(" ") + 1,hasToken.length)
// if(hasToken && hasToken != null && (!store.getters.currentUserInfo || store.getters.currentUserInfo.length <= 0)){
// await store.dispatch('user/getUserInfoByToken',_user_access)
// .then(()=>{
// toNextHandle(to, from, next)
// })
// .catch(()=>{
// // todo-fast:接口恢复后更改
// toNextHandle(to, from, next)
// // Message.error(noUserMsg)
// // pageToLogin(to, from, next)
// })
// return
// }
if(getToken()){
toNextHandle(to, from, next)
// Message.error(noUserMsg)
// pageToLogin(to, from, next)
})
return
}else{
Message.error('暂无token,请重新登录')
store.dispatch("user/logout")
}
toNextHandle(to, from, next)
}
// 跳转处理
@ -67,13 +73,14 @@ const toNextHandle = async (to, from, next) => {
})
}
// 获取菜单数据
if(!store.getters.permission_routes || store.getters.permission_routes.length <= 0){
// 获取菜单数据 permission_routes
if(!store.getters.addRoutes || store.getters.addRoutes.length <= 0){
isFresh = true
await store.dispatch('permission/getApiColumnsNames')
await store.dispatch('permission/getAppConfig')
.then(res=>{
// 没有权限(token失效处理)
if(!res || res.length <=0){
Message.error('用户无权限或者token失效,请重新登录')
store.dispatch("user/logout")
}
})
@ -106,6 +113,8 @@ router.beforeEach(async (to, from, next) => {
// set page title
document.title = getPageTitle()
const hasToken = getToken()
// 判断是否自动登录
let isAutoLogin = JSON.parse(localStorage.getItem('isConfigLogin')) || to.query.loginName
@ -131,25 +140,27 @@ router.beforeEach(async (to, from, next) => {
console.log('没有token,是登录页,pageToLogin')
pageToLogin(to, from, next)
} else {
// todo:自动登录,即没有密码登录情况处理
mgr.signinRedirect(); //执行重定向
// if(isAutoLogin){
// let _username = localStorage.getItem("isConfigLogin") && localStorage.getItem("isConfigLogin") != 'false' ? localStorage.getItem("configLoginName") : to.query.loginName
// await store.dispatch('user/loginOnlyName', {username:_username})
// .then(()=>{
// toPageInit(to, from, next)
// })
// .catch(()=>{
// // todo-fast:接口恢复后更改
// toNextHandle(to, from, next)
// // Message.error(noUserMsg)
// // pageToLogin(to, from, next)
// })
// }else{
// console.log('没有token,不是登录页,不是自动登录,pageToLogin')
// 如果有单点登录方式使用下方配置
// mgr.signinRedirect(); //执行重定向
if(isAutoLogin){
let _username = localStorage.getItem("isConfigLogin") && localStorage.getItem("isConfigLogin") != 'false' ? localStorage.getItem("configLoginName") : to.query.loginName
await store.dispatch('user/login', {
username:_username,
password:localStorage.getItem("configLoginPass")
})
.then(()=>{
toPageInit(to, from, next)
})
.catch(()=>{
// todo-fast:接口恢复后更改
toNextHandle(to, from, next)
// Message.error(noUserMsg)
// pageToLogin(to, from, next)
// }
})
}else{
console.log('没有token,不是登录页,不是自动登录,pageToLogin')
pageToLogin(to, from, next)
}
}
}
})

7
PC/InterFace.Dash/src/store/modules/definition.js

@ -170,6 +170,13 @@ const actions = {
reject(err)
})
})
},
// 重置配置信息
resetDefinition({ commit }) {
commit('SET_ENUM_LIST', [])
commit('SET_COLUMZH_LIST', null)
commit('SET_DTOCOLUMN_TYPES', [])
commit('SET_API_ACTIONS', [])
}
}

18
PC/InterFace.Dash/src/store/modules/permission.js

@ -30,9 +30,6 @@ const mutations = {
SET_TABLESNAME: (state, data) => {
state.tablesName = data
},
SET_AbpIdentity: (state, data) => {
state.abpIdentityName = data
}
}
/**
* 静态路由懒加载
@ -136,14 +133,20 @@ export function initTreeMenusHandle(tree, list,first) {
}
const actions = {
// 设置权限
setUserRoles({commit},data){
commit('SET_ROLES', data)
resetUserRoles({commit}){
commit('SET_ROUTES',[])
commit('SET_ROLES', [])
commit('SET_TABLESNAME', null)
},
getApiColumnsNames({
// 获取菜单数据
getAppConfig({
commit
}, userId) {
return new Promise(resolve => {
getDefinitionMenu(true).then(res => {
// 存储当前用户信息
store.dispatch('user/setUserInfo',res.currentUser)
let roles_arr = []
for(let r in res.auth.grantedPolicies){
if(res.auth.grantedPolicies[r])roles_arr.push(r)
@ -166,8 +169,6 @@ const actions = {
}
// 存储所有的表名
commit('SET_TABLESNAME', _menuList)
// 存储身份标识
commit('SET_AbpIdentity', _AbpIdentity)
// 数据模拟,todo-new:接口获取
let _treeMenusAll = null//树形菜单
// _treeMenusAll = [
@ -249,6 +250,7 @@ const actions = {
})
})
},
}
export default {

100
PC/InterFace.Dash/src/store/modules/user.js

@ -1,5 +1,6 @@
import {
token,
login,
logout,
getUsersByToken,
getUsersByUserName
@ -12,7 +13,6 @@ import {
import router, {
resetRouter
} from '@/router'
import qs from 'qs'
import store from '@/store'
import { mgr } from "@/oidc/oidc-client";
@ -31,15 +31,22 @@ const mutations = {
}
// 登录(token)成功后处理
const loginSuccess = (res,username,resolve,reject) => {
setToken(res.token_type + ' ' + res.access_token)
const loginSuccess = (type,token,username,resolve,reject) => {
let _type = type ? type : 'Bearer'
setToken(_type + ' ' + token)
localStorage.setItem('isLoginTokenName',username)
store.dispatch('user/getUserInfo',username).then(()=>{
resolve()
}).catch(()=>{
reject()
})
// store.dispatch('user/getUserInfoByToken',token).then(()=>{
// resolve()
// }).catch(()=>{
// reject()
// })
// store.dispatch('user/getUserInfo',username).then(()=>{
// resolve()
// }).catch(()=>{
// reject()
// })
}
// 单点登录(token)成功后处理
@ -54,6 +61,11 @@ const loginSuccessBySignin = (res,resolve, reject,commit) => {
}
const actions = {
// 设置当前用户
setUserInfo({commit},data){
commit('SET_USERINFO',data)
},
// 登录,需要密码
login({
commit,
@ -63,50 +75,35 @@ const actions = {
username,
} = userInfo
return new Promise((resolve, reject) => {
let params = qs.stringify({
password: password,
username: username,
client_id:localStorage.getItem('appClientId'),
scopes:localStorage.getItem('appClientScope'),
grant_type:'password'
});
token(params).then(response => {
if (response.access_token == null) {
reject()
} else {
loginSuccess(response,username,resolve,reject,commit)
// let params = qs.stringify({
// password: password,
// username: username,
// client_id:localStorage.getItem('appClientId'),
// scopes:localStorage.getItem('appClientScope'),
// grant_type:'password'
// });
let params= {
name:username,
password: password
}
}).catch(error => {
reject(error)
})
})
},
// 自动登录,不需要密码 todo:更改接口,去掉password
loginOnlyName({
commit,
}, userInfo) {
const {
password,
username,
} = userInfo
return new Promise((resolve, reject) => {
let params = qs.stringify({
password: '1q2w3E*',
username: username,
client_id:localStorage.getItem('appClientId'),
scopes:localStorage.getItem('appClientScope'),
grant_type:'password'
});
token(params).then(response => {
if (response.access_token == null) {
reject()
login(params).then(response => {
if (response && response.token) {
loginSuccess(null,response.token,username,resolve,reject,commit)
} else {
loginSuccess(response,username,resolve,reject,commit)
reject()
}
}).catch(error => {
reject(error)
})
// token(params).then(response => {
// if (response.access_token == null) {
// reject()
// } else {
// loginSuccess(response,username,resolve,reject,commit)
// }
// }).catch(error => {
// reject(error)
// })
})
},
@ -141,10 +138,9 @@ const actions = {
}) {
return new Promise((resolve, reject) => {
// logout().then(() => {
dispatch('permission/setUserRoles',[])
dispatch('tagsView/delAllViews', null, {
root: true
}).then(()=>{
dispatch('permission/resetUserRoles',null,{root:true})
dispatch('definition/resetDefinition',null,{root:true})
dispatch('tagsView/delAllViews', null, {root: true}).then(()=>{
removeToken()
resetRouter()
resolve()
@ -164,7 +160,7 @@ const actions = {
commit
}) {
return new Promise(resolve => {
commit('SET_ROLES', [])
// commit('SET_ROLES', [])
localStorage.setItem('isLoginTokenName',null)
removeToken()
resolve()
@ -200,7 +196,7 @@ const actions = {
.then(info=>{
if(info){
let _info = info
_info.userInfo = info.preferred_username
_info.name = info.preferred_username
_info.id = info.sub
commit('SET_USERINFO', _info)
resolve(_info)

Loading…
Cancel
Save