main.js 5.8 KB

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