Browse Source

接口错误及路由封装优化

noToken
安虹睿 1 year ago
parent
commit
e42d5308d4
  1. 6
      PC/InterFace.Dash/src/permission.js
  2. 12
      PC/InterFace.Dash/src/store/modules/definition.js
  3. 9
      PC/InterFace.Dash/src/utils/request.js
  4. 4
      PC/UI.WinIn.FasterZ.Job/src/permission.js
  5. 12
      PC/UI.WinIn.FasterZ.Job/src/store/modules/definition.js
  6. 9
      PC/UI.WinIn.FasterZ.Job/src/utils/request.js
  7. 7
      PC/UI.WinIn.FasterZ.Store/src/permission.js
  8. 12
      PC/UI.WinIn.FasterZ.Store/src/store/modules/definition.js
  9. 9
      PC/UI.WinIn.FasterZ.Store/src/utils/request.js

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

@ -19,7 +19,9 @@ router.beforeEach(async (to, from, next) => {
// 获取表头转义 // 获取表头转义
if(!store.getters.columZHList || store.getters.columZHList.length <= 0){ if(!store.getters.columZHList || store.getters.columZHList.length <= 0){
await store.dispatch('definition/getColumZHList') await store.dispatch('definition/getColumZHList',()=>{
NProgress.done()
})
} }
// 获取菜单数据 // 获取菜单数据
@ -74,6 +76,7 @@ router.beforeEach(async (to, from, next) => {
console.log("-------用户信息获取成功-------") console.log("-------用户信息获取成功-------")
localStorage.setItem('alreadyTryLogin',true) localStorage.setItem('alreadyTryLogin',true)
next(to) next(to)
NProgress.done()
// next({ // next({
// ...to, // ...to,
// query:{ // query:{
@ -114,6 +117,7 @@ router.beforeEach(async (to, from, next) => {
}, },
replace: true replace: true
}) })
NProgress.done()
} }
} }
} }

12
PC/InterFace.Dash/src/store/modules/definition.js

@ -148,13 +148,18 @@ const actions = {
}) })
}, },
// 获取表头转义 // 获取表头转义
getColumZHList({ commit }) { getColumZHList({ commit },errCallback) {
return new Promise(resolve => { return new Promise((resolve,reject) => {
getInterfaceBoard().then(res=>{ getInterfaceBoard()
.then(res=>{
let _zh = res.resources[localStorage.getItem('columnsApiNamesZh')].texts; let _zh = res.resources[localStorage.getItem('columnsApiNamesZh')].texts;
commit('SET_COLUMZH_LIST', _zh) commit('SET_COLUMZH_LIST', _zh)
resolve(res) resolve(res)
}) })
.catch(err=>{
if(errCallback)errCallback()
reject(err)
})
}) })
} }
} }
@ -165,4 +170,3 @@ export default {
mutations, mutations,
actions actions
} }

9
PC/InterFace.Dash/src/utils/request.js

@ -91,6 +91,15 @@ service.interceptors.response.use(
// } // }
}, },
error => { error => {
if(!error.response || !error.response.data){
Message({
message: '访问出错,请重试',
type: 'error',
duration: 5 * 1000,
showClose:true
})
return Promise.reject(error)
}
let err = error.response.data.error // for debug let err = error.response.data.error // for debug
if (err && err.validationErrors) { if (err && err.validationErrors) {
for (let item in err.validationErrors) { for (let item in err.validationErrors) {

4
PC/UI.WinIn.FasterZ.Job/src/permission.js

@ -19,7 +19,9 @@ router.beforeEach(async (to, from, next) => {
// 获取表头转义 // 获取表头转义
if(!store.getters.columZHList || store.getters.columZHList.length <= 0){ if(!store.getters.columZHList || store.getters.columZHList.length <= 0){
await store.dispatch('definition/getColumZHList') await store.dispatch('definition/getColumZHList',()=>{
NProgress.done()
})
} }
// 获取菜单数据 // 获取菜单数据

12
PC/UI.WinIn.FasterZ.Job/src/store/modules/definition.js

@ -148,13 +148,18 @@ const actions = {
}) })
}, },
// 获取表头转义 // 获取表头转义
getColumZHList({ commit }) { getColumZHList({ commit },errCallback) {
return new Promise(resolve => { return new Promise((resolve,reject) => {
getInterfaceBoard().then(res=>{ getInterfaceBoard()
.then(res=>{
let _zh = res.resources[localStorage.getItem('columnsApiNamesZh')].texts; let _zh = res.resources[localStorage.getItem('columnsApiNamesZh')].texts;
commit('SET_COLUMZH_LIST', _zh) commit('SET_COLUMZH_LIST', _zh)
resolve(res) resolve(res)
}) })
.catch(err=>{
if(errCallback)errCallback()
reject(err)
})
}) })
} }
} }
@ -165,4 +170,3 @@ export default {
mutations, mutations,
actions actions
} }

