ColumnItem.tsx 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. import React from "react";
  2. import { HolderOutlined } from "@ant-design/icons";
  3. import {
  4. Button,
  5. Form,
  6. Input,
  7. InputNumber,
  8. Popover,
  9. Row,
  10. Col,
  11. Tooltip,
  12. Select,
  13. } from "antd";
  14. import { ColumnItem as ColumnItemType } from "@/type";
  15. import { DATA_TYPE_OPTIONS } from "@/constants";
  16. import { useSortable } from "@dnd-kit/sortable";
  17. import { CSS } from "@dnd-kit/utilities";
  18. import LangInput from "@/components/LangInput";
  19. import LangInputTextarea from "@/components/LangInputTextarea";
  20. export default function ColumnItem({
  21. column,
  22. onChange,
  23. onDelete,
  24. }: {
  25. column: ColumnItemType;
  26. onChange: (key: string, value: any) => void;
  27. onDelete: (id: string) => void;
  28. }) {
  29. console.log(column);
  30. const { setNodeRef, attributes, listeners, transform, transition } =
  31. useSortable({
  32. id: column.id,
  33. transition: {
  34. duration: 500,
  35. easing: "cubic-bezier(0.25, 1, 0.5, 1)",
  36. },
  37. });
  38. const styles = {
  39. transform: CSS.Transform.toString(transform),
  40. transition,
  41. };
  42. return (
  43. <div
  44. key={column.id}
  45. className="column-item flex gap-4px items-center jutify-space-between hover:bg-gray-100 mb-4px"
  46. style={styles}
  47. ref={setNodeRef}
  48. {...attributes}
  49. data-cypress="draggable-item"
  50. >
  51. <HolderOutlined className="cursor-move" data-cypress="draggable-handle" {...listeners}/>
  52. <Tooltip title="字段编码">
  53. <Input
  54. placeholder="编码"
  55. defaultValue={column.schemaName}
  56. className="flex-1"
  57. onChange={(e) => onChange("schemaName", e.target.value)}
  58. />
  59. </Tooltip>
  60. <Tooltip title="字段类型">
  61. <Select
  62. placeholder="类型"
  63. className="w-80px"
  64. options={DATA_TYPE_OPTIONS}
  65. value={column.type}
  66. onChange={(value) => onChange("type", value)}
  67. dropdownStyle={{ width: 120 }}
  68. />
  69. </Tooltip>
  70. <Tooltip title="非空">
  71. <div
  72. className="
  73. rounded-4px
  74. cus-btn
  75. w-32px
  76. h-32px
  77. bg-#eee
  78. flex-none
  79. text-center
  80. leading-32px
  81. cursor-pointer
  82. hover:bg-#ddd"
  83. style={
  84. column.isRequired ? { background: "#1677ff", color: "#fff" } : {}
  85. }
  86. onClick={() => onChange("isRequired", !column.isRequired)}
  87. >
  88. !
  89. </div>
  90. </Tooltip>
  91. <Tooltip title="唯一">
  92. <div
  93. className="
  94. rounded-4px
  95. cus-btn
  96. w-32px
  97. h-32px
  98. bg-#eee
  99. flex-none
  100. text-center
  101. leading-32px
  102. cursor-pointer
  103. hover:bg-#ddd"
  104. style={
  105. column.isUnique ? { background: "#1677ff", color: "#fff" } : {}
  106. }
  107. onClick={() => onChange("isUnique", !column.isUnique)}
  108. >
  109. 1
  110. </div>
  111. </Tooltip>
  112. <Popover
  113. trigger="click"
  114. placement="right"
  115. content={
  116. <div
  117. className="w-360px max-h-400px overflow-hidden"
  118. onClick={(e) => e.stopPropagation()}
  119. >
  120. <Form layout="vertical">
  121. <Row gutter={8}>
  122. <Col span={12}>
  123. <Form.Item label="字段名称">
  124. <LangInput value="" onChange={() => {}}/>
  125. </Form.Item>
  126. </Col>
  127. <Col span={12}>
  128. <Form.Item label="默认值">
  129. <Input
  130. className="w-full"
  131. placeholder="默认值"
  132. value={column.defaultValue}
  133. onChange={(e) => onChange("defaultValue", e.target.value)}
  134. />
  135. </Form.Item>
  136. </Col>
  137. </Row>
  138. <Row gutter={8}>
  139. <Col span={12}>
  140. <Form.Item label="长度">
  141. <InputNumber
  142. placeholder="请输入"
  143. min={0}
  144. className="w-full"
  145. value={column.maxLength}
  146. onChange={(num) => onChange("maxLength", num)}
  147. />
  148. </Form.Item>
  149. </Col>
  150. <Col span={12}>
  151. <Form.Item label="精度">
  152. <InputNumber
  153. placeholder="请输入"
  154. min={0}
  155. className="w-full"
  156. value={column.precision}
  157. onChange={(num) => onChange("precision", num)}
  158. />
  159. </Form.Item>
  160. </Col>
  161. </Row>
  162. <Row>
  163. <Col span={24}>
  164. <Form.Item label="描述">
  165. <LangInputTextarea value="" onChange={() => {}}/>
  166. </Form.Item>
  167. </Col>
  168. </Row>
  169. </Form>
  170. <Button
  171. type="default"
  172. danger
  173. className="w-full"
  174. onClick={() => onDelete(column.id)}
  175. >
  176. 删除
  177. </Button>
  178. </div>
  179. }
  180. >
  181. <div className="rounded-4px cus-btn w-32px h-32px bg-#eee flex-none text-center leading-32px cursor-pointer hover:bg-#ddd">
  182. <i className="iconfont icon-gengduo" />
  183. </div>
  184. </Popover>
  185. </div>
  186. );
  187. }