main.js 4.2 KB

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