main.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. import { getTenantId } from "@/utils/auth";
  15. dayjs.extend(isSameOrBefore);
  16. dayjs.extend(isSameOrAfter);
  17. dayjs.extend(isBetween);
  18. import * as constant from "@/constant";
  19. import "normalize.css/normalize.css"; // A modern alternative to CSS resets
  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 "@/styles/iconfont/iconfont.css"; // 字体图标,主要用于菜单图标
  27. // import '@/assets/element-variables.scss'
  28. import App from "./App";
  29. import store from "./store";
  30. import installComponents from "@/components/install";
  31. import router from "./router";
  32. import "./utils/vueFilter";
  33. import "./utils/directive";
  34. // Vue.use(vueFilter)
  35. import "@/icons"; // icon
  36. import "@/permission"; // permission control
  37. import { Message } from "element-ui";
  38. const showMessage = Symbol("showMessage");
  39. // imkit 为核心模块
  40. import { defineCustomElements } from "@rongcloud/imkit";
  41. defineCustomElements();
  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 (
  80. this.selected &&
  81. this.selected.value === 0 &&
  82. this.selected.currentLabel === 0 &&
  83. newValue !== oldValue
  84. ) {
  85. this.handleClearClick.call(this, {
  86. stopPropagation: () => {}
  87. });
  88. }
  89. };
  90. // Vue.use(ElementUI)
  91. Vue.use(installComponents);
  92. // 命名根据需要,DonMessage只是在文章中使用
  93. export const $message = new DonMessage();
  94. Vue.prototype.$message = $message;
  95. // 全局移除数字滚动
  96. document.addEventListener("mousewheel", function() {
  97. if (document.activeElement.type === "number") {
  98. document.activeElement.blur();
  99. }
  100. });
  101. // 费用审核输入框回车之后失去焦点有问题,所以注释
  102. // document.addEventListener('keydown', function (event) {
  103. // if (event.keyCode == 13) {
  104. // setTimeout(() => {
  105. // document.activeElement.blur()
  106. // }, 300)
  107. // }
  108. // })
  109. /**
  110. * If you don't want to use mock-server
  111. * you want to use MockJs for mock api
  112. * you can execute: mockXHR()
  113. *
  114. * Currently MockJs will be used in the production environment,
  115. * please remove it before going online! ! !
  116. */
  117. // import { mockXHR } from '../mock'
  118. // if (process.env.NODE_ENV === 'production') {
  119. // mockXHR()
  120. // }
  121. // 高德地址
  122. import VueAMap from "vue-amap";
  123. Vue.use(VueAMap);
  124. // 检测浏览器是否缩放
  125. // import '@/utils/zoom'
  126. Vue.prototype.$ELEMENT = {
  127. size: "medium",
  128. zIndex: 3000
  129. };
  130. // set ElementUI lang to EN
  131. Vue.use(ElementUI, {
  132. locale
  133. });
  134. Vue.config.productionTip = false;
  135. Vue.prototype.$bus = new Vue();
  136. // 将selects全局混入当前vue实例中
  137. Vue.mixin({
  138. computed: {
  139. selects() {
  140. return store.state.selects;
  141. },
  142. $helpers() {
  143. return {
  144. dayjs,
  145. numeral,
  146. lodash,
  147. qs,
  148. permission,
  149. tenantId: getTenantId()
  150. };
  151. },
  152. $constant() {
  153. return constant;
  154. }
  155. },
  156. methods: {
  157. isNumber(val, max) {
  158. // 只能输入正整数,且可以限制最大值,用法:@input="e => (form.cloud_room_up_limit = isNumber(e, 7))"
  159. val = val.replace(/\b(0+)+[^0-9]*/gi, "");
  160. if (val > max) {
  161. val = max;
  162. }
  163. return val;
  164. },
  165. keyupEvent(e, input) {
  166. // 正数,小数2位 @keyup.native='keyupEvent($event)'
  167. e.target.value = e.target.value.replace(/[^\d.]/g, "");
  168. e.target.value = e.target.value.replace(/\.{2,}/g, ".");
  169. e.target.value = e.target.value.replace(/^\./g, "0.");
  170. e.target.value = e.target.value.replace(
  171. /^\d*\.\d*\./g,
  172. e.target.value.substring(0, e.target.value.length - 1)
  173. );
  174. e.target.value = e.target.value.replace(/^0[^\.]+/g, "0");
  175. e.target.value = e.target.value.replace(/^(\d+)\.(\d\d).*$/, "$1.$2");
  176. },
  177. changeHash(value) {
  178. const origin = window.location.origin;
  179. history.replaceState(
  180. "",
  181. "",
  182. `${origin}/#${this.$route.path}?opt=${value}`
  183. );
  184. },
  185. getFullPermission(str) {
  186. let routeName = this.$route.path;
  187. return str + routeName;
  188. }
  189. }
  190. });
  191. new Vue({
  192. el: "#app",
  193. router,
  194. store,
  195. render: h => h(App)
  196. });