|
@@ -1,19 +1,35 @@
|
1
|
1
|
import React, { useState, useRef } from 'react'
|
2
|
|
-import { Button, Checkbox, Select, Space, Carousel, Typography } from 'antd'
|
|
2
|
+import { Row, Col, Button, InputNumber, Select, Carousel, Typography } from 'antd'
|
3
|
3
|
import { getRangeOfSheet, getAllCols } from './excel'
|
4
|
4
|
import styles from './style.less'
|
5
|
5
|
|
6
|
6
|
const { Title } = Typography;
|
7
|
7
|
const { Option } = Select;
|
8
|
8
|
|
|
9
|
+const ColSelect = (props) => {
|
|
10
|
+ const { value, onChange, cols } = props
|
|
11
|
+
|
|
12
|
+ return (
|
|
13
|
+ <Select value={value} onChange={onChange} allowClear style={{minWidth: '90%'}}>
|
|
14
|
+ {
|
|
15
|
+ cols.map((col) => (<Option key={col} value={col}>{col}</Option>))
|
|
16
|
+ }
|
|
17
|
+ </Select>
|
|
18
|
+ )
|
|
19
|
+}
|
|
20
|
+
|
9
|
21
|
export default (props) => {
|
10
|
|
- const { workbook } = props
|
|
22
|
+ const { workbook, onChange } = props
|
11
|
23
|
|
12
|
24
|
const sliderRef = useRef()
|
13
|
25
|
const [sheetName, setSheetName] = useState()
|
14
|
26
|
const sheetRef = useRef()
|
15
|
27
|
const [allCols, setAllCols] = useState([])
|
16
|
|
- const [columns, setColumns] = useState()
|
|
28
|
+ const [studentNoCol, setStudentCol] = useState()
|
|
29
|
+ const [testNoCol, setTestCol] = useState()
|
|
30
|
+ const [dataStartRow, setDataStartRow] = useState(2)
|
|
31
|
+
|
|
32
|
+ const maped = studentNoCol && testNoCol && studentNoCol !== testNoCol
|
17
|
33
|
|
18
|
34
|
const handleSheetSelect = (nm) => {
|
19
|
35
|
setSheetName(nm)
|
|
@@ -24,39 +40,69 @@ export default (props) => {
|
24
|
40
|
setAllCols(cols)
|
25
|
41
|
}
|
26
|
42
|
|
27
|
|
- const handleColChange = (cols) => {
|
28
|
|
- setColumns(cols)
|
29
|
|
- }
|
30
|
|
-
|
31
|
43
|
const next = () => {
|
32
|
44
|
sliderRef.current.next()
|
33
|
45
|
}
|
34
|
46
|
|
|
47
|
+ const handleSubmit = () => {
|
|
48
|
+ onChange({
|
|
49
|
+ sheet: sheetRef.current,
|
|
50
|
+ cols: { studentNoCol, testNoCol },
|
|
51
|
+ dataStartRow,
|
|
52
|
+ })
|
|
53
|
+
|
|
54
|
+ const t = setTimeout(() => {
|
|
55
|
+ // 重置所有
|
|
56
|
+ sliderRef.current.goTo(0, true)
|
|
57
|
+ setSheetName()
|
|
58
|
+ sheetRef.current = null
|
|
59
|
+ setAllCols([])
|
|
60
|
+ setStudentCol()
|
|
61
|
+ setTestCol()
|
|
62
|
+ setDataStartRow(2)
|
|
63
|
+ clearTimeout(t)
|
|
64
|
+ })
|
|
65
|
+ }
|
|
66
|
+
|
35
|
67
|
return (
|
36
|
68
|
<div>
|
37
|
|
- <Carousel ref={sliderRef}>
|
|
69
|
+ <Carousel ref={sliderRef} style={{width: '100%'}}>
|
|
70
|
+ {/* 第一步 */}
|
38
|
71
|
<div className={styles['step-box']}>
|
39
|
|
- <Space direction="vertical" size="large" style={{width: '100%'}}>
|
40
|
|
- <Title level={4}>请选择 sheet</Title>
|
41
|
|
- <Select value={sheetName} onChange={handleSheetSelect} style={{minWidth: '200px'}}>
|
42
|
|
- {
|
43
|
|
- (workbook.SheetNames || []).map((nm) => (<Option key={nm} value={nm}>{nm}</Option>))
|
44
|
|
- }
|
45
|
|
- </Select>
|
|
72
|
+ <Title level={5}>请选择 sheet</Title>
|
|
73
|
+ <div className={styles['step-content']}>
|
|
74
|
+ <Select value={sheetName} onChange={handleSheetSelect} style={{minWidth: '200px'}}>
|
|
75
|
+ {
|
|
76
|
+ (workbook.SheetNames || []).map((nm) => (<Option key={nm} value={nm}>{nm}</Option>))
|
|
77
|
+ }
|
|
78
|
+ </Select>
|
|
79
|
+ </div>
|
46
|
80
|
<Button disabled={!sheetName} type="primary" onClick={next}>下一步</Button>
|
47
|
|
- </Space>
|
48
|
81
|
</div>
|
49
|
82
|
|
|
83
|
+ {/* 第二步 */}
|
|
84
|
+ <div className={styles['step-box']}>
|
|
85
|
+ <Title level={5}>请设置 数据映射列</Title>
|
|
86
|
+ <div className={styles['step-content']}>
|
|
87
|
+ <Row style={{padding: '.3em 0'}}>
|
|
88
|
+ <Col span={12}>体检号:</Col>
|
|
89
|
+ <Col span={12}><ColSelect cols={allCols} value={testNoCol} onChange={setTestCol} /></Col>
|
|
90
|
+ </Row>
|
|
91
|
+ <Row style={{padding: '.3em 0'}}>
|
|
92
|
+ <Col span={12}>学号:</Col>
|
|
93
|
+ <Col span={12}><ColSelect cols={allCols} value={studentNoCol} onChange={setStudentCol} /></Col>
|
|
94
|
+ </Row>
|
|
95
|
+ </div>
|
|
96
|
+ <Button type="primary" disabled={!maped} onClick={next}>下一步</Button>
|
|
97
|
+ </div>
|
|
98
|
+
|
|
99
|
+ {/* 第三步 */}
|
50
|
100
|
<div className={styles['step-box']}>
|
51
|
|
- <Space direction="vertical" size="large" style={{width: '100%'}}>
|
52
|
|
- <Title level={4}>请选择 数据列</Title>
|
53
|
|
- <Checkbox.Group style={{ width: '100%' }} value={columns} onChange={handleColChange}>
|
54
|
|
- {
|
55
|
|
- allCols.map((col) => (<div key={col}><Checkbox value={col}>{col}</Checkbox></div>))
|
56
|
|
- }
|
57
|
|
- </Checkbox.Group>
|
58
|
|
- <Button type="primary" disabled={!columns || !columns.length} onClick={next}>下一步</Button>
|
59
|
|
- </Space>
|
|
101
|
+ <Title level={5}>请设置 数据起始行</Title>
|
|
102
|
+ <div className={styles['step-content']}>
|
|
103
|
+ <InputNumber value={dataStartRow} onChange={setDataStartRow} step={1} min={1} max={1000} />
|
|
104
|
+ </div>
|
|
105
|
+ <Button type="primary" disabled={!dataStartRow} onClick={handleSubmit}>完成</Button>
|
60
|
106
|
</div>
|
61
|
107
|
</Carousel>
|
62
|
108
|
</div>
|