main.js 4.5 KB

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