Commit fb822c9b1e8d5cb0953782be3b2e42ad9e2772ac
1 parent
e10685e9
优化 人事通用组件-可编辑表格,展示交互;
Showing
1 changed file
with
30 additions
and
8 deletions
src/pages/ehr/components/EditTable.tsx
... | ... | @@ -5,10 +5,11 @@ import { |
5 | 5 | FormInstance, |
6 | 6 | Input, |
7 | 7 | InputRef, |
8 | + Popover, | |
8 | 9 | Table, |
9 | 10 | TableProps, |
10 | 11 | } from "antd"; |
11 | -import { EditOutlined } from "@ant-design/icons"; | |
12 | +import { EditOutlined, ExclamationCircleFilled } from "@ant-design/icons"; | |
12 | 13 | import React, { useContext, useEffect, useMemo, useRef, useState } from "react"; |
13 | 14 | import { Rule, RuleObject } from "antd/lib/form"; |
14 | 15 | import { StoreValue } from "antd/lib/form/interface"; |
... | ... | @@ -122,7 +123,7 @@ export default function EditTable<T>({ |
122 | 123 | useEffect(() => { |
123 | 124 | if (edit) { |
124 | 125 | form.setFieldsValue({ |
125 | - [dataIndex]: record?.[dataIndex] ?? '', | |
126 | + [dataIndex]: record?.[dataIndex] ?? "", | |
126 | 127 | }); |
127 | 128 | } |
128 | 129 | }, []); |
... | ... | @@ -147,10 +148,12 @@ export default function EditTable<T>({ |
147 | 148 | |
148 | 149 | const save = async (e: any) => { |
149 | 150 | try { |
150 | - e.preventDefault(); | |
151 | - const values = await form.validateFields(); | |
152 | - toggleEdit(); | |
153 | - handleSave({ ...record, ...values }); | |
151 | + if (!e.shiftKey) { | |
152 | + e.preventDefault(); | |
153 | + const values = await form.validateFields(); | |
154 | + toggleEdit(); | |
155 | + handleSave({ ...record, [dataIndex]: (values?.[dataIndex] as string)?.trim() }); | |
156 | + } | |
154 | 157 | } catch (errInfo) { |
155 | 158 | console.log("Save failed:", errInfo); |
156 | 159 | } |
... | ... | @@ -207,6 +210,7 @@ export default function EditTable<T>({ |
207 | 210 | ref={inputRef} |
208 | 211 | allowClear |
209 | 212 | maxLength={maxLength} |
213 | + autoSize={{ minRows: 2 }} | |
210 | 214 | // showCount={!!maxLength} |
211 | 215 | onPressEnter={save} |
212 | 216 | onBlur={save} |
... | ... | @@ -222,7 +226,7 @@ export default function EditTable<T>({ |
222 | 226 | onFocus={() => { |
223 | 227 | inputType === "number" && |
224 | 228 | form.setFieldsValue({ |
225 | - [dataIndex]: `${record?.[dataIndex] ?? ''}`?.replace( | |
229 | + [dataIndex]: `${record?.[dataIndex] ?? ""}`?.replace( | |
226 | 230 | /^0+/g, |
227 | 231 | "" |
228 | 232 | ), |
... | ... | @@ -250,7 +254,11 @@ export default function EditTable<T>({ |
250 | 254 | ) : ( |
251 | 255 | <div |
252 | 256 | className="editable-cell-value-wrap" |
253 | - style={{ paddingRight: 24, cursor: "pointer" }} | |
257 | + style={{ | |
258 | + paddingRight: 24, | |
259 | + cursor: "pointer", | |
260 | + whiteSpace: "pre-wrap", | |
261 | + }} | |
254 | 262 | onClick={(e) => { |
255 | 263 | e.stopPropagation(); |
256 | 264 | toggleEdit(); |
... | ... | @@ -297,6 +305,20 @@ export default function EditTable<T>({ |
297 | 305 | } |
298 | 306 | return { |
299 | 307 | ...col, |
308 | + title: | |
309 | + col.editable && col.inputType === "text" ? ( | |
310 | + <> | |
311 | + {col.title} | |
312 | + <Popover | |
313 | + // trigger="" | |
314 | + content="在输入时,如需输入回车换行,请同时按下(Shfit + Enter)键进行换行输入" | |
315 | + > | |
316 | + <ExclamationCircleFilled /> | |
317 | + </Popover> | |
318 | + </> | |
319 | + ) : ( | |
320 | + col.title | |
321 | + ), | |
300 | 322 | onCell: (record: T) => ({ |
301 | 323 | record, |
302 | 324 | ...col, | ... | ... |