main.js 4.3 KB

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