use-config.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { computed, reactive } from "vue";
  2. import { installGlobalVar } from "./use-global-vars";
  3. import { useGlobalResize } from "./use-event";
  4. import { Size } from "@/utils/math";
  5. export type Border = {
  6. color?: string;
  7. opacity: number;
  8. margin: number[] | number;
  9. lineWidth: number;
  10. };
  11. const defLableLineConfig = {
  12. stroke: "#000",
  13. strokeWidth: 1,
  14. opacity: 1,
  15. strokeScaleEnabled: false,
  16. shadowColor: "#fff",
  17. shadowBlur: 3,
  18. shadowOffset: { x: 0, y: 0 },
  19. shadowOpacity: 1,
  20. splitOffset: 80,
  21. showOffset: 20,
  22. fontSize: 12,
  23. splitWidth: 10,
  24. type: 'fix',
  25. showShapeTypes: ['line']
  26. }
  27. export type Config = {
  28. showGrid: boolean;
  29. showLabelLine: boolean;
  30. size: Size | null;
  31. back?: { color?: string; opacity: number };
  32. border?: Border | Border[];
  33. margin?: number | number[];
  34. showCompass: boolean
  35. showComponentSize: boolean
  36. labelLineConfig: typeof defLableLineConfig,
  37. serailAutoGenTable: boolean
  38. };
  39. export const defConfig: Config = {
  40. showGrid: true,
  41. showLabelLine: true,
  42. size: null,
  43. showCompass: false,
  44. showComponentSize: true,
  45. labelLineConfig: defLableLineConfig,
  46. serailAutoGenTable: true
  47. };
  48. export const useConfig = installGlobalVar(() => {
  49. const { setFixSize, size } = useGlobalResize();
  50. return reactive({
  51. ...JSON.parse(JSON.stringify(defConfig)),
  52. size: computed({
  53. get: () => size.value!,
  54. set: (size: Size | null) => {
  55. setFixSize(size)
  56. },
  57. }),
  58. }) as Config ;
  59. });