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. 97
      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://dev.ccwin-in.com:60068'
// window.SITE_CONFIG['baseApi'] = 'http://192.168.0.190: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://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' window.SITE_CONFIG['businessApi'] = 'http://dev.ccwin-in.com:10097'
//是否登录配置信息【loginName】 //是否登录配置信息【loginName】
window.SITE_CONFIG['isConfigLogin'] = false window.SITE_CONFIG['isConfigLogin'] = false
//如果【isConfigLogin】为true则使用【loginName】登录 //如果【isConfigLogin】为true则使用【loginName】登录
window.SITE_CONFIG['configLoginName'] = 'admin' window.SITE_CONFIG['configLoginName'] = 'admin'
// 默认登录密码(isConfigLogin为true或者链接参数存在loginName使用)
window.SITE_CONFIG['configLoginPass'] = '1q2w3E*'
// 是否单页面(不显示菜单头部等部分) // 是否单页面(不显示菜单头部等部分)
window.SITE_CONFIG['isSinglePage'] = false 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('baseApi',window.SITE_CONFIG['baseApi'])
localStorage.setItem('authApi',window.SITE_CONFIG['authApi']) localStorage.setItem('authApi',window.SITE_CONFIG['authApi'])
localStorage.setItem('loginApi',window.SITE_CONFIG['loginApi'])
// localStorage.setItem('userApi',window.SITE_CONFIG['userApi']) // localStorage.setItem('userApi',window.SITE_CONFIG['userApi'])
localStorage.setItem('businessApi',window.SITE_CONFIG['businessApi']) localStorage.setItem('businessApi',window.SITE_CONFIG['businessApi'])
localStorage.setItem('isConfigLogin',window.SITE_CONFIG['isConfigLogin']) localStorage.setItem('isConfigLogin',window.SITE_CONFIG['isConfigLogin'])
localStorage.setItem('configLoginName',window.SITE_CONFIG['configLoginName']) localStorage.setItem('configLoginName',window.SITE_CONFIG['configLoginName'])
localStorage.setItem('configLoginPass',window.SITE_CONFIG['configLoginPass'])
localStorage.setItem('isSinglePage',window.SITE_CONFIG['isSinglePage']) localStorage.setItem('isSinglePage',window.SITE_CONFIG['isSinglePage'])
localStorage.setItem('appClientId',window.SITE_CONFIG['appClientId']) localStorage.setItem('appClientId',window.SITE_CONFIG['appClientId'])
localStorage.setItem('appClientScope',window.SITE_CONFIG['appClientScope']) localStorage.setItem('appClientScope',window.SITE_CONFIG['appClientScope'])

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

