main.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. // 路由导航守卫
  76. router.beforeEach((to, from, next) => {
  77. if (from.path === "/home/performance/customAnalysis") {
  78. if (to.path !== "/home/performance/luckySheet") {
  79. store.commit("dragChart/clearchart");
  80. }
  81. }
  82. next();
  83. });
  84. // 监听页面刷新或关闭事件
  85. window.addEventListener("beforeunload", () => {
  86. // 调用清空 Vuex 仓库的 Action
  87. store.commit("dragChart/clearchart");
  88. });
  89. new Vue({
  90. router,
  91. store,
  92. mounted() {
  93. this.applyTheme();
  94. },
  95. watch: {
  96. "$store.state.themes.theme": {
  97. handler(newTheme, oldTheme) {
  98. this.applyTheme(newTheme, oldTheme);
  99. },
  100. immediate: true,
  101. },
  102. },
  103. methods: {
  104. async applyTheme(theme, oldTheme) {
  105. const themeFile = theme || this.$store.state.themes.theme;
  106. // 动态加载新的主题样式
  107. try {
  108. // 动态导入 SCSS 文件
  109. const theme = await import(`@/themes/${themeFile}.scss`);
  110. Vue.prototype.$backgroundColor = getComputedStyle(
  111. document.documentElement
  112. ).getPropertyValue("--background-color");
  113. // 移除之前的主题样式
  114. let oldThemeStyle = document.getElementById("theme-style");
  115. if (oldThemeStyle) {
  116. oldThemeStyle.parentNode.removeChild(oldThemeStyle);
  117. }
  118. // 创建新的样式标签并插入到 head 中
  119. const style = document.createElement("style");
  120. style.id = "theme-style";
  121. style.type = "text/css";
  122. style.innerHTML = theme.default;
  123. document.head.appendChild(style);
  124. if (theme !== oldTheme && oldTheme !== undefined) {
  125. this.$router.go(0);
  126. }
  127. } catch (error) {
  128. console.error("Failed to load theme", error);
  129. }
  130. },
  131. },
  132. render: (h) => h(App),
  133. }).$mount("#app");