调解系统PC端服务

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import Vue from 'vue'
  2. import Cookies from 'js-cookie'
  3. import Element from 'element-ui'
  4. import './assets/styles/element-variables.scss'
  5. import './assets/icons' // icon
  6. import '@/assets/styles/index.scss' // global css
  7. import '@/assets/styles/ruoyi.scss' // ruoyi css
  8. import App from './App'
  9. import store from './store'
  10. import router from './router'
  11. import directive from './directive' // directive
  12. import plugins from './plugins' // plugins
  13. import { download } from '@/utils/request'
  14. import { Message } from 'element-ui'
  15. import NProgress from 'nprogress'
  16. import 'nprogress/nprogress.css'
  17. import { getToken } from '@/utils/auth'
  18. import { isRelogin } from '@/utils/request'
  19. import './assets/icons' // icon
  20. // 引入Iconfont 矢量图标库
  21. import './assets/icon/iconfont.css'
  22. // import './permission' // permission control
  23. import { getDicts } from "@/api/system/dict/data";
  24. import { getConfigKey } from "@/api/system/config";
  25. import { parseTime, resetForm, addDateRange, selectDictLabel, selectDictLabels, handleTree } from "@/utils/ruoyi";
  26. // 分页组件
  27. import Pagination from "@/components/Pagination";
  28. // 自定义表格工具组件
  29. import RightToolbar from "@/components/RightToolbar"
  30. // 富文本组件
  31. import Editor from "@/components/Editor"
  32. // 文件上传组件
  33. import FileUpload from "@/components/FileUpload"
  34. // 图片上传组件
  35. import ImageUpload from "@/components/ImageUpload"
  36. // 图片预览组件
  37. import ImagePreview from "@/components/ImagePreview"
  38. // 字典标签组件
  39. import DictTag from '@/components/DictTag'
  40. // 头部标签组件
  41. import VueMeta from 'vue-meta'
  42. // 字典数据组件
  43. import DictData from '@/components/DictData'
  44. //画布组件
  45. import vueEsign from 'vue-esign'
  46. import {checkPermi} from '@/utils/permission'
  47. // 全局方法挂载
  48. Vue.prototype.getDicts = getDicts
  49. Vue.prototype.getConfigKey = getConfigKey
  50. Vue.prototype.parseTime = parseTime
  51. Vue.prototype.resetForm = resetForm
  52. Vue.prototype.addDateRange = addDateRange
  53. Vue.prototype.selectDictLabel = selectDictLabel
  54. Vue.prototype.selectDictLabels = selectDictLabels
  55. Vue.prototype.download = download
  56. Vue.prototype.handleTree = handleTree
  57. Vue.prototype.checkPermi = checkPermi
  58. // 全局组件挂载
  59. Vue.component('DictTag', DictTag)
  60. Vue.component('Pagination', Pagination)
  61. Vue.component('RightToolbar', RightToolbar)
  62. Vue.component('Editor', Editor)
  63. Vue.component('FileUpload', FileUpload)
  64. Vue.component('ImageUpload', ImageUpload)
  65. Vue.component('ImagePreview', ImagePreview)
  66. Vue.use(directive)
  67. Vue.use(plugins)
  68. Vue.use(VueMeta)
  69. Vue.use(vueEsign)
  70. DictData.install()
  71. /**
  72. * If you don't want to use mock-server
  73. * you want to use MockJs for mock api
  74. * you can execute: mockXHR()
  75. *
  76. * Currently MockJs will be used in the production environment,
  77. * please remove it before going online! ! !
  78. */
  79. NProgress.configure({ showSpinner: false })
  80. const whiteList = ['/login', '/register']
  81. router.beforeEach((to, from, next) => {
  82. let path = to.fullPath
  83. if(path.indexOf('token') != -1){
  84. path = path.split('token=');
  85. path = path[1];
  86. Cookies.set("Admin-Token", path)
  87. }
  88. NProgress.start()
  89. if (getToken()) {
  90. to.meta.title && store.dispatch('settings/setTitle', to.meta.title)
  91. /* has token*/
  92. if (to.path === '/login') {
  93. next({ path: '/' })
  94. NProgress.done()
  95. } else {
  96. if (store.getters.roles.length === 0) {
  97. isRelogin.show = true
  98. // 判断当前用户是否已拉取完user_info信息
  99. store.dispatch('GetInfo').then(() => {
  100. isRelogin.show = false
  101. store.dispatch('GenerateRoutes').then(accessRoutes => {
  102. // 根据roles权限生成可访问的路由表
  103. router.addRoutes(accessRoutes) // 动态添加可访问路由表
  104. next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
  105. })
  106. }).catch(err => {
  107. store.dispatch('LogOut').then(() => {
  108. Message.error(err)
  109. next({ path: '/' })
  110. })
  111. })
  112. } else {
  113. next()
  114. }
  115. }
  116. } else {
  117. // 没有token
  118. if (whiteList.indexOf(to.path) !== -1) {
  119. // 在免登录白名单,直接进入
  120. next()
  121. } else {
  122. // next(`/login?redirect=${encodeURIComponent(to.fullPath)}`) // 否则全部重定向到登录页
  123. next(`/login`)
  124. NProgress.done()
  125. }
  126. }
  127. })
  128. router.afterEach(() => {
  129. NProgress.done()
  130. })
  131. Vue.use(Element, {
  132. size: Cookies.get('size') || 'medium' // set element-ui default size
  133. })
  134. Vue.config.productionTip = false
  135. new Vue({
  136. el: '#app',
  137. router,
  138. store,
  139. render: h => h(App)
  140. })