main.js 4.8 KB

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