main.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import { createApp } from "vue";
  2. import App from "./App.vue";
  3. import router from "./router";
  4. import store from "./store";
  5. import "font-awesome/css/font-awesome.min.css";
  6. // 引入 element-ui
  7. import ElementPlus from "element-plus";
  8. import "element-plus/dist/index.css";
  9. // import "element-plus/lib/theme-chalk/index.css";
  10. import locale from "element-plus/lib/locale/lang/zh-cn";
  11. import * as ElementPlusIconsVue from "@element-plus/icons-vue";
  12. // // 引入环境配置
  13. // import "@modeConfig/modeConfig.js";
  14. import "@/lib/global-import.js";
  15. import "./permission";
  16. // 引入请求工具
  17. import axios from "@api/axios";
  18. // 引入基础工具
  19. import basicTool from "@tools/basicTool";
  20. import animated from "animate.css";
  21. import { ElMessage } from "element-plus";
  22. const app = createApp(App);
  23. /**阻止多次重复点击指令 延时暂定5秒 示例 v-prevdbclick:arg='func' */
  24. const messageToast = () => {
  25. //作为eventListener时, 必须使用外部定义函数
  26. ElMessage.error("5秒内请勿重复点击");
  27. };
  28. const funListener = (el, binding) => {
  29. let time = null;
  30. el.removeEventListener("click", messageToast);
  31. el.addEventListener(
  32. "click",
  33. () => {
  34. binding.value();
  35. el.addEventListener("click", messageToast, false);
  36. time = setTimeout(() => {
  37. clearTimeout(time);
  38. funListener(el, binding);
  39. }, Number(binding.arg) || 5000);
  40. },
  41. {
  42. once: true,
  43. }
  44. );
  45. };
  46. /**
  47. * 对 Date 的扩展,将 Date 转化为指定格式的字符串
  48. * @param {String} fmt 传入一个字符串,根据所传字符串的格式返回转换后特定格式的日期。
  49. * 调用姿势:new Date().formatDate("yyyy-MM-dd hh:mm:ss");
  50. */
  51. Date.prototype.formatDate = function (fmt) {
  52. let o = {
  53. "M+": this.getMonth() + 1, //月份
  54. "d+": this.getDate(), //日
  55. "h+": this.getHours(), //小时
  56. "m+": this.getMinutes(), //分
  57. "s+": this.getSeconds(), //秒
  58. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  59. S: this.getMilliseconds(), //毫秒
  60. };
  61. if (/(y+)/.test(fmt)) {
  62. fmt = fmt.replace(
  63. RegExp.$1,
  64. (this.getFullYear() + "").substr(4 - RegExp.$1.length)
  65. );
  66. }
  67. for (let k in o) {
  68. if (new RegExp("(" + k + ")").test(fmt)) {
  69. fmt = fmt.replace(
  70. RegExp.$1,
  71. RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)
  72. );
  73. }
  74. }
  75. return fmt;
  76. };
  77. app.directive("prevdbclick", {
  78. mounted(el, binding) {
  79. funListener(el, binding);
  80. },
  81. });
  82. for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  83. app.component(key, component);
  84. }
  85. window.__STATICVUE__ = app;
  86. window.__STATICVUE__.use(ElementPlus, { locale });
  87. // 全局修改默认配置,点击空白处不能关闭弹窗
  88. app._context.components.ElDialog["props"].closeOnClickModal.default = false;
  89. window.__STATICVUE__.use(store);
  90. window.__STATICVUE__.use(router);
  91. window.__STATICVUE__.use(animated);
  92. window.__STATICVUE__.config.globalProperties.API = axios; //全局注册
  93. window.__STATICVUE__.config.globalProperties.BASE = basicTool; //全局注册
  94. // window.__STATICVUE__.config.globalProperties.$Cesium = Cesium;
  95. window.__STATICVUE__.mount("#app");