main.js 3.5 KB

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