From 54dd869743bea0df4de41b72725f6bcba31dc4a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=89=E8=99=B9=E7=9D=BF?= <297504645@qq.com> Date: Tue, 25 Jul 2023 10:10:01 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=AF=E7=94=B1=E4=BC=98=E5=8C=96+=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E5=8C=96=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PC/InterFace.Dash/src/api/wms-api.js | 2 +- .../src/components/News/dialogIndex.vue | 2 +- .../src/components/News/index.vue | 2 +- .../src/components/rowDrop/index.vue | 2 +- .../src/layout/components/Navbar.vue | 1 - PC/InterFace.Dash/src/permission - 副本.js | 90 --------- PC/InterFace.Dash/src/permission-0718.js | 187 ------------------ PC/InterFace.Dash/src/permission-0725.js | 178 +++++++++++++++++ PC/InterFace.Dash/src/permission.js | 145 +++++--------- PC/InterFace.Dash/src/store/getters.js | 9 +- .../src/store/modules/definition.js | 1 - .../src/store/modules/permission.js | 3 +- PC/InterFace.Dash/src/utils/index.js | 18 +- PC/InterFace.Dash/src/views/login/index.vue | 5 +- .../src/views/profileuser/index.vue | 2 +- .../src/views/profileuser/resetPwd.vue | 2 +- 16 files changed, 241 insertions(+), 408 deletions(-) delete mode 100644 PC/InterFace.Dash/src/permission - 副本.js delete mode 100644 PC/InterFace.Dash/src/permission-0718.js create mode 100644 PC/InterFace.Dash/src/permission-0725.js diff --git a/PC/InterFace.Dash/src/api/wms-api.js b/PC/InterFace.Dash/src/api/wms-api.js index 0f1a718..835bfb5 100644 --- a/PC/InterFace.Dash/src/api/wms-api.js +++ b/PC/InterFace.Dash/src/api/wms-api.js @@ -12,7 +12,7 @@ export function postCreate(data, url) { data.warehouseCode = localStorage.getItem('warehouseCode') } if(Object.keys(data).includes('worker')) { - data.worker = store.getters.name.userName + data.worker = store.getters.currentUserInfo.userName } return request({ url: baseURL + url, diff --git a/PC/InterFace.Dash/src/components/News/dialogIndex.vue b/PC/InterFace.Dash/src/components/News/dialogIndex.vue index 2cded50..7259be1 100644 --- a/PC/InterFace.Dash/src/components/News/dialogIndex.vue +++ b/PC/InterFace.Dash/src/components/News/dialogIndex.vue @@ -172,7 +172,7 @@ export default { } }, mounted () { - this.userId = this.$store.getters.name.id + this.userId = this.$store.getters.currentUserInfo.id // todo-new: // this.getList() }, diff --git a/PC/InterFace.Dash/src/components/News/index.vue b/PC/InterFace.Dash/src/components/News/index.vue index 531aa12..82ddeb3 100644 --- a/PC/InterFace.Dash/src/components/News/index.vue +++ b/PC/InterFace.Dash/src/components/News/index.vue @@ -25,7 +25,7 @@ export default { dialogIndex }, mounted () { - this.userId = this.$store.getters.name.id + this.userId = this.$store.getters.currentUserInfo.id this.getNoReadCount(this.userId) this.getSetInterval() // 检测版本是否有更新 diff --git a/PC/InterFace.Dash/src/components/rowDrop/index.vue b/PC/InterFace.Dash/src/components/rowDrop/index.vue index 9d1ba2f..eaf6e1d 100644 --- a/PC/InterFace.Dash/src/components/rowDrop/index.vue +++ b/PC/InterFace.Dash/src/components/rowDrop/index.vue @@ -100,7 +100,7 @@ export default { type: 'warning', cancelButtonClass:'rowDropNotHideItem' }).then(() => { - // 先set是为了字段设置按钮可以监听到缓存变化,之后在移除缓存 this.$store.getters.name.userName + // 先set是为了字段设置按钮可以监听到缓存变化,之后在移除缓存 this.$store.getters.currentUserInfo.userName localStorage.setItem('file_Columns_' + this.source + '_' + this.userName + '_' + this.$route.name, JSON.stringify([])) localStorage.removeItem('file_Columns_' + this.source + '_' +this.userName + '_' + this.$route.name) // let _resetCol = this.$isTableColumns[this.$route.name] diff --git a/PC/InterFace.Dash/src/layout/components/Navbar.vue b/PC/InterFace.Dash/src/layout/components/Navbar.vue index 5a4f586..3523da9 100644 --- a/PC/InterFace.Dash/src/layout/components/Navbar.vue +++ b/PC/InterFace.Dash/src/layout/components/Navbar.vue @@ -80,7 +80,6 @@ export default { async logout() { await this.$store.dispatch("user/logout") // this.$router.push(`/login?redirect=${this.$route.fullPath}`); - localStorage.removeItem("interfaceBoardColumnsNames") // this.$router.push(`/login?redirect=${this.$route.fullPath}&isAutoLogin=false`) this.$router.push(`/login?isAutoLogin=false`) }, diff --git a/PC/InterFace.Dash/src/permission - 副本.js b/PC/InterFace.Dash/src/permission - 副本.js deleted file mode 100644 index 13cf7b6..0000000 --- a/PC/InterFace.Dash/src/permission - 副本.js +++ /dev/null @@ -1,90 +0,0 @@ -import router from './router' -import store from './store' -import { - Message -} from 'element-ui' -import NProgress from 'nprogress' // progress bar -import 'nprogress/nprogress.css' // progress bar style -import { - getToken -} from '@/utils/auth' // get token from cookie -import getPageTitle from '@/utils/get-page-title' -import { - asyncRoutes -} from '@/router' - -NProgress.configure({ - showSpinner: false -}) // NProgress Configuration - -const whiteList = ['/login', '/auth-redirect', '/testForm'] // no redirect whitelist - -router.beforeEach(async (to, from, next) => { - // 添加路由信息,方便代码修改定位 - // console.log('----------------' + to.meta.title + '-----------------------'+ to.fullPath.substring(to.fullPath.lastIndexOf('-')+1,to.fullPath.length) + '.vue' ); - // start progress bar - NProgress.start() - - // set page title - document.title = getPageTitle() - next() - // determine whether the user has logged in - // todo-new:等获取token接口恢复后做处理 - const hasRoles =await store.getters.roles && await store.getters.roles.length > 0 - if (hasRoles) { - next() - } else { - try { - // get user info - // note: roles must be a object array! such as: ['admin'] or ,['developer','editor'] - - // 如果缓存中没有 interfaceBoardColumnsNames(接口监控看板表头信息) 的缓存数据 则退出登录 - let _interfaceBoardColumnsNames = localStorage.getItem("interfaceBoardColumnsNames") - if(!_interfaceBoardColumnsNames || _interfaceBoardColumnsNames == 'undefined' || _interfaceBoardColumnsNames == 'null'){ - await store.dispatch('user/logout') - next(`/login?redirect=${to.path}`) - NProgress.done() - } - - const { - roles - } = await store.dispatch('user/getInfo') - // generate accessible routes map based on roles - - // const accessRoutes = await store.dispatch('permission/generateRoutes', localStorage.getItem('userId')) - // router.addRoutes(accessRoutes) - - // 原码 防止刷新出现空白页(系统暂无出现所以注释) - // const accessRoutes = await store.dispatch('permission/generateRoutes', roles) - // router.addRoutes(accessRoutes) - - // hack method to ensure that addRoutes is complete - // set the replace: true, so the navigation will not leave a history record - next({ - ...to, - replace: true - }) - } catch (error) { - // remove token and go to login page to re-login - await store.dispatch('user/resetToken') - Message.error(error || 'Has Error') - next(`/login?redirect=${to.path}`) - NProgress.done() - } - } -}) - -router.afterEach(() => { - // element-ui 使用 Tooltip 提示时候,更换页面,提示依旧存在偶现bug处理。 - const mytooltipList = document.querySelectorAll('.el-tooltip__popper') // 获取页面所有tooltip的dom集合 - setTimeout(() => { - mytooltipList.forEach((value) => { - value.style.display = 'none' - if(value.parentElement){ - value.parentElement.removeChild(value) - } - }) - }, 1000) - // finish progress bar - NProgress.done() -}) diff --git a/PC/InterFace.Dash/src/permission-0718.js b/PC/InterFace.Dash/src/permission-0718.js deleted file mode 100644 index a4874c6..0000000 --- a/PC/InterFace.Dash/src/permission-0718.js +++ /dev/null @@ -1,187 +0,0 @@ -import router from './router' -import store from './store' -import { - Message -} from 'element-ui' -import NProgress from 'nprogress' // progress bar -import 'nprogress/nprogress.css' // progress bar style -import { - getToken -} from '@/utils/auth' // get token from cookie -import getPageTitle from '@/utils/get-page-title' -import { - asyncRoutes -} from '@/router' -import { getInterfaceBoard } from "@/api/wms-interface" -import { login,getUsersByUserName } from "@/api/wms-auth" - -NProgress.configure({ - showSpinner: false -}) // NProgress Configuration - -const whiteList = ['/login', '/auth-redirect', '/testForm'] // no redirect whitelist - - -router.beforeEach(async (to, from, next) => { - // 添加路由信息,方便代码修改定位 - // console.log('----------------' + to.meta.title + '-----------------------'+ to.fullPath.substring(to.fullPath.lastIndexOf('-')+1,to.fullPath.length) + '.vue' ); - // start progress bar - NProgress.start() - - // set page title - document.title = getPageTitle() - - // 判断是否自动登录 - let isAutoLogin = JSON.parse(localStorage.getItem('isAutoLogin')) - // 如果路径中有isAutoLogin参数则优先,否则读取配置文件中的isAutoLogin参数 - let _url_isAutoLogin = to.query.isAutoLogin - if( _url_isAutoLogin== 'false' || _url_isAutoLogin == 'true'){ - isAutoLogin = JSON.parse(_url_isAutoLogin) - } - let userInfo = localStorage.getItem('currentUserInfo') - let _zh = localStorage.getItem('columnsApiNamesZh') - // 是否有用户信息: - // 1、如果没有判断是否为自动登录(是自动登录则自动执行登录,账号密码为配置信息中的值,不是自动登录则跳到登录页) - // 2、如果有用户信息:则检查是否有api接口的表头数据,没有的话重新获取 - if(!userInfo){ - if(isAutoLogin || to.query.loginName){ - // let loginForm= { - // userNameOrEmailAddress:localStorage.getItem("userNameOrEmailAddress"), - // password:localStorage.getItem("client_secret"), - // // rememberMe:true, - // // grant_type: 'password', - // // client_id: 'Auth_App', - // } - // // store.dispatch('user/login', loginForm).then(() => { - // login(loginForm).then(()=>{ - let _username = to.query.loginName ? to.query.loginName : localStorage.getItem("userNameOrEmailAddress") - getUsersByUserName(_username).then(res=>{ - // todo:currentUserInfo全程需要优化 - localStorage.setItem("currentUserInfo", JSON.stringify(res)); - }) - .catch(err => { - console.log('获取用户信息失败,请重试') - }) - // 提前获取接口监控看板表头数据并存储 - getInterfaceBoard().then(result => { - localStorage.setItem("interfaceBoardColumnsNames", JSON.stringify(result.resources[_zh].texts)); - next('/') - }) - .catch(err => { - console.log('获取表头失败,请重试') - }) - // }) - // .catch((error) => { - // console.log('登录失败') - // }) - }else{ - if (to.path != '/login') { - next('/login') - }else{ - next() - } - NProgress.done() - } - }else{ - // 重新获取api接口表头 - // const _interfaceBoardColumnsNames = localStorage.getItem("interfaceBoardColumnsNames") - // if( !_interfaceBoardColumnsNames || _interfaceBoardColumnsNames == 'undefined' || _interfaceBoardColumnsNames == 'null'){ - getInterfaceBoard().then(result => { - console.log(9999) - // todo-new:columnsApiNamesZh配置的地址补全(evel) - localStorage.setItem("interfaceBoardColumnsNames", JSON.stringify(result.resources[_zh].texts)); - setTimeout(()=>{ - next() - },0) - }) - // }else{ - // next() - // } - } - - - // determine whether the user has logged in - - // todo-new:如果token接口恢复做处理 - const hasToken = getToken() - // else if (hasToken) { - // // if(from.path != '/login'){ - // // let _interfaceBoardColumnsNames = localStorage.getItem("interfaceBoardColumnsNames") - // // if(!_interfaceBoardColumnsNames){ - // // // next({ - // // // path: '/' - // // // }) - // // // NProgress.done() - // // } - // // } - // if (to.path === '/login') { - // // if is logged in, redirect to the home page - // next({ - // path: '/' - // }) - // NProgress.done() // hack: https://github.com/PanJiaChen/vue-element-admin/pull/2939 - // } else { - // // determine whether the user has obtained his permission roles through getInfo - // const hasRoles =await store.getters.roles && await store.getters.roles.length > 0 - // if (hasRoles) { - // next() - // } else { - // try { - // // get user info - // // note: roles must be a object array! such as: ['admin'] or ,['developer','editor'] - - // const { - // roles - // } = await store.dispatch('user/getInfo') - // // generate accessible routes map based on roles - - // // const accessRoutes = await store.dispatch('permission/generateRoutes', localStorage.getItem('userId')) - // // router.addRoutes(accessRoutes) - - // // 原码 防止刷新出现空白页(系统暂无出现所以注释) - // // const accessRoutes = await store.dispatch('permission/generateRoutes', roles) - // // router.addRoutes(accessRoutes) - - // // hack method to ensure that addRoutes is complete - // // set the replace: true, so the navigation will not leave a history record - // next({ - // ...to, - // replace: true - // }) - // } catch (error) { - // // remove token and go to login page to re-login - // await store.dispatch('user/resetToken') - // Message.error(error || 'Has Error') - // next(`/login?redirect=${to.path}`) - // NProgress.done() - // } - // } - // } - // } else { - // /* has no token*/ - - // if (whiteList.indexOf(to.path) !== -1) { - // // in the free login whitelist, go directly - // next() - // } else { - // // other pages that do not have permission to access are redirected to the login page. - // next(`/login?redirect=${to.path}`) - // NProgress.done() - // } - // } -}) - -router.afterEach(() => { - // element-ui 使用 Tooltip 提示时候,更换页面,提示依旧存在偶现bug处理。 - const mytooltipList = document.querySelectorAll('.el-tooltip__popper') // 获取页面所有tooltip的dom集合 - setTimeout(() => { - mytooltipList.forEach((value) => { - value.style.display = 'none' - if(value.parentElement){ - value.parentElement.removeChild(value) - } - }) - }, 1000) - // finish progress bar - NProgress.done() -}) diff --git a/PC/InterFace.Dash/src/permission-0725.js b/PC/InterFace.Dash/src/permission-0725.js new file mode 100644 index 0000000..715670c --- /dev/null +++ b/PC/InterFace.Dash/src/permission-0725.js @@ -0,0 +1,178 @@ +import router from './router' +import store from './store' +import { Message } from 'element-ui' +import NProgress from 'nprogress' // progress bar +import 'nprogress/nprogress.css' // progress bar style +import { getToken } from '@/utils/auth' // get token from cookie +import getPageTitle from '@/utils/get-page-title' +import { asyncRoutes } from '@/router' +import { login,getUsersByUserName } from "@/api/wms-auth" + +NProgress.configure({ + showSpinner: false +}) // NProgress Configuration + +router.beforeEach(async (to, from, next) => { + // start progress bar + NProgress.start() + // set page title + document.title = getPageTitle() + + // 获取枚举数据 + if(!store.getters.enumList || store.getters.enumList.length <= 0){ + await store.dispatch('definition/getEnumList') + } + + // // 获取表头转义 + // if(!store.getters.columZHList || store.getters.columZHList.length <= 0){ + // await store.dispatch('definition/getColumZHList') + // } + + // 判断是否自动登录 + let isAutoLogin = JSON.parse(localStorage.getItem('isAutoLogin')) + const columZHList = store.getters.columZHList + // 如果路径中有isAutoLogin参数则优先,否则读取配置文件中的isAutoLogin参数 + let _url_isAutoLogin = to.query.isAutoLogin + if( _url_isAutoLogin== 'false' || _url_isAutoLogin == 'true'){ + isAutoLogin = JSON.parse(_url_isAutoLogin) + } + // 是否有用户信息: + const userInfo = store.getters.currentUserInfo + // 1、如果没有判断是否为自动登录(是自动登录则自动执行登录,账号密码为配置信息中的值,不是自动登录则跳到登录页) + // 2、有/没有:则检查是否有api接口的表头数据,没有的话重新获取 + if(userInfo){ + console.log('有store.getters.currentUserInfo',store.getters.currentUserInfo) + if(store.getters.permission_routes && store.getters.permission_routes.length > 0){ + console.log('有store.getters.permission_routes',store.getters.permission_routes) + next() + } + else{ + console.log('没有store.getters.permission_routes',store.getters.permission_routes) + const accessRoutes = await store.dispatch('permission/getApiColumnsNames') + router.addRoutes(accessRoutes) + next({ + ...to, + query:{ + loginName:to.query.loginName, + isAutoLogin:to.query.isAutoLogin, + isSinglePage:to.query.isSinglePage + }, + replace: true + }) + } + }else{ + // console.log('没有store.getters.currentUserInfo',store.getters.currentUserInfo) + if(!columZHList){ + console.log('没有columZHList',columZHList) + await store.dispatch('definition/getColumZHList') + // const accessRoutes = await store.dispatch('permission/getApiColumnsNames') + // router.addRoutes(accessRoutes) + next({ + ...to, + query:{ + loginName:to.query.loginName, + isAutoLogin:to.query.isAutoLogin, + isSinglePage:to.query.isSinglePage + }, + replace: true + }) + } + if(isAutoLogin || to.query.loginName){ + console.log('有自动登录',isAutoLogin,to.query.loginName) + // let loginForm= { + // userNameOrEmailAddress:localStorage.getItem("userNameOrEmailAddress"), + // password:localStorage.getItem("client_secret"), + // // rememberMe:true, + // // grant_type: 'password', + // // client_id: 'Auth_App', + // } + // // store.dispatch('user/login', loginForm).then(() => { + // login(loginForm).then(()=>{ + let _username = to.query.loginName || localStorage.getItem("isLoginName") || localStorage.getItem("userNameOrEmailAddress") + if(to.path != '/login'){ + await store.dispatch('user/getUserInfo',_username).then(()=>{ + next({ + ...to, + query:{ + loginName:to.query.loginName, + isAutoLogin:to.query.isAutoLogin, + isSinglePage:to.query.isSinglePage + }, + replace: true + }) + }).catch(()=>{ + next() + // next({ + // path:'/login', + // query:{ + // isAutoLogin:to.query.isAutoLogin, + // isSinglePage:to.query.isSinglePage + // }, + // replace: true + // }) + // next(`/login?loginName=${to.query.loginName}&isAutoLogin=${to.query.isAutoLogin}`) + // next(`/login`) + Message.error('获取用户信息失败,请重试!') + }) + }else{ + next() + // next({ + // ...to, + // query:{ + // loginName:to.query.loginName, + // isAutoLogin:to.query.isAutoLogin, + // isSinglePage:to.query.isSinglePage + // }, + // replace: true + // }) + } + // }) + // .catch((error) => { + // console.log('登录失败') + // }) + } + else{ + console.log('不自动登录',isAutoLogin,to.query.loginName) + if (to.path != '/login') { + Message.error('获取用户信息失败,请重新登录') + next({ + path:'/login', + query:{ + isAutoLogin:to.query.isAutoLogin, + loginName:to.query.loginName, + isSinglePage:to.query.isSinglePage + }, + replace: true + }) + // next(`/login?loginName=${to.query.loginName}&isAutoLogin=${to.query.isAutoLogin}`) + // next(`/login`) + }else{ + // next({ + // ...to, + // query:{ + // isAutoLogin:to.query.isAutoLogin, + // loginName:to.query.loginName, + // }, + // replace: true + // }) + next() + } + } + NProgress.done() + } +}) + +router.afterEach(() => { + // element-ui 使用 Tooltip 提示时候,更换页面,提示依旧存在偶现bug处理。 + const mytooltipList = document.querySelectorAll('.el-tooltip__popper') // 获取页面所有tooltip的dom集合 + setTimeout(() => { + mytooltipList.forEach((value) => { + value.style.display = 'none' + if(value.parentElement){ + value.parentElement.removeChild(value) + } + }) + }, 1000) + // finish progress bar + NProgress.done() +}) \ No newline at end of file diff --git a/PC/InterFace.Dash/src/permission.js b/PC/InterFace.Dash/src/permission.js index ab774e3..208e9e4 100644 --- a/PC/InterFace.Dash/src/permission.js +++ b/PC/InterFace.Dash/src/permission.js @@ -18,68 +18,45 @@ router.beforeEach(async (to, from, next) => { // set page title document.title = getPageTitle() + // 获取表头转义 + if(!store.getters.columZHList || store.getters.columZHList.length <= 0){ + await store.dispatch('definition/getColumZHList') + } + + // 获取菜单数据 + if(!store.getters.permission_routes || store.getters.permission_routes.length <= 0){ + const accessRoutes = await store.dispatch('permission/getApiColumnsNames') + router.addRoutes(accessRoutes) + } + // 获取枚举数据 if(!store.getters.enumList || store.getters.enumList.length <= 0){ await store.dispatch('definition/getEnumList') } - // // 获取表头转义 - // if(!store.getters.columZHList || store.getters.columZHList.length <= 0){ - // await store.dispatch('definition/getColumZHList') - // } - + // 是否有用户信息: + const userInfo = store.getters.currentUserInfo // 判断是否自动登录 let isAutoLogin = JSON.parse(localStorage.getItem('isAutoLogin')) - const interfaceBoardColumnsNames = localStorage.getItem("interfaceBoardColumnsNames") // 如果路径中有isAutoLogin参数则优先,否则读取配置文件中的isAutoLogin参数 let _url_isAutoLogin = to.query.isAutoLogin if( _url_isAutoLogin== 'false' || _url_isAutoLogin == 'true'){ isAutoLogin = JSON.parse(_url_isAutoLogin) } - // 是否有用户信息: - const userInfo = store.getters.currentUserInfo - // 1、如果没有判断是否为自动登录(是自动登录则自动执行登录,账号密码为配置信息中的值,不是自动登录则跳到登录页) - // 2、有/没有:则检查是否有api接口的表头数据,没有的话重新获取 - if(userInfo){ - console.log('有store.getters.currentUserInfo',store.getters.currentUserInfo) - if(store.getters.permission_routes && store.getters.permission_routes.length > 0){ - console.log('有store.getters.permission_routes',store.getters.permission_routes) - next() - } - else{ - console.log('没有store.getters.permission_routes',store.getters.permission_routes) - const accessRoutes = await store.dispatch('permission/getApiColumnsNames') - router.addRoutes(accessRoutes) - next({ - ...to, - query:{ - loginName:to.query.loginName, - isAutoLogin:to.query.isAutoLogin, - isSinglePage:to.query.isSinglePage - }, - replace: true - }) - } + if(to.path == '/login'){ + console.log('-------当前路由为登录页-------') + next() }else{ - // console.log('没有store.getters.currentUserInfo',store.getters.currentUserInfo) - if(!interfaceBoardColumnsNames){ - console.log('没有interfaceBoardColumnsNames',interfaceBoardColumnsNames) - await store.dispatch('definition/getColumZHList') - // const accessRoutes = await store.dispatch('permission/getApiColumnsNames') - // router.addRoutes(accessRoutes) - next({ - ...to, - query:{ - loginName:to.query.loginName, - isAutoLogin:to.query.isAutoLogin, - isSinglePage:to.query.isSinglePage - }, - replace: true - }) - } - if(isAutoLogin || to.query.loginName){ - console.log('有自动登录',isAutoLogin,to.query.loginName) - // let loginForm= { + console.log('-------当前路由不是登录页-------') + if(userInfo){ + console.log('-------当前有用户信息-------',userInfo) + next() + }else{ + console.log('-------当前没有用户信息-------',userInfo) + if(isAutoLogin || to.query.loginName){ + let _username = to.query.loginName || localStorage.getItem("isLoginName") || localStorage.getItem("userNameOrEmailAddress") + console.log('-------要求自动登录-------',isAutoLogin,to.query.loginName,_username) + // let loginForm= { // userNameOrEmailAddress:localStorage.getItem("userNameOrEmailAddress"), // password:localStorage.getItem("client_secret"), // // rememberMe:true, @@ -88,77 +65,49 @@ router.beforeEach(async (to, from, next) => { // } // // store.dispatch('user/login', loginForm).then(() => { // login(loginForm).then(()=>{ - let _username = to.query.loginName || localStorage.getItem("isLoginName") || localStorage.getItem("userNameOrEmailAddress") - if(to.path != '/login'){ - await store.dispatch('user/getUserInfo',_username).then(()=>{ - next({ - ...to, - query:{ - loginName:to.query.loginName, - isAutoLogin:to.query.isAutoLogin, - isSinglePage:to.query.isSinglePage - }, - replace: true - }) - }).catch(()=>{ - next() - // next({ - // path:'/login', - // query:{ - // isAutoLogin:to.query.isAutoLogin, - // isSinglePage:to.query.isSinglePage - // }, - // replace: true - // }) - // next(`/login?loginName=${to.query.loginName}&isAutoLogin=${to.query.isAutoLogin}`) - // next(`/login`) - Message.error('获取用户信息失败,请重试!') + await store.dispatch('user/getUserInfo',_username).then(()=>{ + console.log("-------用户信息获取成功-------") + next({ + ...to, + query:{ + loginName:to.query.loginName, + isAutoLogin:to.query.isAutoLogin, + isSinglePage:to.query.isSinglePage + }, + replace: true }) - }else{ + }).catch(()=>{ next() // next({ - // ...to, + // path:'/login', // query:{ - // loginName:to.query.loginName, // isAutoLogin:to.query.isAutoLogin, // isSinglePage:to.query.isSinglePage // }, // replace: true - // }) - } + // }) + // next(`/login?loginName=${to.query.loginName}&isAutoLogin=${to.query.isAutoLogin}`) + // next(`/login`) + localStorage.removeItem("isLoginName") + Message.error('获取用户信息失败,请重试!') + }) // }) // .catch((error) => { // console.log('登录失败') // }) - } - else{ - console.log('不自动登录',isAutoLogin,to.query.loginName) - if (to.path != '/login') { - Message.error('获取用户信息失败,请重新登录') + }else{ + console.log('-------不需要自动登录-------',isAutoLogin,to.query.loginName) next({ path:'/login', query:{ - isAutoLogin:to.query.isAutoLogin, loginName:to.query.loginName, + isAutoLogin:to.query.isAutoLogin, isSinglePage:to.query.isSinglePage }, replace: true }) - // next(`/login?loginName=${to.query.loginName}&isAutoLogin=${to.query.isAutoLogin}`) - // next(`/login`) - }else{ - // next({ - // ...to, - // query:{ - // isAutoLogin:to.query.isAutoLogin, - // loginName:to.query.loginName, - // }, - // replace: true - // }) - next() } } - NProgress.done() } }) diff --git a/PC/InterFace.Dash/src/store/getters.js b/PC/InterFace.Dash/src/store/getters.js index 544de54..44fe854 100644 --- a/PC/InterFace.Dash/src/store/getters.js +++ b/PC/InterFace.Dash/src/store/getters.js @@ -7,14 +7,13 @@ const getters = { cachedViews: state => state.tagsView.cachedViews, token: state => state.user.token, avatar: state => state.user.avatar, - name: state => state.user.name, introduction: state => state.user.introduction, roles: state => state.user.roles, - currentUserInfo: state => state.user.userInfo, - permission_routes: state => state.permission.routes, + currentUserInfo: state => state.user.userInfo,//当前用户信息 + permission_routes: state => state.permission.routes,//接口获取的菜单 errorLogs: state => state.errorLog.logs, dictionaries: state => state.dictionaries.dict, - enumList: state => state.definition.enumList, - columZHList: state => state.definition.enumList, + enumList: state => state.definition.enumList,//接口获取的枚举 + columZHList: state => state.definition.columZHList,//接口转义的表头 } export default getters diff --git a/PC/InterFace.Dash/src/store/modules/definition.js b/PC/InterFace.Dash/src/store/modules/definition.js index fc46be0..5119f9d 100644 --- a/PC/InterFace.Dash/src/store/modules/definition.js +++ b/PC/InterFace.Dash/src/store/modules/definition.js @@ -29,7 +29,6 @@ const actions = { return new Promise(resolve => { getInterfaceBoard().then(res=>{ let _zh = res.resources[localStorage.getItem('columnsApiNamesZh')].texts; - localStorage.setItem("interfaceBoardColumnsNames",JSON.stringify(_zh)) commit('GET_COLUMZH_LIST', _zh) resolve(res) }) diff --git a/PC/InterFace.Dash/src/store/modules/permission.js b/PC/InterFace.Dash/src/store/modules/permission.js index c44f7f1..55ae7ef 100644 --- a/PC/InterFace.Dash/src/store/modules/permission.js +++ b/PC/InterFace.Dash/src/store/modules/permission.js @@ -5,6 +5,7 @@ import { import Layout from '@/layout' import { getWebMenu } from '@/api/wms-auth' import { getDefinitionMenu } from '@/api/wms-interface' +import store from '@/store' /** * Use meta.role to determine if the current user has permission @@ -144,7 +145,7 @@ export function initTreeMenusHandle(tree, list,first) { let _res = [] tree.forEach(item=>{ if(list.indexOf(item.name) >= 0){ - item.title = JSON.parse(localStorage.getItem("interfaceBoardColumnsNames"))[item.name] || item.name + item.title = store.getters.columZHList[item.name] || item.name if(first)item.component = '@/layout' if (item.children && item.children.length > 0) { item.children = initTreeMenusHandle(item.children,list) diff --git a/PC/InterFace.Dash/src/utils/index.js b/PC/InterFace.Dash/src/utils/index.js index cbb610e..2084f38 100644 --- a/PC/InterFace.Dash/src/utils/index.js +++ b/PC/InterFace.Dash/src/utils/index.js @@ -2,6 +2,7 @@ * Created by PanJiaChen on 16/11/18. */ import {fileStorage, getPageList, getDictByCode} from '@/api/wms-api' +import store from '@/store' /** * Parse the time to string * @param {(Object|string|number)} time @@ -560,22 +561,7 @@ export function createNewTabs (url) { // faster-new // 转义及读取api接口返回的表头信息 export function initFromApiColumnsLable (data) { - //todo:待定:重新获取全局从接口缓存的表头(如:接口监控看板) - // import { getInterfaceBoard } from "@/api/wms-interface" - - // getList = () => { - // getInterfaceBoard().then(result => { - - // localStorage.setItem("interfaceBoardColumnsNames", JSON.stringify(result.data.localization.values.Dashboard)); - // }) - // .catch(err => { - // }) - // } - let _Dashboard = null - let _names = localStorage.getItem("interfaceBoardColumnsNames") - if(_names && _names != 'undefined' && _names != 'null') { - _Dashboard = JSON.parse(localStorage.getItem("interfaceBoardColumnsNames")) - } + let _Dashboard = store.getters.columZHList return _Dashboard ? _Dashboard[data] : null } diff --git a/PC/InterFace.Dash/src/views/login/index.vue b/PC/InterFace.Dash/src/views/login/index.vue index ac1d2a7..624a6eb 100644 --- a/PC/InterFace.Dash/src/views/login/index.vue +++ b/PC/InterFace.Dash/src/views/login/index.vue @@ -164,13 +164,12 @@ export default { handleLogin () { this.$refs.loginForm.validate(valid => { if (valid) { - // todo-new:自动登录跳转处理(读取localStorage.getItem("userNameOrEmailAddress")) + // todo-new:自动登录跳转处理 this.$store.dispatch('user/getUserInfo',this.loginForm.username).then(()=>{ + localStorage.setItem('isLoginName',this.loginForm.username) this.$router.push({ path:'/', query:{ - loginName:this.loginForm.username, - isAutoLogin:this.$route.query.isAutoLogin, isSinglePage:this.$route.query.isSinglePage }, replace: true diff --git a/PC/InterFace.Dash/src/views/profileuser/index.vue b/PC/InterFace.Dash/src/views/profileuser/index.vue index 2a4893e..5b725a6 100644 --- a/PC/InterFace.Dash/src/views/profileuser/index.vue +++ b/PC/InterFace.Dash/src/views/profileuser/index.vue @@ -96,7 +96,7 @@ export default { }, methods: { getUser() { - loadLoginUserInfo(this.$store.getters.name.id).then((response) => { + loadLoginUserInfo(this.$store.getters.currentUserInfo.id).then((response) => { this.user = response; }); }, diff --git a/PC/InterFace.Dash/src/views/profileuser/resetPwd.vue b/PC/InterFace.Dash/src/views/profileuser/resetPwd.vue index f88d0d9..fbdcc55 100644 --- a/PC/InterFace.Dash/src/views/profileuser/resetPwd.vue +++ b/PC/InterFace.Dash/src/views/profileuser/resetPwd.vue @@ -74,7 +74,7 @@ export default { postLoginUserInfo({ currentPassword: this.user.oldPassword, newPassword: this.user.newPassword, - }, this.$store.getters.name.id) + }, this.$store.getters.currentUserInfo.id) .then((response) => { this.$notify({ title: "成功",