main.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import Vue from 'vue'
  2. import ElementUI from 'element-ui'
  3. import dayjs from 'dayjs'
  4. import numeral from 'numeral'
  5. import lodash from 'lodash'
  6. import qs from 'qs'
  7. import { permission } from "@/utils/directivePage";
  8. import * as constant from '@/constant'
  9. import 'normalize.css/normalize.css' // A modern alternative to CSS resets
  10. import 'default-passive-events'
  11. import 'babel-polyfill'
  12. import './theme/index.css'
  13. // import './global.scss'
  14. // import 'element-ui/lib/theme-chalk/index.css'
  15. import locale from 'element-ui/lib/locale/lang/zh-CN' // lang i18n
  16. import '@/styles/index.scss' // global css
  17. import App from './App'
  18. import store from './store'
  19. import installComponents from '@/components/install'
  20. import router from './router'
  21. import './utils/vueFilter'
  22. import './utils/directive'
  23. // Vue.use(vueFilter)
  24. import '@/icons' // icon
  25. import '@/permission' // permission control
  26. import { Message } from 'element-ui'
  27. const showMessage = Symbol('showMessage')
  28. class DonMessage {
  29. success (options, single = true) {
  30. this[showMessage]('success', options, single)
  31. }
  32. warning (options, single = true) {
  33. this[showMessage]('warning', options, single)
  34. }
  35. info (options, single = true) {
  36. this[showMessage]('info', options, single)
  37. }
  38. error (options, single = true) {
  39. this[showMessage]('error', options, single)
  40. }
  41. [showMessage] (type, options, single) {
  42. if (single) {
  43. // 判断是否已存在Message
  44. if (document.getElementsByClassName('el-message').length === 0) {
  45. Message[type](options)
  46. }
  47. } else {
  48. Message[type](options)
  49. }
  50. }
  51. }
  52. // 修改默认属性
  53. ElementUI.Dialog.props.closeOnClickModal.default = false;
  54. // ElementUI.Dialog.props.destroyOnClose.default = true;
  55. // 全局修改选择如果value与label都为数字0则清空
  56. const SelectValueWatch = ElementUI.Select.watch.value
  57. ElementUI.Select.watch.value = function (newValue, oldValue) {
  58. SelectValueWatch.call(this, newValue, oldValue)
  59. if (this.selected && this.selected.value === 0 && this.selected.currentLabel === 0 && newValue !== oldValue) {
  60. this.handleClearClick.call(this, {
  61. stopPropagation: () => { }
  62. })
  63. }
  64. }
  65. Vue.use(ElementUI)
  66. Vue.use(installComponents)
  67. // 命名根据需要,DonMessage只是在文章中使用
  68. export const $message = new DonMessage()
  69. Vue.prototype.$message = $message
  70. // 全局移除数字滚动
  71. document.addEventListener('mousewheel', function () {
  72. if (document.activeElement.type === 'number') {
  73. document.activeElement.blur()
  74. }
  75. })
  76. /**
  77. * If you don't want to use mock-server
  78. * you want to use MockJs for mock api
  79. * you can execute: mockXHR()
  80. *
  81. * Currently MockJs will be used in the production environment,
  82. * please remove it before going online! ! !
  83. */
  84. // import { mockXHR } from '../mock'
  85. // if (process.env.NODE_ENV === 'production') {
  86. // mockXHR()
  87. // }
  88. // 高德地址
  89. import VueAMap from 'vue-amap'
  90. Vue.use(VueAMap)
  91. // 检测浏览器是否缩放
  92. // import '@/utils/zoom'
  93. // set ElementUI lang to EN
  94. Vue.use(ElementUI, { locale })
  95. Vue.config.productionTip = false
  96. // 将selects全局混入当前vue实例中
  97. Vue.mixin({
  98. computed: {
  99. selects() {
  100. return store.state.selects
  101. },
  102. $helpers() {
  103. return {
  104. dayjs,
  105. numeral,
  106. lodash,
  107. qs,
  108. permission,
  109. }
  110. },
  111. $constant() {
  112. return constant
  113. }
  114. },
  115. methods: {
  116. changeHash(value) {
  117. const origin = window.location.origin
  118. history.replaceState("", "", `${origin}/#${this.$route.path}?opt=${value}`)
  119. }
  120. }
  121. })
  122. new Vue({
  123. el: '#app',
  124. router,
  125. store,
  126. render: h => h(App)
  127. })