9
PC/UI.WinIn.FasterZ.Job/src/utils/request.js

@ -91,6 +91,15 @@ service.interceptors.response.use(
// } // }
}, },
error => { error => {
if(!error.response || !error.response.data){
Message({
message: '访问出错,请重试',
type: 'error',
duration: 5 * 1000,
showClose:true
})
return Promise.reject(error)
}
let err = error.response.data.error // for debug let err = error.response.data.error // for debug
if (err && err.validationErrors) { if (err && err.validationErrors) {
for (let item in err.validationErrors) { for (let item in err.validationErrors) {

7
PC/UI.WinIn.FasterZ.Store/src/permission.js

@ -10,7 +10,6 @@ import { asyncRoutes } from '@/router'
NProgress.configure({ NProgress.configure({
showSpinner: false showSpinner: false
}) // NProgress Configuration }) // NProgress Configuration
router.beforeEach(async (to, from, next) => { router.beforeEach(async (to, from, next) => {
// start progress bar // start progress bar
NProgress.start() NProgress.start()
@ -19,7 +18,9 @@ router.beforeEach(async (to, from, next) => {
// 获取表头转义 // 获取表头转义
if(!store.getters.columZHList || store.getters.columZHList.length <= 0){ if(!store.getters.columZHList || store.getters.columZHList.length <= 0){
await store.dispatch('definition/getColumZHList') await store.dispatch('definition/getColumZHList',()=>{
NProgress.done()
})
} }
// 获取菜单数据 // 获取菜单数据
@ -74,6 +75,7 @@ router.beforeEach(async (to, from, next) => {
console.log("-------用户信息获取成功-------") console.log("-------用户信息获取成功-------")
localStorage.setItem('alreadyTryLogin',true) localStorage.setItem('alreadyTryLogin',true)
next(to) next(to)
NProgress.done()
// next({ // next({
// ...to, // ...to,
// query:{ // query:{
@ -114,6 +116,7 @@ router.beforeEach(async (to, from, next) => {
}, },
replace: true replace: true
}) })
NProgress.done()
} }
} }
} }

12
PC/UI.WinIn.FasterZ.Store/src/store/modules/definition.js

@ -148,13 +148,18 @@ const actions = {
}) })
}, },
// 获取表头转义 // 获取表头转义
getColumZHList({ commit }) { getColumZHList({ commit },errCallback) {
return new Promise(resolve => { return new Promise((resolve,reject) => {
getInterfaceBoard().then(res=>{ getInterfaceBoard()
.then(res=>{
let _zh = res.resources[localStorage.getItem('columnsApiNamesZh')].texts; let _zh = res.resources[localStorage.getItem('columnsApiNamesZh')].texts;
commit('SET_COLUMZH_LIST', _zh) commit('SET_COLUMZH_LIST', _zh)
resolve(res) resolve(res)
}) })
.catch(err=>{
if(errCallback)errCallback()
reject(err)
})
}) })
} }
} }
@ -165,4 +170,3 @@ export default {
mutations, mutations,
actions actions
} }

9
PC/UI.WinIn.FasterZ.Store/src/utils/request.js

@ -91,6 +91,15 @@ service.interceptors.response.use(
// } // }
}, },
error => { error => {
if(!error.response || !error.response.data){
Message({
message: '访问出错,请重试',
type: 'error',
duration: 5 * 1000,
showClose:true
})
return Promise.reject(error)
}
let err = error.response.data.error // for debug let err = error.response.data.error // for debug
if (err && err.validationErrors) { if (err && err.validationErrors) {
for (let item in err.validationErrors) { for (let item in err.validationErrors) {

Loading…
Cancel
Save