main.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. import { setToken } from '@/utils/auth'
  2. import { getUrlParam, findElem, deleteEmptyObj } from '@/utils/util'
  3. if (getUrlParam().token) {
  4. setToken(getUrlParam().token)
  5. }
  6. import Vue from 'vue'
  7. import 'normalize.css/normalize.css' // A modern alternative to CSS resets
  8. // import './plugins/jquery.hiwprint.js'
  9. import ElementUI from '@zjlib/element-ui2'
  10. import '@zjlib/element-ui2/lib/theme-chalk/index.css'
  11. import VueQuillEditor from 'vue-quill-editor'
  12. // require styles
  13. import 'quill/dist/quill.core.css'
  14. import 'quill/dist/quill.snow.css'
  15. import 'quill/dist/quill.bubble.css'
  16. Vue.use(VueQuillEditor /* { default global options } */)
  17. import dataV from '@jiaminghi/data-view'
  18. Vue.use(dataV)
  19. import VQuillEditor from '@/components/v-quill-editor'
  20. Vue.component('v-quill-editor', VQuillEditor)
  21. import { Loading } from '@zjlib/element-ui2'
  22. let loading
  23. function startLoading() {
  24. loading = Loading.service({
  25. lock: true,
  26. text: '拼命加载中...',
  27. spinner: 'el-icon-loading',
  28. customClass: '.app-container'
  29. })
  30. }
  31. function endLoading() {
  32. loading.close()
  33. }
  34. import * as echarts from 'echarts'
  35. Vue.prototype.$echarts = echarts
  36. import '@/styles/index.scss' // global css
  37. import App from './App'
  38. import store from './store'
  39. import router from './router'
  40. import '@/icons' // icon
  41. import '@/permission' // permission control
  42. import * as filters from './filters' // global filters
  43. import directives from './directives'
  44. window._AMapSecurityConfig = {
  45. serviceHost: 'https://jiasm.zfire.top/' + '_AMapService'
  46. }
  47. import '@zjlib/element-plugins/dest/element-plugins.css'
  48. import ElementPlugins, { AMap } from '@zjlib/element-plugins'
  49. Vue.use(ElementPlugins, {
  50. // 表单页面表单属性配置
  51. formAttributes: {
  52. 'label-position': 'right'
  53. }
  54. // // 操作记录配置
  55. // operationRecord: function (options) {
  56. // // console.log(options.meta.moduleId)
  57. // // return new Promise((r, j) => {
  58. // // r([[], []])
  59. // // })
  60. // }
  61. })
  62. // // 本地引用;
  63. // import ElementPlugins, { AMap } from '@packages'
  64. // Vue.use(ElementPlugins, {
  65. // formAttributes: {
  66. // 'label-position': 'right'
  67. // }
  68. // })
  69. Vue.use(AMap)
  70. AMap.initAMapApiLoader({
  71. // 高德的key
  72. key: 'df9bfabcba60cc6e7ad45ae9923a682d',
  73. plugins: ['AMap.Geocoder', 'AMap.AutoComplete', 'AMap.PlaceSearch']
  74. })
  75. Vue.use(AMap)
  76. AMap.initAMapApiLoader({
  77. // 高德的key
  78. key: 'df9bfabcba60cc6e7ad45ae9923a682d',
  79. version: '2.0',
  80. plugins: ['AMap.Geocoder', 'AMap.AutoComplete', 'AMap.PlaceSearch', 'AMap.DistrictSearch']
  81. })
  82. import '@/utils/time.js'
  83. import { getIPAdd } from '@/utils/lbs.js'
  84. getIPAdd()
  85. .then(res => {
  86. Vue.prototype.$IpAdd = res.data
  87. })
  88. .catch(err => {})
  89. // 成功/错误提示
  90. import { successMsg, errorMsg, warningNotify, checkBtnRole, getSummaries, numToFixed } from '@/utils/common.js'
  91. Vue.prototype.$successMsg = successMsg
  92. Vue.prototype.$errorMsg = errorMsg
  93. Vue.prototype.$warningNotify = warningNotify
  94. Vue.prototype.$checkBtnRole = checkBtnRole
  95. Vue.prototype.$getSummaries = getSummaries
  96. Vue.prototype.$numToFixed = numToFixed
  97. Vue.prototype.$startLoading = startLoading
  98. Vue.prototype.$endLoading = endLoading
  99. Vue.prototype.$restrict = function (...codes) {
  100. var roles = this.$route.meta.roles || []
  101. for (var code of codes) {
  102. if (roles.includes(code)) {
  103. return true
  104. }
  105. }
  106. return false
  107. }
  108. // 自定义组件
  109. import ExportButton from '@/components/Common/export-button.vue'
  110. Vue.component('ExportButton', ExportButton)
  111. import ImportButton from '@/components/Common/import-button.vue'
  112. Vue.component('ImportButton', ImportButton)
  113. import CopyButton from '@/components/Common/copy-button.vue'
  114. Vue.component('CopyButton', CopyButton)
  115. import Collapse from '@/components/Common/collapse'
  116. Vue.component('Collapse', Collapse)
  117. Vue.prototype.$xdocUrl = 'https://pgxtadm.greeapps.com/preview/onlinePreview?url='
  118. Vue.prototype.$imageUrl = process.env.VUE_APP_BASE_API + 'img/get?key='
  119. Vue.prototype.$showImgUrl = function (url) {
  120. // try {
  121. // const { pathname } = new URL(url)
  122. // if (pathname.startsWith('/')) {
  123. // return `${process.env.VUE_APP_BASE_API}img/get?key=${pathname.substring(1)}`
  124. // }
  125. // return `${process.env.VUE_APP_BASE_API}img/get?key=${pathname}`
  126. // } catch (error) {
  127. // return url
  128. // }
  129. return url
  130. }
  131. Vue.prototype.$findElem = findElem
  132. Vue.prototype.$deleteEmptyObj = deleteEmptyObj
  133. /**
  134. * If you don't want to use mock-server
  135. * you want to use MockJs for mock api
  136. * you can execute: mockXHR()
  137. *
  138. * Currently MockJs will be used in the production environment,
  139. * please remove it before going online ! ! !
  140. */
  141. if (process.env.NODE_ENV === 'production') {
  142. const { mockXHR } = require('../mock')
  143. mockXHR()
  144. }
  145. // set ElementUI lang to EN
  146. // Vue.use(ElementUI, { locale })
  147. // 如果想要中文版 element-ui,按如下方式声明
  148. Vue.use(ElementUI)
  149. import { Message } from 'element-ui'
  150. //定义一个新的Message方法,多传入一个offset参数
  151. const $message = options => {
  152. return Message({
  153. ...options,
  154. offset: 80
  155. })
  156. }
  157. //重写方法,将offset写入options
  158. ;['success', 'warning', 'info', 'error'].forEach(type => {
  159. $message[type] = options => {
  160. if (typeof options === 'string') {
  161. options = {
  162. message: options,
  163. offset: 80
  164. }
  165. }
  166. options.type = type
  167. return Message(options)
  168. }
  169. })
  170. //将$message挂载到this上
  171. Vue.prototype.$message = $message
  172. //不加这行代码运行this.$message.closeAll时会报错
  173. Vue.prototype.$message.closeAll = Message.closeAll
  174. // register global utility filters
  175. Object.keys(filters).forEach(key => {
  176. Vue.filter(key, filters[key])
  177. })
  178. Object.keys(directives).forEach(key => {
  179. Vue.directive(key, directives[key])
  180. })
  181. Vue.config.productionTip = false
  182. // 解决翻译
  183. import { translaBeforeRegistration } from './global-text-processor' // 导入插件
  184. Vue.prototype.$setLanguage = function (type) {
  185. window.localStorage.setItem('Vue_Translation_Of_Text_Type', type)
  186. setTimeout(() => {
  187. location.reload(true)
  188. }, 200)
  189. }
  190. translaBeforeRegistration(function () {
  191. new Vue({
  192. el: '#app',
  193. router,
  194. store,
  195. render: h => h(App)
  196. })
  197. })