打包后登录无法跳转问题解决

This commit is contained in:
aike 2026-07-06 18:11:19 +08:00
parent 9daf74b625
commit 4dab02356f
7 changed files with 31 additions and 32 deletions

View File

@ -11,8 +11,8 @@ VUE_APP_VERSION = '240803'
#VUE_APP_BASE_API = '/dev-api' #VUE_APP_BASE_API = '/dev-api'
VUE_APP_PDOMAIN = 'tanex56' VUE_APP_PDOMAIN = 'tanex56'
VUE_APP_DATA_FROM = 'pc' VUE_APP_DATA_FROM = 'pc'
VUE_APP_BASE_API = 'http://47.96.189.20:58089/api/bizsvr' VUE_APP_BASE_API = 'http://localhost:11089/api/bizsvr'
VUE_APP_WS_HOST = 'ws://47.96.189.20:58089/api/bizsvr' VUE_APP_WS_HOST = 'ws://localhost:11089/api/bizsvr'
VUE_APP_PRINTER_HOST = '192.168.88.108:17080' VUE_APP_PRINTER_HOST = '192.168.88.108:17080'

View File

@ -10,7 +10,7 @@ VUE_APP_VERSION = '240803'
# 管理系统/生产环境 # 管理系统/生产环境
VUE_APP_PDOMAIN = 'tanex56' VUE_APP_PDOMAIN = 'tanex56'
VUE_APP_DATA_FROM = 'pc' VUE_APP_DATA_FROM = 'pc'
VUE_APP_BASE_API = 'http://tst-api.emis.tanex56.com/api/bizsvr' VUE_APP_BASE_API = 'http://localhost:7777/api/bizsvr'
VUE_APP_WS_HOST = 'ws://tst-api.emis.tanex56.com/api/bizsvr' VUE_APP_WS_HOST = 'ws://tst-api.emis.tanex56.com/api/bizsvr'
VUE_APP_PRINTER_HOST = '127.0.0.1:17080' VUE_APP_PRINTER_HOST = '127.0.0.1:17080'

View File

