main.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 } 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. console.log(ElementUI.Input)
  62. // 全局修改选择如果value与label都为数字0则清空
  63. const SelectValueWatch = ElementUI.Select.watch.value
  64. ElementUI.Select.watch.value = function (newValue, oldValue) {
  65. SelectValueWatch.call(this, newValue, oldValue)
  66. if (this.selected && this.selected.value === 0 && this.selected.currentLabel === 0 && newValue !== oldValue) {
  67. this.handleClearClick.call(this, {
  68. stopPropagation: () => { }
  69. })
  70. }
  71. }
  72. Vue.use(ElementUI)
  73. Vue.use(installComponents)
  74. // 命名根据需要,DonMessage只是在文章中使用
  75. export const $message = new DonMessage()
  76. Vue.prototype.$message = $message
  77. // 全局移除数字滚动
  78. document.addEventListener('mousewheel', function () {
  79. if (document.activeElement.type === 'number') {
  80. document.activeElement.blur()
  81. }
  82. })
  83. document.addEventListener('keydown', function (event) {
  84. if(event.keyCode == 13){
  85. setTimeout(res=>{
  86. document.activeElement.blur()
  87. },300)
  88. }
  89. })
  90. /**
  91. * If you don't want to use mock-server
  92. * you want to use MockJs for mock api
  93. * you can execute: mockXHR()
  94. *
  95. * Currently MockJs will be used in the production environment,
  96. * please remove it before going online! ! !
  97. */
  98. // import { mockXHR } from '../mock'
  99. // if (process.env.NODE_ENV === 'production') {
  100. // mockXHR()
  101. // }
  102. // 高德地址
  103. import VueAMap from 'vue-amap'
  104. Vue.use(VueAMap)
  105. // 检测浏览器是否缩放
  106. // import '@/utils/zoom'
  107. // set ElementUI lang to EN
  108. Vue.use(ElementUI, { locale })
  109. Vue.config.productionTip = false
  110. // 将selects全局混入当前vue实例中
  111. Vue.mixin({
  112. computed: {
  113. selects() {
  114. return store.state.selects
  115. },
  116. $helpers() {
  117. return {
  118. dayjs,
  119. numeral,
  120. lodash,
  121. qs,
  122. permission,
  123. }
  124. },
  125. $constant() {
  126. return constant
  127. }
  128. },
  129. methods: {
  130. changeHash(value) {
  131. const origin = window.location.origin
  132. history.replaceState("", "", `${origin}/#${this.$route.path}?opt=${value}`)
  133. },
  134. getFullPermission(str){
  135. let routeName = this.$route.path
  136. return str+routeName
  137. }
  138. }
  139. })
  140. new Vue({
  141. el: '#app',
  142. router,
  143. store,
  144. render: h => h(App)
  145. })