Browse Source

路由优化+本地化整理

master
安虹睿 1 year ago
parent
commit
52cd4a9325
  1. 2
      Code/Fe/src/api/wms-api.js
  2. 2
      Code/Fe/src/components/News/dialogIndex.vue
  3. 2
      Code/Fe/src/components/News/index.vue
  4. 2
      Code/Fe/src/components/rowDrop/index.vue
  5. 1
      Code/Fe/src/layout/components/Navbar.vue
  6. 94
      Code/Fe/src/permission-0725.js
  7. 105
      Code/Fe/src/permission.js
  8. 9
      Code/Fe/src/store/getters.js
  9. 1
      Code/Fe/src/store/modules/definition.js
  10. 3
      Code/Fe/src/store/modules/permission.js
  11. 18
      Code/Fe/src/utils/index.js
  12. 6
      Code/Fe/src/views/login/index.vue
  13. 2
      Code/Fe/src/views/profileuser/index.vue
  14. 2
      Code/Fe/src/views/profileuser/resetPwd.vue

2
Code/Fe/src/api/wms-api.js

@ -12,7 +12,7 @@ export function postCreate(data, url) {
data.warehouseCode = localStorage.getItem('warehouseCode') data.warehouseCode = localStorage.getItem('warehouseCode')
} }
if(Object.keys(data).includes('worker')) { if(Object.keys(data).includes('worker')) {
data.worker = store.getters.name.userName data.worker = store.getters.currentUserInfo.userName
} }
return request({ return request({
url: baseURL + url, url: baseURL + url,

2
Code/Fe/src/components/News/dialogIndex.vue

@ -172,7 +172,7 @@ export default {
} }
}, },
mounted () { mounted () {
this.userId = this.$store.getters.name.id this.userId = this.$store.getters.currentUserInfo.id
// todo-new: // todo-new:
// this.getList() // this.getList()
}, },

2
Code/Fe/src/components/News/index.vue

@ -25,7 +25,7 @@ export default {
dialogIndex dialogIndex
}, },
mounted () { mounted () {
this.userId = this.$store.getters.name.id this.userId = this.$store.getters.currentUserInfo.id
this.getNoReadCount(this.userId) this.getNoReadCount(this.userId)
this.getSetInterval() this.getSetInterval()
// //

2
Code/Fe/src/components/rowDrop/index.vue

@ -100,7 +100,7 @@ export default {
type: 'warning', type: 'warning',
cancelButtonClass:'rowDropNotHideItem' cancelButtonClass:'rowDropNotHideItem'
}).then(() => { }).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.setItem('file_Columns_' + this.source + '_' + this.userName + '_' + this.$route.name, JSON.stringify([]))
localStorage.removeItem('file_Columns_' + this.source + '_' +this.userName + '_' + this.$route.name) localStorage.removeItem('file_Columns_' + this.source + '_' +this.userName + '_' + this.$route.name)
// let _resetCol = this.$isTableColumns[this.$route.name] // let _resetCol = this.$isTableColumns[this.$route.name]

1
Code/Fe/src/layout/components/Navbar.vue

@ -80,7 +80,6 @@ export default {
async logout() { async logout() {
await this.$store.dispatch("user/logout") await this.$store.dispatch("user/logout")
// this.$router.push(`/login?redirect=${this.$route.fullPath}`); // 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?redirect=${this.$route.fullPath}&isAutoLogin=false`)
this.$router.push(`/login?isAutoLogin=false`) this.$router.push(`/login?isAutoLogin=false`)
}, },

94
Code/Fe/src/permission-0721.js → 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 { getToken } from '@/utils/auth' // get token from cookie
import getPageTitle from '@/utils/get-page-title' import getPageTitle from '@/utils/get-page-title'
import { asyncRoutes } from '@/router' import { asyncRoutes } from '@/router'
import { getInterfaceBoard } from "@/api/wms-interface"
import { login,getUsersByUserName } from "@/api/wms-auth" import { login,getUsersByUserName } from "@/api/wms-auth"
NProgress.configure({ NProgress.configure({
@ -19,6 +18,16 @@ router.beforeEach(async (to, from, next) => {
// set page title // set page title
document.title = getPageTitle() 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')) let isAutoLogin = JSON.parse(localStorage.getItem('isAutoLogin'))
const interfaceBoardColumnsNames = localStorage.getItem("interfaceBoardColumnsNames") const interfaceBoardColumnsNames = localStorage.getItem("interfaceBoardColumnsNames")
@ -27,41 +36,49 @@ router.beforeEach(async (to, from, next) => {
if( _url_isAutoLogin== 'false' || _url_isAutoLogin == 'true'){ if( _url_isAutoLogin== 'false' || _url_isAutoLogin == 'true'){
isAutoLogin = JSON.parse(_url_isAutoLogin) isAutoLogin = JSON.parse(_url_isAutoLogin)
} }
let userInfo = localStorage.getItem('currentUserInfo')
// 是否有用户信息: // 是否有用户信息:
const userInfo = store.getters.currentUserInfo
// 1、如果没有判断是否为自动登录(是自动登录则自动执行登录,账号密码为配置信息中的值,不是自动登录则跳到登录页) // 1、如果没有判断是否为自动登录(是自动登录则自动执行登录,账号密码为配置信息中的值,不是自动登录则跳到登录页)
// 2、有/没有:则检查是否有api接口的表头数据,没有的话重新获取 // 2、有/没有:则检查是否有api接口的表头数据,没有的话重新获取
if(userInfo){ if(userInfo){
console.log('有store.getters.currentUserInfo',store.getters.currentUserInfo)
if(store.getters.permission_routes && store.getters.permission_routes.length > 0){ if(store.getters.permission_routes && store.getters.permission_routes.length > 0){
console.log('有store.getters.permission_routes',store.getters.permission_routes)
next() next()
}else{ }
else{
console.log('没有store.getters.permission_routes',store.getters.permission_routes)
const accessRoutes = await store.dispatch('permission/getApiColumnsNames') const accessRoutes = await store.dispatch('permission/getApiColumnsNames')
router.addRoutes(accessRoutes) router.addRoutes(accessRoutes)
console.log(52)
next({ next({
...to, ...to,
query:{ query:{
loginName:from.query.loginName, loginName:to.query.loginName,
isAutoLogin:from.query.isAutoLogin, isAutoLogin:to.query.isAutoLogin,
isSinglePage:to.query.isSinglePage
}, },
replace: true replace: true
}) })
} }
}else{ }else{
// console.log('没有store.getters.currentUserInfo',store.getters.currentUserInfo)
if(!interfaceBoardColumnsNames){ if(!interfaceBoardColumnsNames){
const accessRoutes = await store.dispatch('permission/getApiColumnsNames') console.log('没有interfaceBoardColumnsNames',interfaceBoardColumnsNames)
router.addRoutes(accessRoutes) await store.dispatch('definition/getColumZHList')
console.log(123,to) // const accessRoutes = await store.dispatch('permission/getApiColumnsNames')
// router.addRoutes(accessRoutes)
next({ next({
...to, ...to,
query:{ query:{
loginName:to.query.loginName, loginName:to.query.loginName,
isAutoLogin:to.query.isAutoLogin, isAutoLogin:to.query.isAutoLogin,
isSinglePage:to.query.isSinglePage
}, },
replace: true replace: true
}) })
} }
if(isAutoLogin || to.query.loginName){ if(isAutoLogin || to.query.loginName){
console.log('有自动登录',isAutoLogin,to.query.loginName)
// let loginForm= { // let loginForm= {
// userNameOrEmailAddress:localStorage.getItem("userNameOrEmailAddress"), // userNameOrEmailAddress:localStorage.getItem("userNameOrEmailAddress"),
// password:localStorage.getItem("client_secret"), // password:localStorage.getItem("client_secret"),
@ -71,32 +88,43 @@ router.beforeEach(async (to, from, next) => {
// } // }
// // store.dispatch('user/login', loginForm).then(() => { // // store.dispatch('user/login', loginForm).then(() => {
// 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'){ if(to.path != '/login'){
getUsersByUserName(_username).then(res=>{ await store.dispatch('user/getUserInfo',_username).then(()=>{
// todo:currentUserInfo全程需要优化
if(res && JSON.stringify(res).length > 0){
localStorage.setItem("currentUserInfo", JSON.stringify(res));
// next('/')
next({ next({
...to, ...to,
query:{ query:{
loginName:to.query.loginName, loginName:to.query.loginName,
isAutoLogin:to.query.isAutoLogin, isAutoLogin:to.query.isAutoLogin,
isSinglePage:to.query.isSinglePage
}, },
replace: true replace: true
}) })
}else{ }).catch(()=>{
next(`/login?loginName=${to.query.loginName}&isAutoLogin=${to.query.isAutoLogin}`) 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`) // next(`/login`)
Message.error('获取用户信息失败,请重试') Message.error('获取用户信息失败,请重试!')
}
})
.catch(err => {
console.log('获取用户信息失败,请重试')
}) })
}else{ }else{
next() next()
// next({
// ...to,
// query:{
// loginName:to.query.loginName,
// isAutoLogin:to.query.isAutoLogin,
// isSinglePage:to.query.isSinglePage
// },
// replace: true
// })
} }
// }) // })
// .catch((error) => { // .catch((error) => {
@ -104,11 +132,29 @@ router.beforeEach(async (to, from, next) => {
// }) // })
} }
else{ else{
console.log('不自动登录',isAutoLogin,to.query.loginName)
if (to.path != '/login') { if (to.path != '/login') {
Message.error('获取用户信息失败,请重新登录') Message.error('获取用户信息失败,请重新登录')
next(`/login?loginName=${to.query.loginName}&isAutoLogin=${to.query.isAutoLogin}`) next({
next(`/login`) 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{ }else{
// next({
// ...to,
// query:{
// isAutoLogin:to.query.isAutoLogin,
// loginName:to.query.loginName,
// },
// replace: true
// })
next() next()
} }
} }

105
Code/Fe/src/permission.js

@ -18,67 +18,44 @@ router.beforeEach(async (to, from, next) => {
// set page title // set page title
document.title = getPageTitle() 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){ if(!store.getters.enumList || store.getters.enumList.length <= 0){
await store.dispatch('definition/getEnumList') await store.dispatch('definition/getEnumList')
} }
// // 获取表头转义 // 是否有用户信息:
// if(!store.getters.columZHList || store.getters.columZHList.length <= 0){ const userInfo = store.getters.currentUserInfo
// await store.dispatch('definition/getColumZHList')
// }
// 判断是否自动登录 // 判断是否自动登录
let isAutoLogin = JSON.parse(localStorage.getItem('isAutoLogin')) let isAutoLogin = JSON.parse(localStorage.getItem('isAutoLogin'))
const interfaceBoardColumnsNames = localStorage.getItem("interfaceBoardColumnsNames")
// 如果路径中有isAutoLogin参数则优先,否则读取配置文件中的isAutoLogin参数 // 如果路径中有isAutoLogin参数则优先,否则读取配置文件中的isAutoLogin参数
let _url_isAutoLogin = to.query.isAutoLogin let _url_isAutoLogin = to.query.isAutoLogin
if( _url_isAutoLogin== 'false' || _url_isAutoLogin == 'true'){ if( _url_isAutoLogin== 'false' || _url_isAutoLogin == 'true'){
isAutoLogin = JSON.parse(_url_isAutoLogin) isAutoLogin = JSON.parse(_url_isAutoLogin)
} }
// 是否有用户信息: if(to.path == '/login'){
const userInfo = store.getters.currentUserInfo console.log('-------当前路由为登录页-------')
// 1、如果没有判断是否为自动登录(是自动登录则自动执行登录,账号密码为配置信息中的值,不是自动登录则跳到登录页) next()
// 2、有/没有:则检查是否有api接口的表头数据,没有的话重新获取 }else{
console.log('-------当前路由不是登录页-------')
if(userInfo){ if(userInfo){
console.log('有store.getters.currentUserInfo',store.getters.currentUserInfo) console.log('-------当前有用户信息-------',userInfo)
if(store.getters.permission_routes && store.getters.permission_routes.length > 0){
console.log('有store.getters.permission_routes',store.getters.permission_routes)
next() 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{ }else{
// console.log('没有store.getters.currentUserInfo',store.getters.currentUserInfo) console.log('-------当前没有用户信息-------',userInfo)
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){ if(isAutoLogin || to.query.loginName){
console.log('有自动登录',isAutoLogin,to.query.loginName) let _username = to.query.loginName || localStorage.getItem("isLoginName") || localStorage.getItem("userNameOrEmailAddress")
console.log('-------要求自动登录-------',isAutoLogin,to.query.loginName,_username)
// let loginForm= { // let loginForm= {
// userNameOrEmailAddress:localStorage.getItem("userNameOrEmailAddress"), // userNameOrEmailAddress:localStorage.getItem("userNameOrEmailAddress"),
// password:localStorage.getItem("client_secret"), // password:localStorage.getItem("client_secret"),
@ -88,9 +65,8 @@ router.beforeEach(async (to, from, next) => {
// } // }
// // store.dispatch('user/login', loginForm).then(() => { // // store.dispatch('user/login', loginForm).then(() => {
// 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(()=>{ await store.dispatch('user/getUserInfo',_username).then(()=>{
console.log("-------用户信息获取成功-------")
next({ next({
...to, ...to,
query:{ query:{
@ -112,53 +88,26 @@ router.beforeEach(async (to, from, next) => {
// }) // })
// next(`/login?loginName=${to.query.loginName}&isAutoLogin=${to.query.isAutoLogin}`) // next(`/login?loginName=${to.query.loginName}&isAutoLogin=${to.query.isAutoLogin}`)
// next(`/login`) // next(`/login`)
localStorage.removeItem("isLoginName")
Message.error('获取用户信息失败,请重试!') Message.error('获取用户信息失败,请重试!')
}) })
}else{
next()
// next({
// ...to,
// query:{
// loginName:to.query.loginName,
// isAutoLogin:to.query.isAutoLogin,
// isSinglePage:to.query.isSinglePage
// },
// replace: true
// })
}
// }) // })
// .catch((error) => { // .catch((error) => {
// console.log('登录失败') // console.log('登录失败')
// }) // })
} }else{
else{ console.log('-------不需要自动登录-------',isAutoLogin,to.query.loginName)
console.log('不自动登录',isAutoLogin,to.query.loginName)
if (to.path != '/login') {
Message.error('获取用户信息失败,请重新登录')
next({ next({
path:'/login', path:'/login',
query:{ query:{
isAutoLogin:to.query.isAutoLogin,
loginName:to.query.loginName, loginName:to.query.loginName,
isAutoLogin:to.query.isAutoLogin,
isSinglePage:to.query.isSinglePage isSinglePage:to.query.isSinglePage
}, },
replace: true 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()
} }
}) })

9
Code/Fe/src/store/getters.js

@ -7,14 +7,13 @@ const getters = {
cachedViews: state => state.tagsView.cachedViews, cachedViews: state => state.tagsView.cachedViews,
token: state => state.user.token, token: state => state.user.token,
avatar: state => state.user.avatar, avatar: state => state.user.avatar,
name: state => state.user.name,
introduction: state => state.user.introduction, introduction: state => state.user.introduction,
roles: state => state.user.roles, roles: state => state.user.roles,
currentUserInfo: state => state.user.userInfo, currentUserInfo: state => state.user.userInfo,//当前用户信息
permission_routes: state => state.permission.routes, permission_routes: state => state.permission.routes,//接口获取的菜单
errorLogs: state => state.errorLog.logs, errorLogs: state => state.errorLog.logs,
dictionaries: state => state.dictionaries.dict, dictionaries: state => state.dictionaries.dict,
enumList: state => state.definition.enumList, enumList: state => state.definition.enumList,//接口获取的枚举
columZHList: state => state.definition.enumList, columZHList: state => state.definition.columZHList,//接口转义的表头
} }
export default getters export default getters

1
Code/Fe/src/store/modules/definition.js

@ -29,7 +29,6 @@ const actions = {
return new Promise(resolve => { return new Promise(resolve => {
getInterfaceBoard().then(res=>{ getInterfaceBoard().then(res=>{
let _zh = res.resources[localStorage.getItem('columnsApiNamesZh')].texts; let _zh = res.resources[localStorage.getItem('columnsApiNamesZh')].texts;
localStorage.setItem("interfaceBoardColumnsNames",JSON.stringify(_zh))
commit('GET_COLUMZH_LIST', _zh) commit('GET_COLUMZH_LIST', _zh)
resolve(res) resolve(res)
}) })

3
Code/Fe/src/store/modules/permission.js

@ -5,6 +5,7 @@ import {
import Layout from '@/layout' import Layout from '@/layout'
import { getWebMenu } from '@/api/wms-auth' import { getWebMenu } from '@/api/wms-auth'
import { getDefinitionMenu } from '@/api/wms-interface' import { getDefinitionMenu } from '@/api/wms-interface'
import store from '@/store'
/** /**
* Use meta.role to determine if the current user has permission * Use meta.role to determine if the current user has permission
@ -144,7 +145,7 @@ export function initTreeMenusHandle(tree, list,first) {
let _res = [] let _res = []
tree.forEach(item=>{ tree.forEach(item=>{
if(list.indexOf(item.name) >= 0){ 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(first)item.component = '@/layout'
if (item.children && item.children.length > 0) { if (item.children && item.children.length > 0) {
item.children = initTreeMenusHandle(item.children,list) item.children = initTreeMenusHandle(item.children,list)

18
Code/Fe/src/utils/index.js

@ -2,6 +2,7 @@
* Created by PanJiaChen on 16/11/18. * Created by PanJiaChen on 16/11/18.
*/ */
import {fileStorage, getPageList, getDictByCode} from '@/api/wms-api' import {fileStorage, getPageList, getDictByCode} from '@/api/wms-api'
import store from '@/store'
/** /**
* Parse the time to string * Parse the time to string
* @param {(Object|string|number)} time * @param {(Object|string|number)} time
@ -560,22 +561,7 @@ export function createNewTabs (url) {
// faster-new // faster-new
// 转义及读取api接口返回的表头信息 // 转义及读取api接口返回的表头信息
export function initFromApiColumnsLable (data) { export function initFromApiColumnsLable (data) {
//todo:待定:重新获取全局从接口缓存的表头(如:接口监控看板) let _Dashboard = store.getters.columZHList
// 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"))
}
return _Dashboard ? _Dashboard[data] : null return _Dashboard ? _Dashboard[data] : null
} }

6
Code/Fe/src/views/login/index.vue

@ -164,13 +164,13 @@ export default {
handleLogin () { handleLogin () {
this.$refs.loginForm.validate(valid => { this.$refs.loginForm.validate(valid => {
if (valid) { if (valid) {
// todo-new:localStorage.getItem("userNameOrEmailAddress") // todo-new:
this.$store.dispatch('user/getUserInfo',this.loginForm.username).then(()=>{ this.$store.dispatch('user/getUserInfo',this.loginForm.username).then(()=>{
localStorage.setItem('isLoginName',this.loginForm.username)
this.$router.push({ this.$router.push({
path:'/', path:'/',
query:{ query:{
loginName:this.loginForm.username, isSinglePage:this.$route.query.isSinglePage
isAutoLogin:this.$route.query.isAutoLogin,
}, },
replace: true replace: true
}) })

2
Code/Fe/src/views/profileuser/index.vue

@ -96,7 +96,7 @@ export default {
}, },
methods: { methods: {
getUser() { getUser() {
loadLoginUserInfo(this.$store.getters.name.id).then((response) => { loadLoginUserInfo(this.$store.getters.currentUserInfo.id).then((response) => {
this.user = response; this.user = response;
}); });
}, },

2
Code/Fe/src/views/profileuser/resetPwd.vue

@ -74,7 +74,7 @@ export default {
postLoginUserInfo({ postLoginUserInfo({
currentPassword: this.user.oldPassword, currentPassword: this.user.oldPassword,
newPassword: this.user.newPassword, newPassword: this.user.newPassword,
}, this.$store.getters.name.id) }, this.$store.getters.currentUserInfo.id)
.then((response) => { .then((response) => {
this.$notify({ this.$notify({
title: "成功", title: "成功",

Loading…
Cancel
Save