diff --git a/Code/Fe/src/api/wms-api.js b/Code/Fe/src/api/wms-api.js index 0f1a718..835bfb5 100644 --- a/Code/Fe/src/api/wms-api.js +++ b/Code/Fe/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/Code/Fe/src/components/News/dialogIndex.vue b/Code/Fe/src/components/News/dialogIndex.vue index 2cded50..7259be1 100644 --- a/Code/Fe/src/components/News/dialogIndex.vue +++ b/Code/Fe/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/Code/Fe/src/components/News/index.vue b/Code/Fe/src/components/News/index.vue index 531aa12..82ddeb3 100644 --- a/Code/Fe/src/components/News/index.vue +++ b/Code/Fe/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/Code/Fe/src/components/rowDrop/index.vue b/Code/Fe/src/components/rowDrop/index.vue index b4ae25b..58a87d0 100644 --- a/Code/Fe/src/components/rowDrop/index.vue +++ b/Code/Fe/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/Code/Fe/src/layout/components/Navbar.vue b/Code/Fe/src/layout/components/Navbar.vue index 5a4f586..3523da9 100644 --- a/Code/Fe/src/layout/components/Navbar.vue +++ b/Code/Fe/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/Code/Fe/src/permission-0721.js b/Code/Fe/src/permission-0725.js similarity index 50% rename from Code/Fe/src/permission-0721.js rename to Code/Fe/src/permission-0725.js index 72c1859..ab774e3 100644 --- a/Code/Fe/src/permission-0721.js +++ b/Code/Fe/src/permission-0725.js @@ -6,7 +6,6 @@ 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({ @@ -19,6 +18,16 @@ router.beforeEach(async (to, from, next) => { // 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 interfaceBoardColumnsNames = localStorage.getItem("interfaceBoardColumnsNames") @@ -27,41 +36,49 @@ router.beforeEach(async (to, from, next) => { if( _url_isAutoLogin== 'false' || _url_isAutoLogin == 'true'){ isAutoLogin = JSON.parse(_url_isAutoLogin) } - let userInfo = localStorage.getItem('currentUserInfo') // 是否有用户信息: + 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){ - next() - }else{ + 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) - console.log(52) next({ ...to, query:{ - loginName:from.query.loginName, - isAutoLogin:from.query.isAutoLogin, + loginName:to.query.loginName, + isAutoLogin:to.query.isAutoLogin, + isSinglePage:to.query.isSinglePage }, replace: true }) } }else{ + // console.log('没有store.getters.currentUserInfo',store.getters.currentUserInfo) if(!interfaceBoardColumnsNames){ - const accessRoutes = await store.dispatch('permission/getApiColumnsNames') - router.addRoutes(accessRoutes) - console.log(123,to) + 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= { // userNameOrEmailAddress:localStorage.getItem("userNameOrEmailAddress"), // password:localStorage.getItem("client_secret"), @@ -71,32 +88,43 @@ router.beforeEach(async (to, from, next) => { // } // // store.dispatch('user/login', loginForm).then(() => { // login(loginForm).then(()=>{ - let _username = to.query.loginName ? to.query.loginName : localStorage.getItem("userNameOrEmailAddress") + let _username = to.query.loginName || localStorage.getItem("isLoginName") || localStorage.getItem("userNameOrEmailAddress") if(to.path != '/login'){ - getUsersByUserName(_username).then(res=>{ - // todo:currentUserInfo全程需要优化 - if(res && JSON.stringify(res).length > 0){ - localStorage.setItem("currentUserInfo", JSON.stringify(res)); - // next('/') - next({ - ...to, - query:{ - loginName:to.query.loginName, - isAutoLogin:to.query.isAutoLogin, - }, - replace: true - }) - }else{ - next(`/login?loginName=${to.query.loginName}&isAutoLogin=${to.query.isAutoLogin}`) - // next(`/login`) - Message.error('获取用户信息失败,请重试') - } - }) - .catch(err => { - console.log('获取用户信息失败,请重试') + 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) => { @@ -104,12 +132,30 @@ router.beforeEach(async (to, from, next) => { // }) } else{ + console.log('不自动登录',isAutoLogin,to.query.loginName) if (to.path != '/login') { Message.error('获取用户信息失败,请重新登录') - next(`/login?loginName=${to.query.loginName}&isAutoLogin=${to.query.isAutoLogin}`) - next(`/login`) + 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() + // next({ + // ...to, + // query:{ + // isAutoLogin:to.query.isAutoLogin, + // loginName:to.query.loginName, + // }, + // replace: true + // }) + next() } } NProgress.done() diff --git a/Code/Fe/src/permission.js b/Code/Fe/src/permission.js index ab774e3..208e9e4 100644 --- a/Code/Fe/src/permission.js +++ b/Code/Fe/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/Code/Fe/src/store/getters.js b/Code/Fe/src/store/getters.js index 544de54..44fe854 100644 --- a/Code/Fe/src/store/getters.js +++ b/Code/Fe/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/Code/Fe/src/store/modules/definition.js b/Code/Fe/src/store/modules/definition.js index fc46be0..5119f9d 100644 --- a/Code/Fe/src/store/modules/definition.js +++ b/Code/Fe/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/Code/Fe/src/store/modules/permission.js b/Code/Fe/src/store/modules/permission.js index c44f7f1..55ae7ef 100644 --- a/Code/Fe/src/store/modules/permission.js +++ b/Code/Fe/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/Code/Fe/src/utils/index.js b/Code/Fe/src/utils/index.js index cbb610e..2084f38 100644 --- a/Code/Fe/src/utils/index.js +++ b/Code/Fe/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/Code/Fe/src/views/login/index.vue b/Code/Fe/src/views/login/index.vue index 2cf4b08..624a6eb 100644 --- a/Code/Fe/src/views/login/index.vue +++ b/Code/Fe/src/views/login/index.vue @@ -164,13 +164,13 @@ 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/Code/Fe/src/views/profileuser/index.vue b/Code/Fe/src/views/profileuser/index.vue index 2a4893e..5b725a6 100644 --- a/Code/Fe/src/views/profileuser/index.vue +++ b/Code/Fe/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/Code/Fe/src/views/profileuser/resetPwd.vue b/Code/Fe/src/views/profileuser/resetPwd.vue index f88d0d9..fbdcc55 100644 --- a/Code/Fe/src/views/profileuser/resetPwd.vue +++ b/Code/Fe/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: "成功",