appModel.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import { Cell } from "@antv/x6";
  2. import { useState } from "react";
  3. interface PageSettings {
  4. // 背景颜色
  5. backgroundColor: string;
  6. // 宽
  7. width: number;
  8. // 高
  9. height: number;
  10. // 显示网格
  11. grid: boolean;
  12. // 网格大小
  13. gridSize: number;
  14. // 显示跨线
  15. jumpover: boolean;
  16. // 显示打印分割线
  17. printLine: boolean;
  18. // 显示水印
  19. watermark: boolean;
  20. // 水印文字
  21. watermarkText: string;
  22. }
  23. export default function appModel() {
  24. const [projectInfo, setProjectInfo] = useState({
  25. name: "新建流程图",
  26. desc: "",
  27. version: "",
  28. author: "",
  29. });
  30. // 隐藏/显示右侧面板
  31. const [showRightPanel, setShowRightPanel] = useState(false);
  32. const [pageState, setPageState] = useState<PageSettings>({
  33. backgroundColor: "transparent",
  34. width: 0,
  35. height: 0,
  36. grid: true,
  37. gridSize: 15,
  38. jumpover: false,
  39. printLine: false,
  40. watermark: false,
  41. watermarkText: "沙鲁低码平台"
  42. });
  43. const [historyColor, setHistoryColor] = useState<string[]>([
  44. '#B0E38F',
  45. '#F19594',
  46. '#EC7270',
  47. '#996A99',
  48. '#4F374F',
  49. '#94E0E1',
  50. '#FBF1B8',
  51. '#E3F0E1',
  52. '#FDF8DC',
  53. '#569230',
  54. ]);
  55. const [enableFormatBrush, setEnableFormatBrush] = useState(false);
  56. const [formatBrushStyle, setFormatBrusStyle] = useState();
  57. // 收折右侧样式面板
  58. const toggleRightPanel = () => {
  59. setShowRightPanel(!showRightPanel);
  60. }
  61. // 处理页面设置
  62. const onChangePageSettings = (key: keyof PageSettings, value: any) => {
  63. console.log(key, value)
  64. setPageState((state) => {
  65. return {
  66. ...state,
  67. [key]: value
  68. }
  69. })
  70. }
  71. /**
  72. * 新增颜色记录
  73. * 添加时,将移除最早的颜色
  74. * @param color 颜色
  75. */
  76. const addHistoryCoolor = (color: string) => {
  77. if( historyColor.includes(color)) return;
  78. setHistoryColor((state) => {
  79. const newState = [...state];
  80. newState.unshift(color);
  81. newState.pop();
  82. return newState;
  83. })
  84. }
  85. // 开启格式刷
  86. const toggleFormatBrush = (cell?: Cell) => {
  87. setEnableFormatBrush((state) => {
  88. if(state) {
  89. const data = cell?.getData();
  90. setFormatBrusStyle(data);
  91. } else {
  92. setFormatBrusStyle(undefined);
  93. }
  94. return !state;
  95. })
  96. }
  97. return {
  98. showRightPanel,
  99. toggleRightPanel,
  100. pageState,
  101. onChangePageSettings,
  102. historyColor,
  103. addHistoryCoolor,
  104. enableFormatBrush,
  105. toggleFormatBrush,
  106. projectInfo,
  107. setProjectInfo,
  108. }
  109. }