main.js 5.7 KB

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