kts-component-invoice-operate 3.2.257 → 3.2.259
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Invoice/Invoice-digtal/_test/passenger/index.d.ts +4 -0
- package/dist/Invoice/InvoiceController/InvoiceControllerState/PassengerListState/IColumnsReplenish/index.d.ts +6 -0
- package/dist/Invoice/InvoiceController/InvoiceControllerState/PassengerListState/IGood/index.d.ts +24 -0
- package/dist/Invoice/InvoiceController/InvoiceControllerState/PassengerListState/index.d.ts +44 -0
- package/dist/Invoice/InvoiceController/InvoiceControllerState/index.d.ts +5 -0
- package/dist/Invoice/InvoiceController/fns/addPassenger.d.ts +6 -0
- package/dist/Invoice/InvoiceController/fns/delPassenger.d.ts +6 -0
- package/dist/Invoice/InvoiceController/fns/saveEditPassenger.d.ts +6 -0
- package/dist/Invoice/InvoiceController/fns/setEditPassenger.d.ts +6 -0
- package/dist/Invoice/InvoiceController/index.d.ts +12 -0
- package/dist/Invoice/index.d.ts +2 -0
- package/dist/Invoice/ui/components/CustomCascader/index.d.ts +20 -0
- package/dist/Invoice/ui/default/ImportPassengerDrawer/index.d.ts +3 -0
- package/dist/Invoice/ui/digtal/PassengerList/hook/useColumns/index.d.ts +3 -0
- package/dist/Invoice/ui/digtal/PassengerList/hook/useColumns/ui/TitleText/index.d.ts +8 -0
- package/dist/Invoice/ui/digtal/PassengerList/hook/useOnRow/index.d.ts +8 -0
- package/dist/Invoice/ui/digtal/PassengerList/hook/useRowSelection/index.d.ts +8 -0
- package/dist/Invoice/ui/digtal/PassengerList/hook/useWindowClick/index.d.ts +8 -0
- package/dist/Invoice/ui/digtal/PassengerList/index.d.ts +18 -0
- package/dist/Invoice/ui/digtal/PassengerList/ui/AddRowButton/index.d.ts +3 -0
- package/dist/Invoice/ui/digtal/PassengerList/ui/BatchImportButton/index.d.ts +3 -0
- package/dist/Invoice/ui/digtal/PassengerList/ui/BulkMenu/hooks/useDelRowButton/index.d.ts +6 -0
- package/dist/Invoice/ui/digtal/PassengerList/ui/BulkMenu/hooks/useEmptyRefill/index.d.ts +6 -0
- package/dist/Invoice/ui/digtal/PassengerList/ui/TableRow/index.d.ts +3 -0
- package/dist/Invoice/ui/digtal/PassengerList/ui/TableVirtual/index.d.ts +4 -0
- package/dist/Invoice/ui/digtal/Stakeholder/index.d.ts +2 -0
- package/dist/index.esm.js +3501 -45
- package/dist/index.js +3491 -35
- package/package.json +1 -1
- package/src/Invoice/Invoice-digtal/_test/freight/index.tsx +12 -0
- package/src/Invoice/Invoice-digtal/_test/passenger/index.tsx +14602 -0
- package/src/Invoice/Invoice-digtal/index.md +3 -0
- package/src/Invoice/InvoiceController/InvoiceControllerForm/index.ts +11 -0
- package/src/Invoice/InvoiceController/InvoiceControllerState/PassengerListState/IColumnsReplenish/index.ts +10 -0
- package/src/Invoice/InvoiceController/InvoiceControllerState/PassengerListState/IGood/index.ts +34 -0
- package/src/Invoice/InvoiceController/InvoiceControllerState/PassengerListState/index.ts +179 -0
- package/src/Invoice/InvoiceController/InvoiceControllerState/index.ts +8 -2
- package/src/Invoice/InvoiceController/fns/addPassenger.ts +11 -0
- package/src/Invoice/InvoiceController/fns/delPassenger.ts +38 -0
- package/src/Invoice/InvoiceController/fns/saveEditPassenger.ts +24 -0
- package/src/Invoice/InvoiceController/fns/setEditPassenger.ts +16 -0
- package/src/Invoice/InvoiceController/index.ts +23 -1
- package/src/Invoice/index.tsx +5 -0
- package/src/Invoice/ui/components/CustomCascader/index.tsx +356 -0
- package/src/Invoice/ui/default/ImportPassengerDrawer/index.tsx +214 -0
- package/src/Invoice/ui/digtal/PassengerList/hook/useColumns/index.tsx +428 -0
- package/src/Invoice/ui/digtal/PassengerList/hook/useColumns/ui/TitleText/index.tsx +20 -0
- package/src/Invoice/ui/digtal/PassengerList/hook/useOnRow/index.tsx +37 -0
- package/src/Invoice/ui/digtal/PassengerList/hook/useRowSelection/index.tsx +120 -0
- package/src/Invoice/ui/digtal/PassengerList/hook/useWindowClick/index.tsx +23 -0
- package/src/Invoice/ui/digtal/PassengerList/index.less +73 -0
- package/src/Invoice/ui/digtal/PassengerList/index.tsx +152 -0
- package/src/Invoice/ui/digtal/PassengerList/ui/AddRowButton/index.tsx +75 -0
- package/src/Invoice/ui/digtal/PassengerList/ui/BatchImportButton/index.tsx +74 -0
- package/src/Invoice/ui/digtal/PassengerList/ui/BulkMenu/hooks/useDelRowButton/index.tsx +50 -0
- package/src/Invoice/ui/digtal/PassengerList/ui/BulkMenu/hooks/useEmptyRefill/index.tsx +37 -0
- package/src/Invoice/ui/digtal/PassengerList/ui/TableRow/index.less +29 -0
- package/src/Invoice/ui/digtal/PassengerList/ui/TableRow/index.tsx +21 -0
- package/src/Invoice/ui/digtal/PassengerList/ui/TableVirtual/index.less +39 -0
- package/src/Invoice/ui/digtal/PassengerList/ui/TableVirtual/index.tsx +109 -0
- package/src/Invoice/ui/digtal/Stakeholder/index.tsx +22 -17
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
useState,
|
|
3
|
+
useCallback,
|
|
4
|
+
useEffect,
|
|
5
|
+
useRef,
|
|
6
|
+
forwardRef,
|
|
7
|
+
useImperativeHandle,
|
|
8
|
+
} from 'react';
|
|
9
|
+
import { Cascader, Input, Space, Button } from 'kts-xui';
|
|
10
|
+
import type { CascaderProps } from 'kts-components-antd-x4/es/cascader';
|
|
11
|
+
import { DownOutlined, CloseOutlined } from '@ant-design/icons';
|
|
12
|
+
|
|
13
|
+
export interface CustomCascaderOption {
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface CustomCascaderFieldNames {
|
|
18
|
+
label?: string;
|
|
19
|
+
value?: string;
|
|
20
|
+
children?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface CustomCascaderProps
|
|
24
|
+
extends Omit<
|
|
25
|
+
CascaderProps<CustomCascaderOption>,
|
|
26
|
+
'value' | 'onChange' | 'options' | 'open' | 'onDropdownVisibleChange' | 'fieldNames' | 'getPopupContainer'
|
|
27
|
+
> {
|
|
28
|
+
options?: CustomCascaderOption[];
|
|
29
|
+
fieldNames?: CustomCascaderFieldNames;
|
|
30
|
+
placeholder?: string;
|
|
31
|
+
onChange?: (value: (string | number)[] | undefined, selectedOptions?: CustomCascaderOption[]) => void;
|
|
32
|
+
value?: (string | number)[];
|
|
33
|
+
onBlur?: (e: React.FocusEvent) => void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const DROPDOWN_CLASS = 'custom-cascader-dropdown';
|
|
37
|
+
const ARROW_CLASS = 'custom-cascader-arrow';
|
|
38
|
+
const CLEAR_CLASS = 'custom-cascader-clear';
|
|
39
|
+
|
|
40
|
+
const CustomCascader = forwardRef<any, CustomCascaderProps>(
|
|
41
|
+
(
|
|
42
|
+
{
|
|
43
|
+
options = [],
|
|
44
|
+
fieldNames = { label: 'label', value: 'value', children: 'children' },
|
|
45
|
+
placeholder = '请选择或输入地址',
|
|
46
|
+
onChange,
|
|
47
|
+
value: externalValue,
|
|
48
|
+
className = '',
|
|
49
|
+
style = {},
|
|
50
|
+
onBlur: onBlurProp,
|
|
51
|
+
...restProps
|
|
52
|
+
},
|
|
53
|
+
ref
|
|
54
|
+
) => {
|
|
55
|
+
const [open, setOpen] = useState<boolean>(false);
|
|
56
|
+
const [inputText, setInputText] = useState<string>('');
|
|
57
|
+
const isComposingRef = useRef<boolean>(false);
|
|
58
|
+
const inputRef = useRef<any>(null);
|
|
59
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
60
|
+
const blurTimerRef = useRef<any>(null);
|
|
61
|
+
const isMenuClickRef = useRef<boolean>(false);
|
|
62
|
+
const preventOpenRef = useRef<boolean>(false);
|
|
63
|
+
|
|
64
|
+
const labelKey = fieldNames.label || 'label';
|
|
65
|
+
const valueKey = fieldNames.value || 'value';
|
|
66
|
+
const childrenKey = fieldNames.children || 'children';
|
|
67
|
+
|
|
68
|
+
// ---------- 工具函数 ----------
|
|
69
|
+
const getPathLabel = useCallback(
|
|
70
|
+
(val: (string | number)[] | undefined): string => {
|
|
71
|
+
if (!val || val.length === 0) return '';
|
|
72
|
+
let current = options;
|
|
73
|
+
const labels: string[] = [];
|
|
74
|
+
for (const v of val) {
|
|
75
|
+
const found = current.find((node) => node[valueKey] === v);
|
|
76
|
+
if (!found) break;
|
|
77
|
+
labels.push(found[labelKey]?.toString() || '');
|
|
78
|
+
current = found[childrenKey] || [];
|
|
79
|
+
}
|
|
80
|
+
return labels.length === val.length ? labels.join('') : val[val.length - 1].toString();
|
|
81
|
+
},
|
|
82
|
+
[options, valueKey, labelKey, childrenKey]
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
const findInTree = useCallback(
|
|
86
|
+
(searchVal: string, nodes: CustomCascaderOption[]): boolean => {
|
|
87
|
+
if (!searchVal || !nodes) return false;
|
|
88
|
+
for (const node of nodes) {
|
|
89
|
+
const nodeLabel = node[labelKey]?.toString() || '';
|
|
90
|
+
if (nodeLabel === searchVal) return true;
|
|
91
|
+
if (node[childrenKey] && findInTree(searchVal, node[childrenKey])) return true;
|
|
92
|
+
}
|
|
93
|
+
return false;
|
|
94
|
+
},
|
|
95
|
+
[labelKey, childrenKey]
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
// ---------- 同步外部值 ----------
|
|
99
|
+
useEffect(() => {
|
|
100
|
+
if (externalValue && externalValue.length > 0) {
|
|
101
|
+
const pathLabel = getPathLabel(externalValue);
|
|
102
|
+
setInputText(pathLabel);
|
|
103
|
+
} else {
|
|
104
|
+
setInputText('');
|
|
105
|
+
}
|
|
106
|
+
}, [externalValue, getPathLabel]);
|
|
107
|
+
|
|
108
|
+
// ---------- 清理定时器 ----------
|
|
109
|
+
useEffect(() => {
|
|
110
|
+
return () => {
|
|
111
|
+
if (blurTimerRef.current) clearTimeout(blurTimerRef.current);
|
|
112
|
+
};
|
|
113
|
+
}, []);
|
|
114
|
+
|
|
115
|
+
// ---------- 核心逻辑 ----------
|
|
116
|
+
const processText = useCallback(
|
|
117
|
+
(text: string) => {
|
|
118
|
+
if (!text.trim()) {
|
|
119
|
+
onChange?.(undefined, []);
|
|
120
|
+
setOpen(false);
|
|
121
|
+
} else {
|
|
122
|
+
const matched = findInTree(text, options);
|
|
123
|
+
const newValue: (string | number)[] = [text];
|
|
124
|
+
onChange?.(newValue, [{ [labelKey]: text, [valueKey]: text, isCustom: true }]);
|
|
125
|
+
setOpen(matched);
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
[options, findInTree, labelKey, valueKey, onChange]
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
// ---------- 全局 mousedown 监听 ----------
|
|
132
|
+
useEffect(() => {
|
|
133
|
+
const handleMouseDown = (e: MouseEvent) => {
|
|
134
|
+
const target = e.target as HTMLElement;
|
|
135
|
+
const container = containerRef.current;
|
|
136
|
+
if (!container) return;
|
|
137
|
+
|
|
138
|
+
const inputElement = inputRef.current?.input;
|
|
139
|
+
const hasFocus = inputElement && document.activeElement === inputElement;
|
|
140
|
+
|
|
141
|
+
// 检查是否点击在级联菜单内
|
|
142
|
+
const isMenu = target.closest?.(`.${DROPDOWN_CLASS}`);
|
|
143
|
+
if (isMenu) {
|
|
144
|
+
isMenuClickRef.current = true;
|
|
145
|
+
if (hasFocus) {
|
|
146
|
+
requestAnimationFrame(() => {
|
|
147
|
+
inputRef.current?.focus();
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// 检查是否点击在自定义内部元素(箭头、清除按钮)
|
|
154
|
+
const isInternal = target.closest?.(`.${ARROW_CLASS}, .${CLEAR_CLASS}`);
|
|
155
|
+
if (isInternal) {
|
|
156
|
+
// 如果是箭头,允许 toggleOpen 处理,不干预焦点
|
|
157
|
+
// 如果是清除,也不干预
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
isMenuClickRef.current = false;
|
|
162
|
+
|
|
163
|
+
if (container.contains(target)) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (hasFocus) {
|
|
168
|
+
if (blurTimerRef.current) clearTimeout(blurTimerRef.current);
|
|
169
|
+
blurTimerRef.current = setTimeout(() => {
|
|
170
|
+
if (inputElement && document.activeElement === inputElement) {
|
|
171
|
+
inputRef.current?.blur();
|
|
172
|
+
}
|
|
173
|
+
blurTimerRef.current = null;
|
|
174
|
+
}, 0);
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
document.addEventListener('mousedown', handleMouseDown);
|
|
179
|
+
return () => {
|
|
180
|
+
document.removeEventListener('mousedown', handleMouseDown);
|
|
181
|
+
};
|
|
182
|
+
}, []);
|
|
183
|
+
|
|
184
|
+
// ---------- 事件处理 ----------
|
|
185
|
+
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
186
|
+
const text = e.target.value;
|
|
187
|
+
setInputText(text);
|
|
188
|
+
if (isComposingRef.current) return;
|
|
189
|
+
processText(text);
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
const handleCompositionStart = () => {
|
|
193
|
+
isComposingRef.current = true;
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const handleCompositionEnd = (e: React.CompositionEvent<HTMLInputElement>) => {
|
|
197
|
+
isComposingRef.current = false;
|
|
198
|
+
const text = (e.target as HTMLInputElement).value;
|
|
199
|
+
processText(text);
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const handleInputFocus = () => {
|
|
203
|
+
if (preventOpenRef.current) {
|
|
204
|
+
preventOpenRef.current = false;
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
setOpen(true);
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
const handleInputBlur = (e: React.FocusEvent<HTMLInputElement>) => {
|
|
211
|
+
if (isMenuClickRef.current) {
|
|
212
|
+
isMenuClickRef.current = false;
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const relatedTarget = e.relatedTarget as HTMLElement | null;
|
|
217
|
+
if (relatedTarget) {
|
|
218
|
+
// 如果焦点移向菜单或内部自定义元素(箭头、清除),忽略失焦
|
|
219
|
+
const isMenu = relatedTarget.closest?.(`.${DROPDOWN_CLASS}`);
|
|
220
|
+
const isInternal = relatedTarget.closest?.(`.${ARROW_CLASS}, .${CLEAR_CLASS}`);
|
|
221
|
+
if (isMenu || isInternal) {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
setOpen(false);
|
|
227
|
+
onBlurProp?.(e);
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
const handleCascaderChange = (
|
|
231
|
+
selectedValue: (any)[],
|
|
232
|
+
selectedOptions: CustomCascaderOption[]
|
|
233
|
+
) => {
|
|
234
|
+
const path = selectedOptions.map((opt) => opt[labelKey]?.toString() || '').join('');
|
|
235
|
+
setInputText(path);
|
|
236
|
+
onChange?.(selectedValue, selectedOptions);
|
|
237
|
+
|
|
238
|
+
const lastOption = selectedOptions[selectedOptions.length - 1];
|
|
239
|
+
const hasChildren = lastOption?.[childrenKey] && lastOption[childrenKey].length > 0;
|
|
240
|
+
|
|
241
|
+
if (hasChildren) {
|
|
242
|
+
setOpen(true);
|
|
243
|
+
setTimeout(() => {
|
|
244
|
+
inputRef.current?.focus();
|
|
245
|
+
}, 0);
|
|
246
|
+
} else {
|
|
247
|
+
setOpen(false);
|
|
248
|
+
preventOpenRef.current = true;
|
|
249
|
+
setTimeout(() => {
|
|
250
|
+
inputRef.current?.focus();
|
|
251
|
+
}, 0);
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
const handleClear = (e?: React.MouseEvent) => {
|
|
256
|
+
e?.stopPropagation();
|
|
257
|
+
setInputText('');
|
|
258
|
+
setOpen(false);
|
|
259
|
+
onChange?.(undefined, []);
|
|
260
|
+
// 保持焦点
|
|
261
|
+
inputRef.current?.focus();
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
const toggleOpen = () => {
|
|
265
|
+
if (open) {
|
|
266
|
+
setOpen(false);
|
|
267
|
+
// 保持焦点
|
|
268
|
+
inputRef.current?.focus();
|
|
269
|
+
} else {
|
|
270
|
+
// 打开弹窗,清除阻止标记,确保 onFocus 能正常工作
|
|
271
|
+
preventOpenRef.current = false;
|
|
272
|
+
setOpen(true);
|
|
273
|
+
inputRef.current?.focus();
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
const showClear = externalValue && externalValue.length > 0;
|
|
278
|
+
|
|
279
|
+
useImperativeHandle(ref, () => ({
|
|
280
|
+
focus: () => inputRef.current?.focus(),
|
|
281
|
+
blur: () => inputRef.current?.blur(),
|
|
282
|
+
}));
|
|
283
|
+
|
|
284
|
+
return (
|
|
285
|
+
<div
|
|
286
|
+
ref={containerRef}
|
|
287
|
+
className={className}
|
|
288
|
+
style={{ position: 'relative', width: '100%', ...style }}
|
|
289
|
+
>
|
|
290
|
+
<Input
|
|
291
|
+
ref={inputRef}
|
|
292
|
+
placeholder={placeholder}
|
|
293
|
+
value={inputText}
|
|
294
|
+
onChange={handleInputChange}
|
|
295
|
+
onCompositionStart={handleCompositionStart}
|
|
296
|
+
onCompositionEnd={handleCompositionEnd}
|
|
297
|
+
onFocus={handleInputFocus}
|
|
298
|
+
onBlur={handleInputBlur}
|
|
299
|
+
style={{
|
|
300
|
+
// height: 25,
|
|
301
|
+
// paddingRight: 10,
|
|
302
|
+
...style,
|
|
303
|
+
}}
|
|
304
|
+
suffix={
|
|
305
|
+
<>
|
|
306
|
+
{showClear && (
|
|
307
|
+
<CloseOutlined
|
|
308
|
+
className={CLEAR_CLASS}
|
|
309
|
+
onClick={handleClear}
|
|
310
|
+
style={{ color: 'rgba(0,0,0,0.25)', cursor: 'pointer', marginRight: 4 }}
|
|
311
|
+
/>
|
|
312
|
+
)}
|
|
313
|
+
<DownOutlined
|
|
314
|
+
className={ARROW_CLASS}
|
|
315
|
+
onClick={toggleOpen}
|
|
316
|
+
style={{
|
|
317
|
+
color: open ? '#1677ff' : 'rgba(0,0,0,0.25)',
|
|
318
|
+
cursor: 'pointer',
|
|
319
|
+
transition: 'transform 0.2s',
|
|
320
|
+
transform: open ? 'rotate(180deg)' : 'none',
|
|
321
|
+
}}
|
|
322
|
+
/>
|
|
323
|
+
</>
|
|
324
|
+
}
|
|
325
|
+
/>
|
|
326
|
+
|
|
327
|
+
<Cascader<CustomCascaderOption>
|
|
328
|
+
{...restProps}
|
|
329
|
+
options={options}
|
|
330
|
+
fieldNames={fieldNames}
|
|
331
|
+
value={externalValue}
|
|
332
|
+
onChange={handleCascaderChange}
|
|
333
|
+
open={open}
|
|
334
|
+
getPopupContainer={() => document.body}
|
|
335
|
+
dropdownClassName={DROPDOWN_CLASS}
|
|
336
|
+
style={{
|
|
337
|
+
position: 'absolute',
|
|
338
|
+
top: 0,
|
|
339
|
+
left: 0,
|
|
340
|
+
width: '100%',
|
|
341
|
+
height: '100%',
|
|
342
|
+
opacity: 0,
|
|
343
|
+
pointerEvents: 'none',
|
|
344
|
+
zIndex: -1,
|
|
345
|
+
}}
|
|
346
|
+
showSearch={false}
|
|
347
|
+
expandIcon={null}
|
|
348
|
+
/>
|
|
349
|
+
</div>
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
);
|
|
353
|
+
|
|
354
|
+
CustomCascader.displayName = 'CustomCascader';
|
|
355
|
+
|
|
356
|
+
export default CustomCascader;
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Invoice from '../../..';
|
|
3
|
+
import { IGoodPassenger } from '../../../InvoiceController';
|
|
4
|
+
import {
|
|
5
|
+
Drawer,
|
|
6
|
+
Button,
|
|
7
|
+
Upload,
|
|
8
|
+
Table,
|
|
9
|
+
Alert,
|
|
10
|
+
Tag,
|
|
11
|
+
Space,
|
|
12
|
+
Typography,
|
|
13
|
+
message,
|
|
14
|
+
Input,
|
|
15
|
+
Progress,
|
|
16
|
+
} from 'kts-components-antd-x4';
|
|
17
|
+
import { DownloadOutlined, InboxOutlined } from '@ant-design/icons';
|
|
18
|
+
import type { UploadProps } from 'kts-components-antd-x4'; // 引入 UploadProps 用于类型提取
|
|
19
|
+
import { CheckCircleFilled } from '@ant-design/icons';
|
|
20
|
+
import idGenerator from '@/Invoice/tools/idGenerator';
|
|
21
|
+
|
|
22
|
+
const { Dragger } = Upload;
|
|
23
|
+
const { Text } = Typography;
|
|
24
|
+
|
|
25
|
+
export default () => {
|
|
26
|
+
const controller = Invoice.useInvoiceController();
|
|
27
|
+
|
|
28
|
+
const visible = controller.useMemo(s => s.passengerListState.isVisibleDrawer, []);
|
|
29
|
+
const dataSource = controller.useMemo(s => s.passengerListState.dataSource, []);
|
|
30
|
+
|
|
31
|
+
const onClose = React.useCallback(() => {
|
|
32
|
+
controller.pipeline(async s => {
|
|
33
|
+
s.passengerListState.isVisibleDrawer = false;
|
|
34
|
+
})();
|
|
35
|
+
}, [controller]);
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
const onConfirm = React.useCallback(async () => {
|
|
39
|
+
if (dataSource.length) {
|
|
40
|
+
await controller.pipeline(async s => {
|
|
41
|
+
const data = dataSource.map(item => {
|
|
42
|
+
return {
|
|
43
|
+
$index: idGenerator(),
|
|
44
|
+
...item
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
s.passengerListState.goodsList = [...s.passengerListState.goodsList, ...data];
|
|
48
|
+
s.passengerListState.dataSource = [];
|
|
49
|
+
})();
|
|
50
|
+
await controller.wait()
|
|
51
|
+
}
|
|
52
|
+
onClose();
|
|
53
|
+
}, [controller, dataSource]);
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<Drawer
|
|
57
|
+
title="批量导入"
|
|
58
|
+
placement="right"
|
|
59
|
+
// closable={false}
|
|
60
|
+
destroyOnClose={true}
|
|
61
|
+
width={983}
|
|
62
|
+
onClose={onClose}
|
|
63
|
+
visible={visible}
|
|
64
|
+
// 使用 footer 属性放置底部按钮
|
|
65
|
+
footer={
|
|
66
|
+
<div style={{ textAlign: 'right' }}>
|
|
67
|
+
<Space>
|
|
68
|
+
<Button onClick={() => onClose()}>取消</Button>
|
|
69
|
+
<Button type="primary" onClick={onConfirm}>确定</Button>
|
|
70
|
+
</Space>
|
|
71
|
+
</div>
|
|
72
|
+
}
|
|
73
|
+
>
|
|
74
|
+
<DrawerBody />
|
|
75
|
+
</Drawer>
|
|
76
|
+
);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const DrawerBody = () => {
|
|
80
|
+
const controller = Invoice.useInvoiceController();
|
|
81
|
+
|
|
82
|
+
const [fileName, setFileName] = React.useState('');
|
|
83
|
+
const [status, setStatus] = React.useState<'idle' | 'uploading' | 'done' | 'error'>('idle');
|
|
84
|
+
const [percent, setPercent] = React.useState(0);
|
|
85
|
+
const [fileData, setFileData] = React.useState<any[]>([]);
|
|
86
|
+
const [success, setSuccess] = React.useState(false);
|
|
87
|
+
|
|
88
|
+
const columns = controller.useMemo(s => s.passengerListState.columns, []);
|
|
89
|
+
|
|
90
|
+
const dataSource = controller.useMemo(s => s.passengerListState.dataSource, []);
|
|
91
|
+
|
|
92
|
+
const pagination = controller.useMemo(s => s.passengerListState.pagination, []);
|
|
93
|
+
|
|
94
|
+
const handleDownloadTemplate = React.useCallback(() => {
|
|
95
|
+
if (controller.downloadPassengerTpt) {
|
|
96
|
+
controller.downloadPassengerTpt();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
}, [controller])
|
|
100
|
+
|
|
101
|
+
// 1. 前置校验:限制文件类型为 .xls, .xlsx
|
|
102
|
+
const beforeUpload = React.useCallback((file: any) => {
|
|
103
|
+
const isExcel = file.type === 'application/vnd.ms-excel' ||
|
|
104
|
+
file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ||
|
|
105
|
+
/\.(xls|xlsx)$/.test(file.name); // 兜底判断文件名后缀
|
|
106
|
+
|
|
107
|
+
if (!isExcel) {
|
|
108
|
+
message.error('只能上传 .xls 或 .xlsx 格式的Excel文件!');
|
|
109
|
+
return Upload.LIST_IGNORE; // 阻止上传
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
setFileName(file.name);
|
|
113
|
+
setStatus('uploading');
|
|
114
|
+
setPercent(0);
|
|
115
|
+
return true;
|
|
116
|
+
}, []);
|
|
117
|
+
|
|
118
|
+
// 2. 正确类型定义的 customRequest
|
|
119
|
+
// 直接使用 UploadProps['customRequest'] 可以完美推导出 options 内所有的类型!
|
|
120
|
+
const customRequest: UploadProps['customRequest'] = async (options) => {
|
|
121
|
+
const { file, onSuccess, onError , onProgress } = options;
|
|
122
|
+
|
|
123
|
+
if (controller.uploadPassenger) {
|
|
124
|
+
const res = await controller.uploadPassenger(file as any);
|
|
125
|
+
if (res) {
|
|
126
|
+
setStatus('done');
|
|
127
|
+
setPercent(100);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// 3. 处理文件选择状态(更新左侧 Input 显示的文件名)
|
|
133
|
+
const handleChange = (info: any) => {
|
|
134
|
+
if (info.file.status === 'done') {
|
|
135
|
+
// 上传成功后可以获取后端返回的信息
|
|
136
|
+
console.log('上传成功返回的数据:', info.file.response);
|
|
137
|
+
}
|
|
138
|
+
// 更新文件名
|
|
139
|
+
if (info.file.name) {
|
|
140
|
+
setFileName(info.file.name);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
React.useEffect(() => {
|
|
146
|
+
controller.getBuyerList &&
|
|
147
|
+
controller.getBuyerList({ pagination: { current: 1 } });
|
|
148
|
+
}, [controller]);
|
|
149
|
+
|
|
150
|
+
return (
|
|
151
|
+
<div>
|
|
152
|
+
<Alert
|
|
153
|
+
type="info"
|
|
154
|
+
showIcon
|
|
155
|
+
message={
|
|
156
|
+
<span>
|
|
157
|
+
请先下载模板
|
|
158
|
+
<a href="#" style={{ margin: '0 4px' }} onClick={handleDownloadTemplate}>
|
|
159
|
+
《旅客运输服务特定信息-批量导入模板》
|
|
160
|
+
</a>
|
|
161
|
+
,按照模板填写后上传。
|
|
162
|
+
</span>
|
|
163
|
+
}
|
|
164
|
+
/>
|
|
165
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 20, marginTop: 20 }}>
|
|
166
|
+
<Input
|
|
167
|
+
placeholder="选择文件"
|
|
168
|
+
value={fileName}
|
|
169
|
+
readOnly
|
|
170
|
+
style={{ width: 400, height: 32 }}
|
|
171
|
+
suffix={
|
|
172
|
+
status === 'uploading' ? (
|
|
173
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: 4 }}>
|
|
174
|
+
<span style={{ fontSize: 12, color: '#1890ff' }}>{percent}%</span>
|
|
175
|
+
</div>
|
|
176
|
+
) : status === 'done' ? (
|
|
177
|
+
<CheckCircleFilled style={{ color: '#52c41a', fontSize: 16 }} />
|
|
178
|
+
) : null
|
|
179
|
+
}
|
|
180
|
+
/>
|
|
181
|
+
|
|
182
|
+
<Upload
|
|
183
|
+
accept=".xls,.xlsx"
|
|
184
|
+
showUploadList={false}
|
|
185
|
+
beforeUpload={beforeUpload}
|
|
186
|
+
customRequest={customRequest}
|
|
187
|
+
>
|
|
188
|
+
<Button style={status === 'uploading' ? { color: '#1890ff', borderColor: '#1890ff' } : undefined}>
|
|
189
|
+
{fileName ? '重新选择' : "选择文件"}
|
|
190
|
+
</Button>
|
|
191
|
+
</Upload>
|
|
192
|
+
</div>
|
|
193
|
+
{success && <div style={{ marginBottom: 20, marginTop: 20 }}>
|
|
194
|
+
<Alert type="success" showIcon message={
|
|
195
|
+
<span>
|
|
196
|
+
文件导入成功,处理旅客运输服务特定信息记录{dataSource.length}条,处理成功{dataSource.length}条。
|
|
197
|
+
</span>
|
|
198
|
+
} />
|
|
199
|
+
</div>}
|
|
200
|
+
|
|
201
|
+
<Table
|
|
202
|
+
bordered
|
|
203
|
+
size="small"
|
|
204
|
+
columns={columns}
|
|
205
|
+
dataSource={dataSource}
|
|
206
|
+
locale={{
|
|
207
|
+
emptyText: '暂无数据'
|
|
208
|
+
}}
|
|
209
|
+
pagination={false}
|
|
210
|
+
/>
|
|
211
|
+
</div>
|
|
212
|
+
);
|
|
213
|
+
};
|
|
214
|
+
|