main.js 4.9 KB

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