main.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 "./assets/style/element-variables.module.scss";
  6. import "./icons/index"; // icon
  7. import VueRulerTool from "vue-ruler-tool";
  8. // 引入element ui
  9. import ElementUI from "element-ui";
  10. import "element-ui/lib/theme-chalk/index.css";
  11. import "@wangeditor/editor/dist/css/style.css";
  12. // 引入css
  13. import "./styles/index.scss";
  14. // 注册svg组件
  15. import SvgIcons from "@/components/SvgIcons/index.vue";
  16. import VueDraggableResizable from "vue-draggable-resizable-gorkys";
  17. import "vue-draggable-resizable-gorkys/dist/VueDraggableResizable.css";
  18. import "vue-virtual-scroller/dist/vue-virtual-scroller.css";
  19. import VirtualList from "@/components/virtual_list/index.vue";
  20. import ManyVirtualList from "@/components/virtual_list/ManyVirtualList.vue";
  21. Vue.component("VueDraggableResizable", VueDraggableResizable);
  22. Vue.component("SvgIcons", SvgIcons);
  23. Vue.component("vue-ruler-tool", VueRulerTool);
  24. // 序列化post方法
  25. import qs from "qs";
  26. // 将自动注册所有组件为全局组件
  27. import dataV from "@jiaminghi/data-view";
  28. import permission from "./directives/permission"; // 导入自定义指令
  29. import lazyLoad from "./directives/lazyLoad";
  30. import inview from "./directives/inview";
  31. import "echarts-gl";
  32. Vue.use(dataV);
  33. Vue.prototype.$qs = qs;
  34. // Vue.prototype.$tinymce = tinymce;
  35. // dialog拖拽全屏
  36. import dialogDrag from "./views/health/dialogDrag";
  37. import { RecycleScroller } from "vue-virtual-scroller";
  38. Vue.directive("dialogDrag", dialogDrag);
  39. Vue.component("RecycleScroller", RecycleScroller);
  40. Vue.component("VirtualList", VirtualList);
  41. Vue.component("ManyVirtualList", ManyVirtualList);
  42. Vue.use(ElementUI);
  43. // 引入tailwind
  44. // https://www.tailwindcss.cn/docs/installation
  45. Vue.prototype.$BASE_URL = window?._BASE_CONFIG?.API;
  46. Vue.config.productionTip = false;
  47. if (store.state.auth.userInfo.permission !== undefined) {
  48. store.dispatch("auth/setAddRouter", {
  49. resultRouter:
  50. (store.state.auth.userInfo && store.state.auth.userInfo.permission) || [],
  51. router,
  52. });
  53. }
  54. //开始结束时间转换
  55. Vue.prototype.$formatDate = function (date) {
  56. const year = date.getFullYear();
  57. const month = (date.getMonth() + 1).toString().padStart(2, "0"); // Adding 1 to month since it's zero-based
  58. const day = date.getDate().toString().padStart(2, "0");
  59. return `${year}-${month}-${day}`;
  60. };
  61. Vue.directive("lazy-load", lazyLoad);
  62. Vue.directive("hasPermi", permission);
  63. Vue.directive("inview", inview);
  64. // 时间戳转换
  65. Vue.prototype.$formatDateTWO = function (timestamp) {
  66. const date = new Date(timestamp);
  67. const year = date.getFullYear();
  68. const month = String(date.getMonth() + 1).padStart(2, "0");
  69. const day = String(date.getDate()).padStart(2, "0");
  70. const hours = String(date.getHours()).padStart(2, "0");
  71. const minutes = String(date.getMinutes()).padStart(2, "0");
  72. // const seconds = String(date.getSeconds()).padStart(2, "0");:${seconds}
  73. return `${year}-${month}-${day} ${hours}:${minutes}`;
  74. };
  75. Vue.directive("number-only", {
  76. bind(el) {
  77. el.addEventListener("input", (e) => {
  78. // 正则表达式:允许数字和最多一个小数点
  79. let inputVal = e.target.value;
  80. const regex = /^\d*\.?\d*$/;
  81. // 如果不符合格式,移除不合法字符
  82. if (!regex.test(inputVal)) {
  83. inputVal = inputVal.replace(/[^\d.]/g, ""); // 移除非数字和小数点的字符
  84. }
  85. // 防止多个小数点
  86. const parts = inputVal.split(".");
  87. if (parts.length > 2) {
  88. inputVal = parts[0] + "." + parts[1]; // 只保留第一个小数点及其后面的部分
  89. }
  90. // 更新输入框的值
  91. e.target.value = inputVal;
  92. });
  93. },
  94. });
  95. // man.js
  96. // 注册 convertDMSToDecimal 方法
  97. Vue.prototype.$convertDMSToDecimal = function (dms) {
  98. const dmsRegex = /^([+-]?\d{1,3})°(\d{1,2})′(\d{1,2})″$/;
  99. const match = dms.match(dmsRegex);
  100. if (match) {
  101. const degrees = parseInt(match[1], 10);
  102. const minutes = parseInt(match[2], 10);
  103. const seconds = parseInt(match[3], 10);
  104. // 使用公式进行转换
  105. return degrees + minutes / 60 + seconds / 3600;
  106. }
  107. return null; // 如果格式不正确,返回null
  108. };
  109. // 路由导航守卫
  110. router.beforeEach((to, from, next) => {
  111. if (from.path === "/home/performance/customAnalysis") {
  112. if (to.path !== "/home/performance/luckySheet") {
  113. store.commit("dragChart/clearchart");
  114. }
  115. }
  116. next();
  117. });
  118. // 监听页面刷新或关闭事件
  119. window.addEventListener("beforeunload", () => {
  120. // 调用清空 Vuex 仓库的 Action
  121. store.commit("dragChart/clearchart");
  122. });
  123. new Vue({
  124. router,
  125. store,
  126. mounted() {
  127. this.applyTheme();
  128. },
  129. watch: {
  130. "$store.state.themes.theme": {
  131. handler(newTheme, oldTheme) {
  132. this.applyTheme(newTheme, oldTheme);
  133. },
  134. immediate: true,
  135. },
  136. },
  137. methods: {
  138. async applyTheme(theme, oldTheme) {
  139. const themeFile = theme || this.$store.state.themes.theme;
  140. // 动态加载新的主题样式
  141. try {
  142. // 动态导入 SCSS 文件
  143. const theme = await import(`@/themes/${themeFile}.scss`);
  144. Vue.prototype.$backgroundColor = getComputedStyle(
  145. document.documentElement
  146. ).getPropertyValue("--background-color");
  147. // 移除之前的主题样式
  148. let oldThemeStyle = document.getElementById("theme-style");
  149. if (oldThemeStyle) {
  150. oldThemeStyle.parentNode.removeChild(oldThemeStyle);
  151. }
  152. // 创建新的样式标签并插入到 head 中
  153. const style = document.createElement("style");
  154. style.id = "theme-style";
  155. style.type = "text/css";
  156. style.innerHTML = theme.default;
  157. document.head.appendChild(style);
  158. if (theme !== oldTheme && oldTheme !== undefined) {
  159. this.$router.go(0);
  160. }
  161. } catch (error) {
  162. console.error("Failed to load theme", error);
  163. }
  164. },
  165. },
  166. render: (h) => h(App),
  167. }).$mount("#app");