main.js 3.9 KB

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