setSystem.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. axios.get(getSysSetting).then((data) => {
  18. systemData.value.name = data.data.title;
  19. systemData.value.color = data.data.themeColour;
  20. refresh();
  21. });
  22. const update = () => {
  23. axios.post(updateSysSetting, {
  24. title: systemData.value.name,
  25. themeColour: systemData.value.color,
  26. });
  27. };
  28. export const themeColors = [
  29. "0960bd",
  30. "0084f4",
  31. "009688",
  32. "536dfe",
  33. "ff5c93",
  34. "ee4f12",
  35. "0096c7",
  36. "9c27b0",
  37. "ff9800",
  38. ];
  39. export const systemData = ref({
  40. name: appConstant.name,
  41. color: themeColors[0],
  42. });
  43. const refresh = () => {
  44. title.value = systemData.value.name;
  45. const key = Object.keys(modules).find((key) =>
  46. key.includes(systemData.value.color)
  47. );
  48. if (key) {
  49. return modules[key]();
  50. } else {
  51. return Promise.resolve();
  52. }
  53. };
  54. export const setTheme = async (color: string) => {
  55. systemData.value.color = color;
  56. await update();
  57. refresh();
  58. };
  59. export const setTitle = async (d: string) => {
  60. systemData.value.name = d;
  61. await update();
  62. refresh();
  63. };