main.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import Vue from 'vue'
  2. import ElementUI from 'element-ui'
  3. import 'normalize.css/normalize.css' // A modern alternative to CSS resets
  4. import 'default-passive-events'
  5. import 'babel-polyfill'
  6. // import './global.scss'
  7. import 'element-ui/lib/theme-chalk/index.css'
  8. import locale from 'element-ui/lib/locale/lang/zh-CN' // lang i18n
  9. import '@/styles/index.scss' // global css
  10. import App from './App'
  11. import store from './store'
  12. import router from './router'
  13. import './utils/vueFilter'
  14. import './utils/directive'
  15. // Vue.use(vueFilter)
  16. import '@/icons' // icon
  17. import '@/permission' // permission control
  18. import { Message } from 'element-ui'
  19. const showMessage = Symbol('showMessage')
  20. class DonMessage {
  21. success (options, single = true) {
  22. this[showMessage]('success', options, single)
  23. }
  24. warning (options, single = true) {
  25. this[showMessage]('warning', options, single)
  26. }
  27. info (options, single = true) {
  28. this[showMessage]('info', options, single)
  29. }
  30. error (options, single = true) {
  31. this[showMessage]('error', options, single)
  32. }
  33. [showMessage] (type, options, single) {
  34. if (single) {
  35. // 判断是否已存在Message
  36. if (document.getElementsByClassName('el-message').length === 0) {
  37. Message[type](options)
  38. }
  39. } else {
  40. Message[type](options)
  41. }
  42. }
  43. }
  44. // 修改默认属性
  45. ElementUI.Dialog.props.closeOnClickModal.default = false;
  46. // ElementUI.Dialog.props.destroyOnClose.default = true;
  47. // 全局修改选择如果value与label都为数字0则清空
  48. const SelectValueWatch = ElementUI.Select.watch.value
  49. ElementUI.Select.watch.value = function (newValue, oldValue) {
  50. SelectValueWatch.call(this, newValue, oldValue)
  51. if(this.selected && this.selected.value === 0 && this.selected.currentLabel === 0 && newValue !== oldValue) {
  52. this.handleClearClick.call(this, {
  53. stopPropagation: () => {}
  54. })
  55. }
  56. }
  57. Vue.use(ElementUI)
  58. // 命名根据需要,DonMessage只是在文章中使用
  59. export const $message = new DonMessage()
  60. Vue.prototype.$message = $message
  61. // 全局移除数字滚动
  62. document.addEventListener('mousewheel', function (event) {
  63. if (document.activeElement.type === 'number') {
  64. document.activeElement.blur()
  65. }
  66. })
  67. /**
  68. * If you don't want to use mock-server
  69. * you want to use MockJs for mock api
  70. * you can execute: mockXHR()
  71. *
  72. * Currently MockJs will be used in the production environment,
  73. * please remove it before going online! ! !
  74. */
  75. // import { mockXHR } from '../mock'
  76. // if (process.env.NODE_ENV === 'production') {
  77. // mockXHR()
  78. // }
  79. // 高德地址
  80. import VueAMap from 'vue-amap'
  81. Vue.use(VueAMap)
  82. // set ElementUI lang to EN
  83. Vue.use(ElementUI, { locale })
  84. Vue.config.productionTip = false
  85. new Vue({
  86. el: '#app',
  87. router,
  88. store,
  89. render: h => h(App)
  90. })