main.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import Vue from 'vue'
  2. import router from './router'
  3. import 'normalize.css/normalize.css' // a modern alternative to CSS resets
  4. import 'element-ui/lib/theme-chalk/display.css'
  5. import Viewer from 'v-viewer'
  6. import {
  7. getToken, removeMenu,
  8. removeBtn, removeToken
  9. } from '@/utils/auth'
  10. import ElementUI from 'element-ui'
  11. import 'viewerjs/dist/viewer.css'
  12. import 'element-ui/lib/theme-chalk/display.css'
  13. import './styles/element-variables.scss'
  14. import FlowChart from '@/components/flow-chart'
  15. import './styles/index.scss' // global css
  16. import globalComponents from './components/globalComponents'
  17. import App from './App'
  18. import store from './store'
  19. import base from './assets/utils/prototype/index'
  20. import dataV from '@jiaminghi/data-view'
  21. // 按需引入vue-awesome图标
  22. import Icon from 'vue-awesome/components/Icon'
  23. import 'vue-awesome/icons/chart-bar.js'
  24. import 'vue-awesome/icons/chart-area.js'
  25. import 'vue-awesome/icons/chart-pie.js'
  26. import 'vue-awesome/icons/chart-line.js'
  27. import 'vue-awesome/icons/align-left.js'
  28. import echarts from 'echarts'
  29. import * as filters from './filters' // global filters
  30. Vue.component('icon', Icon)
  31. Vue.use(dataV)
  32. Vue.component('flow-chart', FlowChart)
  33. Vue.prototype.$echarts = echarts
  34. window.Array.prototype.remove = function(val) {
  35. var index = this.indexOf(val)
  36. if (index > -1) {
  37. this.splice(index, 1)
  38. }
  39. }
  40. // 兼容
  41. if (typeof String.prototype.startsWith !== 'function') {
  42. window.String.prototype.startsWith = function(prefix) {
  43. return this.slice(0, prefix.length) === prefix
  44. }
  45. }
  46. Vue.use(globalComponents)
  47. Vue.use(Viewer, {
  48. defaultOptions: {
  49. zIndex: 9999
  50. }
  51. })
  52. Vue.use(base)
  53. import PuzzleVerification from 'vue-puzzle-verification'
  54. import { registerEvent } from '@/utils/watchToken'
  55. Vue.use(PuzzleVerification)
  56. registerEvent()
  57. // register global utility filters
  58. Object.keys(filters).forEach(key => {
  59. Vue.filter(key, filters[key])
  60. })
  61. Vue.config.productionTip = false
  62. Vue.use(ElementUI)
  63. router.beforeEach((to, from, next) => {
  64. if (to.path === '/login' || from.path === '/accept') {
  65. next()
  66. } else if (getToken() === null || getToken() === undefined || getToken() === '') {
  67. removeMenu()
  68. removeBtn()
  69. removeToken()
  70. // router.replace({ name: 'login' })
  71. next('/login')
  72. } else {
  73. next()
  74. }
  75. })
  76. window.vm = new Vue({
  77. router,
  78. store,
  79. render: h => h(App)
  80. }).$mount('#app')