@ -85,7 +85,7 @@
"nprogress": "0.2.0", "nprogress": "0.2.0",
"pako": "^2.1.0", "pako": "^2.1.0",
"pdf-lib": "^1.17.1", "pdf-lib": "^1.17.1",
"pdfjs-dist": "^2.5.207", "pdfjs-dist": "2.5.207",
"print-js": "^1.6.0", "print-js": "^1.6.0",
"qrcode": "^1.5.4", "qrcode": "^1.5.4",
"qrcodejs2": "^0.0.2", "qrcodejs2": "^0.0.2",
@ -118,8 +118,7 @@
"vuedraggable": "^2.24.3", "vuedraggable": "^2.24.3",
"vuex": "3.6.0", "vuex": "3.6.0",
"watermark-dom": "2.3.0", "watermark-dom": "2.3.0",
"xd-pdf": "1.0.0", "worker-loader": "2.0.0",
"xd-vue-pdf": "3.0.0",
"xlsx": "^0.17.5" "xlsx": "^0.17.5"
}, },
"devDependencies": { "devDependencies": {

View File

@ -9,7 +9,7 @@
</div> </div>
</template> </template>
<script> <script>
import pdf from 'xd-vue-pdf' import pdf from './xdpdf/vuePdfNoSss.vue'
export default { export default {
components: { components: {
pdf pdf

View File

@ -41,21 +41,9 @@ router.beforeEach(async(to, from, next) => {
store.dispatch('GetInfo').then(() => { store.dispatch('GetInfo').then(() => {
isRelogin.show = false isRelogin.show = false
store.dispatch('GenerateRoutes').then(accessRoutes => { store.dispatch('GenerateRoutes').then(accessRoutes => {
// 根据roles权限生成可访问的路由表
let path = '/'
if(accessRoutes&&accessRoutes[0].path != path){
if(accessRoutes[0].children){
path = accessRoutes[0].path + '/' + accessRoutes[0].children[0].path
}
else{
path = accessRoutes[0].path
}
}else{
path = accessRoutes[0].children[0].path
}
// next({ path, replace: true }) // hack方法 确保addRoutes已完成
// next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
router.addRoutes(accessRoutes) // 动态添加可访问路由表 router.addRoutes(accessRoutes) // 动态添加可访问路由表
// 使用 GenerateRoutes 计算的首页路径,避免相对路径导致跳转失败
const path = store.state.permission.indexPage || '/'
if(from.path == '/login' || to.fullPath=='/'){ if(from.path == '/login' || to.fullPath=='/'){
next({ path, replace: true }) // hack方法 确保addRoutes已完成 next({ path, replace: true }) // hack方法 确保addRoutes已完成
@ -64,6 +52,11 @@ router.beforeEach(async(to, from, next) => {
next({ ...to, replace: true }) next({ ...to, replace: true })
} }
}).catch(err => {
store.dispatch('LogOut').then(() => {
Message.error(err || '路由加载失败')
next({ path: '/login' })
})
}) })
}).catch(err => { }).catch(err => {
store.dispatch('LogOut').then(() => { store.dispatch('LogOut').then(() => {

View File

@ -36,7 +36,7 @@ const permission = {
actions: { actions: {
// 生成路由 // 生成路由
GenerateRoutes({ commit,dispatch }) { GenerateRoutes({ commit,dispatch }) {
return new Promise(resolve => { return new Promise((resolve, reject) => {
// 向后端请求路由数据 // 向后端请求路由数据
getRouters().then(res => { getRouters().then(res => {
const sdata = JSON.parse(JSON.stringify(res.data)) const sdata = JSON.parse(JSON.stringify(res.data))
@ -54,7 +54,8 @@ const permission = {
if(sidebarRoutes.length==0){ if(sidebarRoutes.length==0){
// 无左侧菜单路由,则退出登录 // 无左侧菜单路由,则退出登录
dispatch('FedLogOut', { }, { root: true }) dispatch('FedLogOut', { }, { root: true })
// rewriteRoutes.push({ path: '*', redirect: '/401', hidden: true }) reject(new Error('当前账号无菜单权限,请联系管理员'))
return
} }
router.addRoutes(asyncRoutes); router.addRoutes(asyncRoutes);
@ -66,6 +67,8 @@ const permission = {
commit('SET_INDEX_PAGE', indexUrl) commit('SET_INDEX_PAGE', indexUrl)
resolve(rewriteRoutes) resolve(rewriteRoutes)
}).catch(err => {
reject(err)
}) })
}) })
} }
@ -164,13 +167,16 @@ export function filterDynamicRoutes(routes) {
return res return res
} }
// 匹配 views 目录下所有 .vue 文件,用于动态路由组件加载
const viewModules = require.context('../../views', true, /\.vue$/)
export const loadView = (view) => { export const loadView = (view) => {
if (process.env.NODE_ENV === 'development') { // 后端返回的组件路径可能带 .vue 后缀
return (resolve) => require([`@/views/${view}`], resolve) if (view.endsWith('.vue')) {
} else { view = view.slice(0, -4)
// 使用 import 实现生产环境的路由懒加载
return () => import(`@/views/${view}`)
} }
const modulePath = `./${view}.vue`
return () => Promise.resolve(viewModules(modulePath).default || viewModules(modulePath))
} }
export default permission export default permission

View File

@ -545,10 +545,11 @@ export default {
} }
this.$store.dispatch("Login", this.loginForm).then(() => { this.$store.dispatch("Login", this.loginForm).then(() => {
this.$router.push({ path: this.redirect || "/" }).catch(()=>{}); return this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
}).catch(() => { }).catch(() => {
this.loading = false;
this.getCode(); this.getCode();
}).finally(() => {
this.loading = false;
}); });
} }
}); });
@ -563,8 +564,8 @@ export default {
if (valid) { if (valid) {
this.loading = true; this.loading = true;
this.$store.dispatch("LoginByMobile", this.loginForm2).then(() => { this.$store.dispatch("LoginByMobile", this.loginForm2).then(() => {
this.$router.push({ path: this.redirect || "/" }).catch(()=>{}); return this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
}).catch(() => { }).finally(() => {
this.loading = false; this.loading = false;
}); });
} }