main.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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, getCurrentUser, getRolesPermissions, storageGet, storageSave} from '@/js/index'
  9. import {notify} from '@/constants/index'
  10. import {
  11. Avatar,
  12. Badge,
  13. Button,
  14. ButtonGroup,
  15. Card,
  16. Carousel,
  17. CarouselItem,
  18. Checkbox,
  19. CheckboxButton,
  20. CheckboxGroup,
  21. Col,
  22. Collapse,
  23. CollapseItem,
  24. DatePicker,
  25. Dialog,
  26. Dropdown,
  27. DropdownItem,
  28. DropdownMenu,
  29. Form,
  30. FormItem,
  31. Image,
  32. Input,
  33. InputNumber,
  34. Link,
  35. Loading,
  36. Menu,
  37. MenuItem,
  38. MenuItemGroup,
  39. Message,
  40. MessageBox,
  41. Notification,
  42. Option,
  43. Pagination,
  44. Popover,
  45. Radio,
  46. RadioButton,
  47. RadioGroup,
  48. Row,
  49. Select,
  50. Submenu,
  51. Switch,
  52. Table,
  53. TableColumn,
  54. TabPane,
  55. Tabs,
  56. Tag,
  57. TimePicker,
  58. TimeSelect,
  59. Tooltip,
  60. Upload,
  61. } from 'element-ui'
  62. function getCurrentUserSuccess(res){
  63. }
  64. router.beforeEach((to, from, next) => {
  65. const urls = getAuthUrls()
  66. if (storageGet('user') == null) {
  67. getCurrentUser().then((res) => {
  68. storageSave('user', res)
  69. storageSave('rolesPermissions', getRolesPermissions(res.roleList))
  70. if (to.matched.some(record => record.meta.requireAuth)) { // 判断该路由是否需要登录权限
  71. if (sessionStorage.userName === '2' && urls.includes(to.matched[0].path)) { // 判断缓存里面是否有 userName //在登录的时候设置它的值
  72. next()
  73. } else {
  74. next({
  75. path: '/',
  76. query: {
  77. redirect: to.fullPath
  78. } // 将跳转的路由path作为参数,登录成功后跳转到该路由
  79. })
  80. }
  81. } else {
  82. next()
  83. }
  84. }).catch((error) => {
  85. notify('warning', '请登录')
  86. if (to.matched.some(record => record.meta.requireAuth)) { // 判断该路由是否需要登录权限
  87. if (sessionStorage.userName === '2' && urls.includes(to.matched[0].path)) { // 判断缓存里面是否有 userName //在登录的时候设置它的值
  88. next()
  89. } else {
  90. next({
  91. path: '/',
  92. query: {
  93. redirect: to.fullPath
  94. } // 将跳转的路由path作为参数,登录成功后跳转到该路由
  95. })
  96. }
  97. } else {
  98. next()
  99. }
  100. })
  101. } else {
  102. if (to.matched.some(record => record.meta.requireAuth)) { // 判断该路由是否需要登录权限
  103. if (sessionStorage.userName === '2' && urls.includes(to.matched[0].path)) { // 判断缓存里面是否有 userName //在登录的时候设置它的值
  104. next()
  105. } else {
  106. next({
  107. path: '/',
  108. query: {
  109. redirect: to.fullPath
  110. } // 将跳转的路由path作为参数,登录成功后跳转到该路由
  111. })
  112. }
  113. } else {
  114. next()
  115. }
  116. }
  117. //console.log(to.matched[0].path)
  118. //console.log(urls.includes(to.matched[0].path))
  119. })
  120. // require('./mock.js')
  121. Vue.use(Carousel)
  122. Vue.use(CarouselItem)
  123. Vue.use(Row)
  124. Vue.use(Col)
  125. Vue.use(Table)
  126. Vue.use(TableColumn)
  127. Vue.use(Form)
  128. Vue.use(FormItem)
  129. Vue.use(Button)
  130. Vue.use(ButtonGroup)
  131. Vue.use(Menu)
  132. Vue.use(Submenu)
  133. Vue.use(MenuItem)
  134. Vue.use(MenuItemGroup)
  135. Vue.use(Input)
  136. Vue.use(InputNumber)
  137. Vue.use(Radio)
  138. Vue.use(RadioGroup)
  139. Vue.use(RadioButton)
  140. Vue.use(Checkbox)
  141. Vue.use(CheckboxButton)
  142. Vue.use(CheckboxGroup)
  143. Vue.use(DatePicker)
  144. Vue.use(TimeSelect)
  145. Vue.use(TimePicker)
  146. Vue.use(Switch)
  147. Vue.use(Select)
  148. Vue.use(Option)
  149. Vue.use(Upload)
  150. Vue.use(Tabs)
  151. Vue.use(TabPane)
  152. Vue.use(Collapse)
  153. Vue.use(CollapseItem)
  154. Vue.use(Dialog)
  155. Vue.use(Card)
  156. Vue.use(Tag)
  157. Vue.use(Avatar)
  158. Vue.use(Pagination)
  159. Vue.use(Link)
  160. Vue.use(Loading)
  161. Vue.use(Tooltip)
  162. Vue.use(Dropdown)
  163. Vue.use(DropdownItem)
  164. Vue.use(DropdownMenu)
  165. Vue.use(Image)
  166. Vue.use(Badge)
  167. Vue.use(Popover)
  168. Vue.prototype.$msgbox = MessageBox
  169. Vue.prototype.$alert = MessageBox.alert
  170. Vue.prototype.$confirm = MessageBox.confirm
  171. Vue.prototype.$prompt = MessageBox.prompt
  172. Vue.prototype.$notify = Notification
  173. Vue.prototype.$message = Message
  174. Vue.config.productionTip = false
  175. /* eslint-disable no-new */
  176. new Vue({
  177. el: '#app',
  178. router,
  179. data:{
  180. Bus:new Vue()
  181. },
  182. components: {App},
  183. template: '<App/>'
  184. })