index.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. import Vue from "vue"
  2. import store from "@/store"
  3. import VueRouter from "vue-router"
  4. // 解决Vue-Router升级导致的Uncaught(in promise) navigation guard问题
  5. const originalPush = VueRouter.prototype.push
  6. VueRouter.prototype.push = function push (location, onResolve, onReject) {
  7. if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  8. return originalPush.call(this, location).catch(err => err)
  9. }
  10. import {
  11. query
  12. } from "@/utils/query"
  13. import {
  14. getPvUv
  15. } from "@/api/public.js"
  16. Vue.use(VueRouter)
  17. const routes = [
  18. {
  19. path: '/',
  20. redirect: '/home/overview', // 只有区域,及区域以上用户才能进入总部首页这一套
  21. },
  22. {
  23. path: "/404",
  24. name: "404页面",
  25. component: () => import("../components/404"),
  26. },
  27. {
  28. path: "/group",
  29. name: "集团首页",
  30. component: () => import("../views/statistics/index"),
  31. },
  32. // home
  33. {
  34. path: "/home",
  35. name: "home",
  36. component: () => import("../views/index"),
  37. redirect: "/home/homepage",
  38. children: [{
  39. path: "homepage",
  40. name: "项目首页",
  41. component: () => import("../views/homepage"),
  42. // TODO: 注释重定向到预览页面,liujiandong用户 路由跳转处理
  43. // redirect: "/home/overview",
  44. beforeEnter (to,from,next){
  45. if (store.state.userInfo.username !== 'liujiandong') {
  46. next('/home/overview')
  47. } else {
  48. next()
  49. }
  50. }
  51. },
  52. //概览
  53. {
  54. path: "overview",
  55. name: "项目概览",
  56. component: () => import("../views/overview"),
  57. },
  58. // 楼层功能
  59. {
  60. path: "floorFunc",
  61. name: "楼层功能",
  62. component: () => import("../views/floorFunc"),
  63. },
  64. // 设备设施
  65. {
  66. path: "equipment",
  67. name: "设备设施",
  68. component: () => import("../views/equipment"),
  69. },
  70. // 其他功能
  71. {
  72. path: "other",
  73. name: "其他事项",
  74. component: () => import("../views/other"),
  75. },
  76. // 分析
  77. {
  78. path: "analysis",
  79. name: "分享报表",
  80. component: () => import("../views/analysis"),
  81. },
  82. //图例库管理
  83. {
  84. path: "legendLibrary",
  85. name: "图例管理",
  86. component: () => import("../views/legendLibrary"),
  87. },
  88. //图例绘制规则
  89. {
  90. path: "legendRules",
  91. name: "绘制规则",
  92. component: () => import("../views/legendRules"),
  93. },
  94. ],
  95. },
  96. ]
  97. const router = new VueRouter({
  98. mode: "history",
  99. base: process.env.BASE_URL,
  100. routes,
  101. })
  102. const ignore = ["/404"]
  103. // router.beforeEach(async (to, from, next) => {
  104. // // 如果路径上有plazaId就保存
  105. // let plazaId = to.query.plazaId ?to.query.plazaId:''
  106. // if (plazaId) {
  107. // localStorage.setItem('PLAZAID', plazaId)
  108. // store.commit('STOREPLAZAID', plazaId);
  109. // }
  110. // let previewUrl = to.query.isPreview ? to.query.isPreview : '';
  111. // if (previewUrl) {
  112. // sessionStorage.setItem("SETISPREVIEW", previewUrl)
  113. // store.commit('SETISPREVIEW', previewUrl)
  114. // }
  115. // // 取出刷新时的 ssoToken, 路由拦截时app.vue 生命周期还没有执行,store中还没有数据,
  116. // let beforeunload = localStorage.getItem("beforeunload"),
  117. // __token = null
  118. // beforeunload && (__token = JSON.parse(beforeunload).ssoToken)
  119. // if (!ignore.includes(to.path)) {
  120. // //都是需要token检验的页面 首先优先获取路由上带的token
  121. // let token = null
  122. // if (to.query.token) {
  123. // store.commit("SETSSOTOKEN", to.query.token) //存vuex
  124. // sessionStorage.setItem("SSOTOKEN", to.query.token)
  125. // token = to.query.token
  126. // } else {
  127. // if (store.getters["ssoToken"]) {
  128. // token = store.getters["ssoToken"]
  129. // } else if (sessionStorage.getItem("SSOTOKEN")) {
  130. // token = sessionStorage.getItem("SSOTOKEN")
  131. // store.commit("SETSSOTOKEN", sessionStorage.getItem("SSOTOKEN")) //存vuex
  132. // } else {
  133. // redirectGetToken(to,from)
  134. // }
  135. // }
  136. // // 如果有token
  137. // if (token) {
  138. // // 有token 将数据 isPreview赋给 vuex方便取值
  139. // store.commit('SETISPREVIEW', sessionStorage.getItem("SETISPREVIEW"))
  140. // // 如果在跳转获取token之前保存了指定的路径,则后去token后需要跳转到相关页面
  141. // if(to.path !='/group' && to.path !='/home/homepage' && to.path !='/' ){
  142. // if(!store.state.permissions || store.state.permissions.length ==0){
  143. // // 如果没有请求permissions则请求getUserInfo
  144. // await store.dispatch("getUserInfoNoPath", router)
  145. // }
  146. // }
  147. // if (sessionStorage.getItem("TOURL")) {
  148. // // 如果去的地址等于缓存的地址
  149. // if (sessionStorage.getItem("TOURL") == to.path) {
  150. // sessionStorage.setItem("TOURL", '')
  151. // if (to.path == "/") {
  152. // next("/group")
  153. // }
  154. // if (to.path == "/group" || to.path == "/home/homepage") {
  155. // if (store.state.accessLevel == -1) {
  156. // await store.dispatch("getUserInfo", router)
  157. // await store.dispatch("getBrand")
  158. // // await store.dispatch('getFact')
  159. // }
  160. // }
  161. // await store.dispatch("getFloors")
  162. // await store.dispatch("getBrand")
  163. // next()
  164. // } else {
  165. // next(sessionStorage.getItem("TOURL"))
  166. // }
  167. // } else {
  168. // if (to.path == "/") {
  169. // next("/group")
  170. // }
  171. // if (to.path == "/group" || to.path == "/home/homepage") {
  172. // if (store.state.accessLevel == -1) {
  173. // await store.dispatch("getUserInfo", router)
  174. // console.log('getUserInfo', 4)
  175. // await store.dispatch("getBrand")
  176. // // await store.dispatch('getFact')
  177. // }
  178. // }
  179. // await store.dispatch("getFloors")
  180. // await store.dispatch("getBrand")
  181. // next()
  182. // }
  183. // } else {
  184. // redirectGetToken(to,from)
  185. // }
  186. // } else {
  187. // next()
  188. // return
  189. // }
  190. // })
  191. // 跳入路由后要对发送pvuv
  192. router.afterEach((to) => {
  193. let postParams = {
  194. type: "router",
  195. target: to.name,
  196. parameter: to.path,
  197. }
  198. const data = {
  199. plazaId: store.getters["plazaId"],
  200. }
  201. getPvUv(data, postParams)
  202. .then((res) => {
  203. console.log("pvuv", res)
  204. })
  205. .catch((res) => {
  206. console.log("error", res)
  207. })
  208. })
  209. // 重定向获取token
  210. function redirectGetToken (to) {
  211. let lastRoute = {
  212. path: to.path,
  213. params: to.params,
  214. query: to.query,
  215. }
  216. store.commit("SETLASTROUTER", lastRoute)
  217. let ssoServer = "http://oauth.wanda-dev.cn"
  218. if (process.env.NODE_ENV == "wanda_build") {
  219. ssoServer = "http://oauth.wanda.cn"
  220. }
  221. let systemcode = "CAD156",
  222. signal = new Date().getTime(),
  223. version = "1.0.0";
  224. // 获取token前需要保存跳转前路径
  225. if (!ignore.includes(to.path)) {
  226. let previewUrl = to.query.isPreview ? to.query.isPreview : '';
  227. let plazaId = to.query.plazaId ?to.query.plazaId:''
  228. if (previewUrl) {
  229. sessionStorage.setItem("SETISPREVIEW", previewUrl)
  230. store.commit('SETISPREVIEW', previewUrl)
  231. }
  232. // else{
  233. // sessionStorage.setItem("SETISPREVIEW", 'false')
  234. // store.commit('SETISPREVIEW', 'false')
  235. // }
  236. if (plazaId) {
  237. localStorage.setItem('PLAZAID', plazaId)
  238. store.commit('STOREPLAZAID', plazaId)
  239. }
  240. sessionStorage.setItem("TOURL", to.path)
  241. } else {
  242. // 如果重定向前为404则跳入/
  243. sessionStorage.setItem("TOURL", '/')
  244. }
  245. window.location.href = `${ssoServer}/login?systemcode=${systemcode}&signal=${signal}&version=${version}`
  246. }
  247. export default router