RemarkPanel.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import { DeleteOutlined, SearchOutlined } from "@ant-design/icons";
  2. import { Button, Input, Form, Popconfirm } from "antd";
  3. import React, { useState } from "react";
  4. import CustomColorPicker from "@/components/CustomColorPicker";
  5. import { useModel } from "umi";
  6. import noData from "@/assets/no-data.png";
  7. export default function RemarkPanel() {
  8. const { project, addRemark, deleteRemark, updateRemark } =
  9. useModel("erModel");
  10. const { remarks = [] } = project;
  11. const [search, setSearch] = React.useState("");
  12. const [activeKey, setActiveKey] = React.useState("");
  13. const list = React.useMemo(() => {
  14. return remarks.filter((item) => item.name.includes(search));
  15. }, [search, remarks]);
  16. const handleChange = (index: number, key: string, value: any) => {
  17. const data = remarks[index];
  18. updateRemark({
  19. ...data,
  20. [key]: value,
  21. });
  22. };
  23. return (
  24. <div className="px-12px">
  25. <div className="flex gap-12px">
  26. <Input
  27. placeholder="输入关键字搜索"
  28. className="m-b-10px"
  29. suffix={<SearchOutlined />}
  30. value={search}
  31. onChange={(e) => setSearch(e.target.value)}
  32. />
  33. <Button type="primary" onClick={addRemark}>
  34. 添加注释
  35. </Button>
  36. </div>
  37. {list.map((item, index) => {
  38. return (
  39. <div
  40. key={item.id}
  41. className="
  42. border-b-solid
  43. border-b-[#e4e4e4]
  44. border-b-[1px]"
  45. >
  46. <div
  47. className="
  48. header
  49. flex
  50. items-center
  51. justify-between
  52. leading-[40px]
  53. hover:bg-[#fafafa]
  54. cursor-pointer
  55. m-b-[10px]"
  56. onClick={() => setActiveKey(activeKey === item.id ? "" : item.id)}
  57. >
  58. <div className="font-bold truncate">{item.name}</div>
  59. <div>
  60. <i className="iconfont icon-open m-r-10px" />
  61. </div>
  62. </div>
  63. <div
  64. className="content overflow-hidden grid"
  65. style={{
  66. gridTemplateRows: activeKey === item.id ? "1fr" : "0fr",
  67. transition: "all 0.3s",
  68. }}
  69. >
  70. <Form layout="vertical" className="overflow-hidden">
  71. <Form.Item label="标题" layout="vertical">
  72. <Input
  73. placeholder="请输入"
  74. value={item.name}
  75. onChange={(e) =>
  76. handleChange(index, "name", e.target.value)
  77. }
  78. />
  79. </Form.Item>
  80. <Form.Item label="" layout="vertical" wrapperCol={{ span: 24 }}>
  81. <div className="flex gap-12px">
  82. <Input.TextArea
  83. placeholder="内容"
  84. autoSize={false}
  85. style={{ resize: "none" }}
  86. value={item.text}
  87. onChange={(e) =>
  88. handleChange(index, "text", e.target.value)
  89. }
  90. />
  91. <div>
  92. <CustomColorPicker
  93. color={item.style.background}
  94. onChange={(color) => {
  95. handleChange(index, "style", {
  96. ...item.style,
  97. background: color,
  98. });
  99. }}
  100. >
  101. <div
  102. className="rounded-4px cus-btn w-32px h-32px bg-#eee flex-none cursor-pointer shadow-inner"
  103. style={{ background: item.style.background }}
  104. ></div>
  105. </CustomColorPicker>
  106. <Popconfirm
  107. okType="primary"
  108. title="确定删除该注释?"
  109. okText="确定"
  110. cancelText="取消"
  111. onConfirm={() => deleteRemark(item.id)}
  112. >
  113. <div className="rounded-4px cus-btn w-32px h-32px bg-#eee flex-none cursor-pointer text-center leading-32px color-red">
  114. <DeleteOutlined />
  115. </div>
  116. </Popconfirm>
  117. </div>
  118. </div>
  119. </Form.Item>
  120. </Form>
  121. </div>
  122. </div>
  123. );
  124. })}
  125. {list.length === 0 && (
  126. <div className="flex flex-col items-center justify-center h-[300px]">
  127. <img src={noData} alt="暂无数据" className="w-[200px] h-[200px]" />
  128. <div className="text-gray-400">添加额外注释内容!</div>
  129. </div>
  130. )}
  131. </div>
  132. );
  133. }