@ -14,7 +14,7 @@ NProgress.configure({
const whiteList = ['/login','/callback'] // no redirect whitelist const whiteList = ['/login','/callback'] // no redirect whitelist
const noUserMsg = '获取用户信息失败,请重新登录 !' const noUserMsg = '获取用户信息失败,请重新登录 !'
const getErrMsg = '数据获取失败 !' const getErrMsg = '数据获取失败 !'
const hasToken = getToken()
// 跳转登录页 // 跳转登录页
const pageToLogin = (to, from, next) => { const pageToLogin = (to, from, next) => {
@ -24,7 +24,8 @@ const pageToLogin = (to, from, next) => {
NProgress.done() NProgress.done()
} else { } else {
// other pages that do not have permission to access are redirected to the login page. // 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}`) next(`/login?redirect=${to.path}`)
NProgress.done() NProgress.done()
} }
@ -32,27 +33,32 @@ const pageToLogin = (to, from, next) => {
// 首次进入页面加载数据处理 // 首次进入页面加载数据处理
const toPageInit = async (to, from, next) => { const toPageInit = async (to, from, next) => {
// const hasToken = getToken()
// 获取用户信息 // // 获取用户信息
// let _userName = localStorage.getItem("isLoginTokenName")//使用用户名获取 // // let _userName = localStorage.getItem("isLoginTokenName")//使用用户名获取
// if(_userName && _userName != null && (!store.getters.currentUserInfo || store.getters.currentUserInfo.length <= 0)){ // // if(_userName && _userName != null && (!store.getters.currentUserInfo || store.getters.currentUserInfo.length <= 0)){
// await store.dispatch('user/getUserInfo',_userName)//使用用户名获取 // // await store.dispatch('user/getUserInfo',_userName)//使用用户名获取
let _user_access = hasToken.substring(hasToken.indexOf(" ") + 1,hasToken.length) // let _user_access = hasToken.substring(hasToken.indexOf(" ") + 1,hasToken.length)
if(hasToken && hasToken != null && (!store.getters.currentUserInfo || store.getters.currentUserInfo.length <= 0)){ // if(hasToken && hasToken != null && (!store.getters.currentUserInfo || store.getters.currentUserInfo.length <= 0)){
await store.dispatch('user/getUserInfoByToken',_user_access) // await store.dispatch('user/getUserInfoByToken',_user_access)
.then(()=>{ // .then(()=>{
toNextHandle(to, from, next) // toNextHandle(to, from, next)
}) // })
.catch(()=>{ // .catch(()=>{
// todo-fast:接口恢复后更改 // // todo-fast:接口恢复后更改
toNextHandle(to, from, next) // toNextHandle(to, from, next)
// Message.error(noUserMsg) // // Message.error(noUserMsg)
// pageToLogin(to, from, next) // // pageToLogin(to, from, next)
}) // })
return // return
// }
if(getToken()){
toNextHandle(to, from, next)
}else{
Message.error('暂无token,请重新登录')
store.dispatch("user/logout")
} }
toNextHandle(to, from, next)
} }
// 跳转处理 // 跳转处理
@ -67,13 +73,14 @@ const toNextHandle = async (to, from, next) => {
}) })
} }
// 获取菜单数据 // 获取菜单数据 permission_routes
if(!store.getters.permission_routes || store.getters.permission_routes.length <= 0){ if(!store.getters.addRoutes || store.getters.addRoutes.length <= 0){
isFresh = true isFresh = true
await store.dispatch('permission/getApiColumnsNames') await store.dispatch('permission/getAppConfig')
.then(res=>{ .then(res=>{
// 没有权限(token失效处理) // 没有权限(token失效处理)
if(!res || res.length <=0){ if(!res || res.length <=0){
Message.error('用户无权限或者token失效,请重新登录')
store.dispatch("user/logout") store.dispatch("user/logout")
} }
}) })
@ -106,6 +113,8 @@ router.beforeEach(async (to, from, next) => {
// set page title // set page title
document.title = getPageTitle() document.title = getPageTitle()
const hasToken = getToken()
// 判断是否自动登录 // 判断是否自动登录
let isAutoLogin = JSON.parse(localStorage.getItem('isConfigLogin')) || to.query.loginName let isAutoLogin = JSON.parse(localStorage.getItem('isConfigLogin')) || to.query.loginName
@ -131,25 +140,27 @@ router.beforeEach(async (to, from, next) => {
console.log('没有token,是登录页,pageToLogin') console.log('没有token,是登录页,pageToLogin')
pageToLogin(to, from, next) pageToLogin(to, from, next)
} else { } else {
// todo:自动登录,即没有密码登录情况处理 // 如果有单点登录方式使用下方配置
mgr.signinRedirect(); //执行重定向 // mgr.signinRedirect(); //执行重定向
if(isAutoLogin){
// if(isAutoLogin){ let _username = localStorage.getItem("isConfigLogin") && localStorage.getItem("isConfigLogin") != 'false' ? localStorage.getItem("configLoginName") : to.query.loginName
// let _username = localStorage.getItem("isConfigLogin") && localStorage.getItem("isConfigLogin") != 'false' ? localStorage.getItem("configLoginName") : to.query.loginName await store.dispatch('user/login', {
// await store.dispatch('user/loginOnlyName', {username:_username}) username:_username,
// .then(()=>{ password:localStorage.getItem("configLoginPass")
// toPageInit(to, from, next) })
// }) .then(()=>{
// .catch(()=>{ toPageInit(to, from, next)
// // todo-fast:接口恢复后更改 })
// toNextHandle(to, from, next) .catch(()=>{
// // Message.error(noUserMsg) // todo-fast:接口恢复后更改
// // pageToLogin(to, from, next) toNextHandle(to, from, next)
// }) // Message.error(noUserMsg)
// }else{ // pageToLogin(to, from, next)
// console.log('没有token,不是登录页,不是自动登录,pageToLogin') })
// 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) 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) => { SET_TABLESNAME: (state, data) => {
state.tablesName = data state.tablesName = data
}, },
SET_AbpIdentity: (state, data) => {
state.abpIdentityName = data
}
} }
/** /**
* 静态路由懒加载 * 静态路由懒加载
@ -136,14 +133,20 @@ export function initTreeMenusHandle(tree, list,first) {
} }
const actions = { const actions = {
// 设置权限 // 设置权限
setUserRoles({commit},data){ resetUserRoles({commit}){
commit('SET_ROLES', data) commit('SET_ROUTES',[])
commit('SET_ROLES', [])
commit('SET_TABLESNAME', null)
}, },
getApiColumnsNames({
// 获取菜单数据
getAppConfig({
commit commit
}, userId) { }, userId) {
return new Promise(resolve => { return new Promise(resolve => {
getDefinitionMenu(true).then(res => { getDefinitionMenu(true).then(res => {
// 存储当前用户信息
store.dispatch('user/setUserInfo',res.currentUser)
let roles_arr = [] let roles_arr = []
for(let r in res.auth.grantedPolicies){ for(let r in res.auth.grantedPolicies){
if(res.auth.grantedPolicies[r])roles_arr.push(r) if(res.auth.grantedPolicies[r])roles_arr.push(r)
@ -166,8 +169,6 @@ const actions = {
} }
// 存储所有的表名 // 存储所有的表名
commit('SET_TABLESNAME', _menuList) commit('SET_TABLESNAME', _menuList)
// 存储身份标识
commit('SET_AbpIdentity', _AbpIdentity)
// 数据模拟,todo-new:接口获取 // 数据模拟,todo-new:接口获取
let _treeMenusAll = null//树形菜单 let _treeMenusAll = null//树形菜单
// _treeMenusAll = [ // _treeMenusAll = [
@ -249,6 +250,7 @@ const actions = {
}) })
}) })
}, },
} }
export default { export default {

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

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

Loading…
Cancel
Save