setSystem.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import { ref } from "vue";
  2. import { title } from "./store/system";
  3. import { appConstant } from "./app";
  4. import {
  5. caseFileTypes,
  6. caseFiles,
  7. insertCaseFile,
  8. deleteCaseFile,
  9. updateCaseFile,
  10. axios,
  11. caseFileInfo,
  12. saveCaseFileInfo,
  13. getSysSetting,
  14. updateSysSetting,
  15. } from "@/request";
  16. const modules = import.meta.glob("@/assets/style/theme/*.scss", {
  17. query: "?inline",
  18. });
  19. const appId = import.meta.env.VITE_APP_APP
  20. axios.get(getSysSetting, {
  21. params: {
  22. platformKey: appId
  23. }
  24. }).then((data) => {
  25. systemData.value.name = data.data.title;
  26. systemData.value.color = data.data.themeColour;
  27. console.log('获取后台当前色', data.data.themeColour)
  28. localStorage.setItem('f-themeColour', data.data.themeColour)
  29. refresh();
  30. });
  31. const update = () => {
  32. axios.post(updateSysSetting, {
  33. title: systemData.value.name,
  34. themeColour: systemData.value.color,
  35. });
  36. };
  37. export const themeColors = [
  38. "d8000a",
  39. "0960bd",
  40. "0084f4",
  41. "009688",
  42. "536dfe",
  43. "ff5c93",
  44. "ee4f12",
  45. "0096c7",
  46. "9c27b0",
  47. "ff9800",
  48. ];
  49. export const systemData = ref({
  50. name: appConstant.name,
  51. color: themeColors[0],
  52. });
  53. const $style = document.createElement("style");
  54. $style.setAttribute("type", "text/css");
  55. document.body.appendChild($style);
  56. const refresh = async () => {
  57. title.value = systemData.value.name;
  58. const key = Object.keys(modules).find((key) =>
  59. key.includes(systemData.value.color)
  60. );
  61. if (key) {
  62. const res1: any = await modules[key]();
  63. const res2: any = await import("@/assets/style/public.scss?inline");
  64. $style.innerHTML = res1.default + res2.default;
  65. }
  66. };
  67. export const setTheme = async (color: string) => {
  68. systemData.value.color = color;
  69. await update();
  70. refresh();
  71. };
  72. export const setTitle = async (d: string) => {
  73. systemData.value.name = d;
  74. await update();
  75. refresh();
  76. };
  77. export const setSettings = async (title: string, color: string) => {
  78. systemData.value.name = title;
  79. systemData.value.color = color;
  80. await update();
  81. refresh();
  82. };