main.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. Progress
  62. } from 'element-ui'
  63. function getCurrentUserSuccess(res){
  64. }
  65. // var _hmt = _hmt || [];
  66. // (function() {
  67. // var hm = document.createElement("script");
  68. // hm.src = "https://hm.baidu.com/hm.js?0e3bd98236bd62558926fc433751d60c";
  69. // var s = document.getElementsByTagName("script")[0];
  70. // s.parentNode.insertBefore(hm, s);
  71. // })();
  72. router.beforeEach((to, from, next) => {
  73. // if (_hmt) {
  74. // if (to.path) {
  75. // _hmt.push(['_trackPageview', '/#' + to.fullPath]);
  76. // }
  77. // }
  78. const urls = getAuthUrls()
  79. if (storageGet('user') == null) {
  80. getCurrentUser().then((res) => {
  81. storageSave('user', res)
  82. storageSave('rolesPermissions', getRolesPermissions(res.roleList))
  83. if (to.matched.some(record => record.meta.requireAuth)) { // 判断该路由是否需要登录权限
  84. if (sessionStorage.userName === '2' && urls.includes(to.matched[0].path)) { // 判断缓存里面是否有 userName //在登录的时候设置它的值
  85. next()
  86. } else {
  87. next({
  88. path: '/',
  89. query: {
  90. redirect: to.fullPath
  91. } // 将跳转的路由path作为参数,登录成功后跳转到该路由
  92. })
  93. }
  94. } else {
  95. next()
  96. }
  97. }).catch((error) => {
  98. notify('warning', '请登录')
  99. if (to.matched.some(record => record.meta.requireAuth)) { // 判断该路由是否需要登录权限
  100. if (sessionStorage.userName === '2' && urls.includes(to.matched[0].path)) { // 判断缓存里面是否有 userName //在登录的时候设置它的值
  101. next()
  102. } else {
  103. next({
  104. path: '/',
  105. query: {
  106. redirect: to.fullPath
  107. } // 将跳转的路由path作为参数,登录成功后跳转到该路由
  108. })
  109. }
  110. } else {
  111. next()
  112. }
  113. })
  114. } else {
  115. if (to.matched.some(record => record.meta.requireAuth)) { // 判断该路由是否需要登录权限
  116. if (sessionStorage.userName === '2' && urls.includes(to.matched[0].path)) { // 判断缓存里面是否有 userName //在登录的时候设置它的值
  117. next()
  118. } else {
  119. next({
  120. path: '/',
  121. query: {
  122. redirect: to.fullPath
  123. } // 将跳转的路由path作为参数,登录成功后跳转到该路由
  124. })
  125. }
  126. } else {
  127. next()
  128. }
  129. }
  130. //console.log(to.matched[0].path)
  131. //console.log(urls.includes(to.matched[0].path))
  132. })
  133. // require('./mock.js')
  134. Vue.use(Carousel)
  135. Vue.use(CarouselItem)
  136. Vue.use(Row)
  137. Vue.use(Col)
  138. Vue.use(Table)
  139. Vue.use(TableColumn)
  140. Vue.use(Form)
  141. Vue.use(FormItem)
  142. Vue.use(Button)
  143. Vue.use(ButtonGroup)
  144. Vue.use(Menu)
  145. Vue.use(Submenu)
  146. Vue.use(MenuItem)
  147. Vue.use(MenuItemGroup)
  148. Vue.use(Input)
  149. Vue.use(InputNumber)
  150. Vue.use(Radio)
  151. Vue.use(RadioGroup)
  152. Vue.use(RadioButton)
  153. Vue.use(Checkbox)
  154. Vue.use(CheckboxButton)
  155. Vue.use(CheckboxGroup)
  156. Vue.use(DatePicker)
  157. Vue.use(TimeSelect)
  158. Vue.use(TimePicker)
  159. Vue.use(Switch)
  160. Vue.use(Select)
  161. Vue.use(Option)
  162. Vue.use(Upload)
  163. Vue.use(Tabs)
  164. Vue.use(TabPane)
  165. Vue.use(Collapse)
  166. Vue.use(CollapseItem)
  167. Vue.use(Dialog)
  168. Vue.use(Card)
  169. Vue.use(Tag)
  170. Vue.use(Avatar)
  171. Vue.use(Pagination)
  172. Vue.use(Link)
  173. Vue.use(Loading)
  174. Vue.use(Tooltip)
  175. Vue.use(Dropdown)
  176. Vue.use(DropdownItem)
  177. Vue.use(DropdownMenu)
  178. Vue.use(Image)
  179. Vue.use(Badge)
  180. Vue.use(Popover)
  181. Vue.use(Progress)
  182. Vue.prototype.$msgbox = MessageBox
  183. Vue.prototype.$alert = MessageBox.alert
  184. Vue.prototype.$confirm = MessageBox.confirm
  185. Vue.prototype.$prompt = MessageBox.prompt
  186. Vue.prototype.$notify = Notification
  187. Vue.prototype.$message = Message
  188. Vue.config.productionTip = false
  189. /* eslint-disable no-new */
  190. new Vue({
  191. el: '#app',
  192. router,
  193. data:{
  194. Bus:new Vue()
  195. },
  196. components: {App},
  197. template: '<App/>'
  198. })