main.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // The Vue build version to load with the `import` command
  2. // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
  3. import Vue from 'vue'
  4. import App from './App'
  5. import router from './router'
  6. import 'font-awesome/css/font-awesome.css'
  7. import './style/main.scss'
  8. import {getAuthUrls} from '@/js/index'
  9. import {
  10. Avatar,
  11. Button,
  12. ButtonGroup,
  13. Card,
  14. Carousel,
  15. CarouselItem,
  16. Checkbox,
  17. CheckboxButton,
  18. CheckboxGroup,
  19. Col,
  20. Collapse,
  21. CollapseItem,
  22. DatePicker,
  23. Dialog,
  24. Form,
  25. FormItem,
  26. Input,
  27. InputNumber,
  28. Menu,
  29. MenuItem,
  30. MenuItemGroup,
  31. Message,
  32. MessageBox,
  33. Notification,
  34. Option,
  35. Radio,
  36. RadioButton,
  37. RadioGroup,
  38. Row,
  39. Select,
  40. Submenu,
  41. Switch,
  42. Table,
  43. TableColumn,
  44. TabPane,
  45. Tabs,
  46. Tag,
  47. TimePicker,
  48. TimeSelect,
  49. Upload,
  50. } from 'element-ui'
  51. router.beforeEach((to, from, next) => {
  52. const urls = getAuthUrls()
  53. //console.log(to.matched[0].path)
  54. //console.log(urls.includes(to.matched[0].path))
  55. if (to.matched.some(record => record.meta.requireAuth)) { // 判断该路由是否需要登录权限
  56. //console.log('需要登录')
  57. if (sessionStorage.userName === '2' && urls.includes(to.matched[0].path)) { // 判断缓存里面是否有 userName //在登录的时候设置它的值
  58. //console.log('未拦截')
  59. next()
  60. } else {
  61. //console.log('拦截')
  62. next({
  63. path: '/',
  64. query: {
  65. redirect: to.fullPath
  66. } // 将跳转的路由path作为参数,登录成功后跳转到该路由
  67. })
  68. }
  69. } else {
  70. //console.log('不需要登录')
  71. next()
  72. }
  73. })
  74. // require('./mock.js')
  75. Vue.use(Carousel)
  76. Vue.use(CarouselItem)
  77. Vue.use(Row)
  78. Vue.use(Col)
  79. Vue.use(Table)
  80. Vue.use(TableColumn)
  81. Vue.use(Form)
  82. Vue.use(FormItem)
  83. Vue.use(Button)
  84. Vue.use(ButtonGroup)
  85. Vue.use(Menu)
  86. Vue.use(Submenu)
  87. Vue.use(MenuItem)
  88. Vue.use(MenuItemGroup)
  89. Vue.use(Input)
  90. Vue.use(InputNumber)
  91. Vue.use(Radio)
  92. Vue.use(RadioGroup)
  93. Vue.use(RadioButton)
  94. Vue.use(Checkbox)
  95. Vue.use(CheckboxButton)
  96. Vue.use(CheckboxGroup)
  97. Vue.use(DatePicker)
  98. Vue.use(TimeSelect)
  99. Vue.use(TimePicker)
  100. Vue.use(Switch)
  101. Vue.use(Select)
  102. Vue.use(Option)
  103. Vue.use(Upload)
  104. Vue.use(Tabs)
  105. Vue.use(TabPane)
  106. Vue.use(Collapse)
  107. Vue.use(CollapseItem)
  108. Vue.use(Dialog)
  109. Vue.use(Card)
  110. Vue.use(Tag)
  111. Vue.use(Avatar)
  112. Vue.prototype.$msgbox = MessageBox
  113. Vue.prototype.$alert = MessageBox.alert
  114. Vue.prototype.$confirm = MessageBox.confirm
  115. Vue.prototype.$prompt = MessageBox.prompt
  116. Vue.prototype.$notify = Notification
  117. Vue.prototype.$message = Message
  118. Vue.config.productionTip = false
  119. /* eslint-disable no-new */
  120. new Vue({
  121. el: '#app',
  122. router,
  123. components: {App},
  124. template: '<App/>'
  125. })