main.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. Vue.use(AMap)
  63. AMap.initAMapApiLoader({
  64. // 高德的key
  65. key: 'df9bfabcba60cc6e7ad45ae9923a682d',
  66. version: '2.0',
  67. plugins: ['AMap.Geocoder', 'AMap.AutoComplete', 'AMap.PlaceSearch', 'AMap.DistrictSearch']
  68. })
  69. // // 本地引用;
  70. // import ElementPlugins, { AMap } from '@packages'
  71. // Vue.use(ElementPlugins, {
  72. // formAttributes: {
  73. // 'label-position': 'right'
  74. // }
  75. // })
  76. // Vue.use(AMap)
  77. // AMap.initAMapApiLoader({
  78. // // 高德的key
  79. // key: 'df9bfabcba60cc6e7ad45ae9923a682d',
  80. // plugins: ['AMap.Geocoder', 'AMap.AutoComplete', 'AMap.PlaceSearch']
  81. // })
  82. Number.prototype.toFixed = function (d) {
  83. var s = this + ''
  84. if (!d) d = 0
  85. if (s.indexOf('.') == -1) s += '.'
  86. s += new Array(d + 1).join('0')
  87. if (new RegExp('^(-|\\+)?(\\d+(\\.\\d{0,' + (d + 1) + '})?)\\d*$').test(s)) {
  88. var s = '0' + RegExp.$2,
  89. pm = RegExp.$1,
  90. a = RegExp.$3.length,
  91. b = true
  92. if (a == d + 2) {
  93. a = s.match(/\d/g)
  94. if (parseInt(a[a.length - 1]) > 4) {
  95. for (var i = a.length - 2; i >= 0; i--) {
  96. a[i] = parseInt(a[i]) + 1
  97. if (a[i] == 10) {
  98. a[i] = 0
  99. b = i != 1
  100. } else break
  101. }
  102. }
  103. s = a.join('').replace(new RegExp('(\\d+)(\\d{' + d + '})\\d$'), '$1.$2')
  104. }
  105. if (b) s = s.substr(1)
  106. return (pm + s).replace(/\.$/, '')
  107. }
  108. return this + ''
  109. }
  110. import '@/utils/time.js'
  111. import { getIPAdd } from '@/utils/lbs.js'
  112. getIPAdd()
  113. .then(res => {
  114. Vue.prototype.$IpAdd = res.data
  115. })
  116. .catch(err => {})
  117. // 成功/错误提示
  118. import { successMsg, errorMsg, warningNotify, checkBtnRole, getSummaries, numToFixed } from '@/utils/common.js'
  119. Vue.prototype.$successMsg = successMsg
  120. Vue.prototype.$errorMsg = errorMsg
  121. Vue.prototype.$warningNotify = warningNotify
  122. Vue.prototype.$checkBtnRole = checkBtnRole
  123. Vue.prototype.$getSummaries = getSummaries
  124. Vue.prototype.$numToFixed = numToFixed
  125. Vue.prototype.$startLoading = startLoading
  126. Vue.prototype.$endLoading = endLoading
  127. Vue.prototype.$restrict = function (...codes) {
  128. var roles = this.$route.meta.roles || []
  129. for (var code of codes) {
  130. if (roles.includes(code)) {
  131. return true
  132. }
  133. }
  134. return false
  135. }
  136. // 自定义组件
  137. import ExportButton from '@/components/Common/export-button.vue'
  138. Vue.component('ExportButton', ExportButton)
  139. import ImportButton from '@/components/Common/import-button.vue'
  140. Vue.component('ImportButton', ImportButton)
  141. import CopyButton from '@/components/Common/copy-button.vue'
  142. Vue.component('CopyButton', CopyButton)
  143. import Collapse from '@/components/Common/collapse'
  144. Vue.component('Collapse', Collapse)
  145. Vue.prototype.$xdocUrl = 'https://pgxtadm.greeapps.com/preview/onlinePreview?url='
  146. Vue.prototype.$imageUrl = process.env.VUE_APP_BASE_API + 'img/get?key='
  147. Vue.prototype.$showImgUrl = function (url) {
  148. try {
  149. const { pathname } = new URL(url)
  150. if (pathname.startsWith('/')) {
  151. return `${process.env.VUE_APP_BASE_API}img/get?key=${pathname.substring(1)}`
  152. }
  153. return `${process.env.VUE_APP_BASE_API}img/get?key=${pathname}`
  154. } catch (error) {
  155. return url
  156. }
  157. }
  158. Vue.prototype.$findElem = findElem
  159. Vue.prototype.$deleteEmptyObj = deleteEmptyObj
  160. /**
  161. * If you don't want to use mock-server
  162. * you want to use MockJs for mock api
  163. * you can execute: mockXHR()
  164. *
  165. * Currently MockJs will be used in the production environment,
  166. * please remove it before going online ! ! !
  167. */
  168. if (process.env.NODE_ENV === 'production') {
  169. const { mockXHR } = require('../mock')
  170. mockXHR()
  171. }
  172. // set ElementUI lang to EN
  173. // Vue.use(ElementUI, { locale })
  174. // 如果想要中文版 element-ui,按如下方式声明
  175. Vue.use(ElementUI)
  176. import { Message } from 'element-ui'
  177. //定义一个新的Message方法,多传入一个offset参数
  178. const $message = options => {
  179. return Message({
  180. ...options,
  181. offset: 80
  182. })
  183. }
  184. //重写方法,将offset写入options
  185. ;['success', 'warning', 'info', 'error'].forEach(type => {
  186. $message[type] = options => {
  187. if (typeof options === 'string') {
  188. options = {
  189. message: options,
  190. offset: 80
  191. }
  192. }
  193. options.type = type
  194. return Message(options)
  195. }
  196. })
  197. //将$message挂载到this上
  198. Vue.prototype.$message = $message
  199. //不加这行代码运行this.$message.closeAll时会报错
  200. Vue.prototype.$message.closeAll = Message.closeAll
  201. // register global utility filters
  202. Object.keys(filters).forEach(key => {
  203. Vue.filter(key, filters[key])
  204. })
  205. Object.keys(directives).forEach(key => {
  206. Vue.directive(key, directives[key])
  207. })
  208. Vue.config.productionTip = false
  209. new Vue({
  210. el: '#app',
  211. router,
  212. store,
  213. render: h => h(App)
  214. })