main.js 5.4 KB

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