main.js 3.2 KB

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