main.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import Vue from "vue";
  2. import App from "./App.vue";
  3. import router from "./router";
  4. import { store } from "./store/index.js";
  5. import { getEnvDefaultTheme, ensureDefaultTheme } from "./store/themes.js";
  6. import { applyTheme } from "./utils/theme.js";
  7. // import "./assets/style/element-variables.module.scss";
  8. import "./icons/index"; // icon
  9. import VueRulerTool from "vue-ruler-tool";
  10. // 引入element ui
  11. import ElementUI from "element-ui";
  12. import "element-ui/lib/theme-chalk/index.css";
  13. import "@wangeditor/editor/dist/css/style.css";
  14. // 引入css
  15. import "./styles/index.scss";
  16. // 注册svg组件
  17. import SvgIcons from "@/components/SvgIcons/index.vue";
  18. import VueDraggableResizable from "vue-draggable-resizable-gorkys";
  19. import "vue-draggable-resizable-gorkys/dist/VueDraggableResizable.css";
  20. import "vue-virtual-scroller/dist/vue-virtual-scroller.css";
  21. import VirtualList from "@/components/virtual_list/index.vue";
  22. import ManyVirtualList from "@/components/virtual_list/ManyVirtualList.vue";
  23. Vue.component("VueDraggableResizable", VueDraggableResizable);
  24. Vue.component("SvgIcons", SvgIcons);
  25. Vue.component("vue-ruler-tool", VueRulerTool);
  26. // 序列化post方法
  27. import qs from "qs";
  28. // 将自动注册所有组件为全局组件
  29. import dataV from "@jiaminghi/data-view";
  30. import permission from "./directives/permission"; // 导入自定义指令
  31. import lazyLoad from "./directives/lazyLoad";
  32. import inview from "./directives/inview";
  33. import "echarts-gl";
  34. Vue.use(dataV);
  35. Vue.prototype.$qs = qs;
  36. // Vue.prototype.$tinymce = tinymce;
  37. import { RecycleScroller } from "vue-virtual-scroller";
  38. Vue.component("RecycleScroller", RecycleScroller);
  39. Vue.component("VirtualList", VirtualList);
  40. Vue.component("ManyVirtualList", ManyVirtualList);
  41. Vue.use(ElementUI);
  42. // 引入tailwind
  43. // https://www.tailwindcss.cn/docs/installation
  44. Vue.prototype.$BASE_URL = window?._BASE_CONFIG?.API;
  45. Vue.config.productionTip = false;
  46. if (store.state.auth.userInfo.permission !== undefined) {
  47. store.dispatch("auth/setAddRouter", {
  48. resultRouter:
  49. (store.state.auth.userInfo && store.state.auth.userInfo.permission) || [],
  50. router,
  51. });
  52. }
  53. //开始结束时间转换
  54. Vue.prototype.$formatDate = function (date) {
  55. const year = date.getFullYear();
  56. const month = (date.getMonth() + 1).toString().padStart(2, "0"); // Adding 1 to month since it's zero-based
  57. const day = date.getDate().toString().padStart(2, "0");
  58. return `${year}-${month}-${day}`;
  59. };
  60. Vue.directive("lazy-load", lazyLoad);
  61. Vue.directive("hasPermi", permission);
  62. Vue.directive("inview", inview);
  63. // 时间戳转换
  64. Vue.prototype.$formatDateTWO = function (timestamp) {
  65. const date = new Date(timestamp);
  66. const year = date.getFullYear();
  67. const month = String(date.getMonth() + 1).padStart(2, "0");
  68. const day = String(date.getDate()).padStart(2, "0");
  69. const hours = String(date.getHours()).padStart(2, "0");
  70. const minutes = String(date.getMinutes()).padStart(2, "0");
  71. // const seconds = String(date.getSeconds()).padStart(2, "0");:${seconds}
  72. return `${year}-${month}-${day} ${hours}:${minutes}`;
  73. };
  74. Vue.directive("number-only", {
  75. bind(el) {
  76. el.addEventListener("input", (e) => {
  77. // 正则表达式:允许数字和最多一个小数点
  78. let inputVal = e.target.value;
  79. const regex = /^\d*\.?\d*$/;
  80. // 如果不符合格式,移除不合法字符
  81. if (!regex.test(inputVal)) {
  82. inputVal = inputVal.replace(/[^\d.]/g, ""); // 移除非数字和小数点的字符
  83. }
  84. // 防止多个小数点
  85. const parts = inputVal.split(".");
  86. if (parts.length > 2) {
  87. inputVal = parts[0] + "." + parts[1]; // 只保留第一个小数点及其后面的部分
  88. }
  89. // 更新输入框的值
  90. e.target.value = inputVal;
  91. });
  92. },
  93. });
  94. // man.js
  95. // 注册 convertDMSToDecimal 方法
  96. Vue.prototype.$convertDMSToDecimal = function (dms) {
  97. const dmsRegex = /^([+-]?\d{1,3})°(\d{1,2})′(\d{1,2})″$/;
  98. const match = dms.match(dmsRegex);
  99. if (match) {
  100. const degrees = parseInt(match[1], 10);
  101. const minutes = parseInt(match[2], 10);
  102. const seconds = parseInt(match[3], 10);
  103. // 使用公式进行转换
  104. return degrees + minutes / 60 + seconds / 3600;
  105. }
  106. return null; // 如果格式不正确,返回null
  107. };
  108. ensureDefaultTheme(store);
  109. applyTheme(store.state.themes.theme || getEnvDefaultTheme());
  110. new Vue({
  111. router,
  112. store,
  113. watch: {
  114. "$store.state.themes.theme": {
  115. handler(newTheme, oldTheme) {
  116. if (!newTheme || newTheme === oldTheme) return;
  117. applyTheme(newTheme, oldTheme);
  118. },
  119. },
  120. },
  121. render: (h) => h(App),
  122. }).$mount("#app");