main.js 2.9 KB

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