App.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <div id="app">
  3. <router-view />
  4. </div>
  5. </template>
  6. <script>
  7. import { getGlobalInterface } from '@/api/data.js'
  8. import { getUserInfo } from '@/api/user.js'
  9. // omega埋点工具包
  10. import OmegaTracker from '@didi/omega-tracker/lib/index.esm'
  11. const config = { appKey: 'omega6b172861f4' }
  12. export default {
  13. name: 'App',
  14. mounted() {
  15. window.addEventListener('offline', () => {
  16. // 网络由正常常到异常时触发
  17. this.$message({ message: '网络异常,请检查网络!', type: 'error', duration: 2000, offset: 150 })
  18. })
  19. window.addEventListener('online', () => {
  20. location.reload()
  21. })
  22. getUserInfo()
  23. .then(res => {
  24. localStorage.setItem('realname', res.data.chineseName)
  25. localStorage.setItem('username', res.data.username)
  26. })
  27. },
  28. created() {
  29. this.initOmegaTracker()
  30. this.initRoutes()
  31. },
  32. methods: {
  33. initOmegaTracker() {
  34. const omega = OmegaTracker.getTracker(config)
  35. return omega
  36. },
  37. initRoutes() {
  38. this.$store.dispatch('data/setRoutes', this.$router.options.routes)
  39. // 数据中心动态路由获取
  40. getGlobalInterface().then(res => {
  41. this.$store.dispatch('data/setMenu', res.data)
  42. const dataCenterRoutes = []
  43. const route = {
  44. path: '/data',
  45. component: () => import('@/layout'),
  46. redirect: '/data/upload-file',
  47. name: '数据中心',
  48. meta: { title: '数据中心' },
  49. children: [
  50. {
  51. path: 'upload-file',
  52. name: 'jar包管理',
  53. component: () => import('@/views/data/upload.vue'),
  54. meta: { title: 'jar包管理' }
  55. }
  56. ]
  57. }
  58. for (const i in res.data) {
  59. const routeItem = {
  60. path: res.data[i].subMenus[0].path + '/' + i,
  61. redirect: res.data[i].subMenus[0].path,
  62. name: res.data[i].menuName + '/' + i,
  63. component: () => import('@/views/data/index.vue'),
  64. meta: { title: res.data[i].menuName },
  65. children: [{ path: 'dc' }]
  66. }
  67. for (const j in res.data[i].subMenus) {
  68. const routeChildrenItem = {
  69. path: res.data[i].subMenus[j].path + '/' + i + '/' + j,
  70. name: res.data[i].subMenus[j].subMenuName + '/' + i + '/' + j,
  71. component: () => import('@/views/data/index.vue'),
  72. meta: { title: res.data[i].subMenus[j].subMenuName }
  73. }
  74. routeItem.children.push(routeChildrenItem)
  75. }
  76. route.children.push(routeItem)
  77. }
  78. dataCenterRoutes.push(route)
  79. this.$router.addRoutes(dataCenterRoutes)
  80. for (const i in this.$router.options.routes) {
  81. if (this.$router.options.routes[i].name === '工具集合') {
  82. this.$router.options.routes[i].children.push(route)
  83. }
  84. }
  85. this.$store.dispatch('data/setRoutes', this.$router.options.routes)
  86. })
  87. }
  88. }
  89. }
  90. </script>
  91. <style>
  92. /* el-table头部 */
  93. .tableHead{
  94. color: rgba(0, 0, 0, 0.726);
  95. }
  96. /* 分页 */
  97. .el-pagination{
  98. margin: 2% 0 2% 0;
  99. }
  100. .stylus-content{
  101. width: 98%;
  102. padding: 0.3% 1% 1% 1%;
  103. margin: 0 auto;
  104. background-color: #fff;
  105. border-radius: 4px;
  106. }
  107. </style>