12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import React, { useState, useRef } from 'react'
  2. import { Button, Checkbox, Select, Space, Carousel, Typography } from 'antd'
  3. import { getRangeOfSheet, getAllCols } from './excel'
  4. import styles from './style.less'
  5. const { Title } = Typography;
  6. const { Option } = Select;
  7. export default (props) => {
  8. const { workbook } = props
  9. const sliderRef = useRef()
  10. const [sheetName, setSheetName] = useState()
  11. const sheetRef = useRef()
  12. const [allCols, setAllCols] = useState([])
  13. const [columns, setColumns] = useState()
  14. const handleSheetSelect = (nm) => {
  15. setSheetName(nm)
  16. sheetRef.current = workbook.Sheets[nm]
  17. const sheetRange = getRangeOfSheet(sheetRef.current)
  18. const cols = getAllCols(sheetRange.startCol, sheetRange.endCol)
  19. setAllCols(cols)
  20. }
  21. const handleColChange = (cols) => {
  22. setColumns(cols)
  23. }
  24. const next = () => {
  25. sliderRef.current.next()
  26. }
  27. return (
  28. <div>
  29. <Carousel ref={sliderRef}>
  30. <div className={styles['step-box']}>
  31. <Space direction="vertical" size="large" style={{width: '100%'}}>
  32. <Title level={4}>请选择 sheet</Title>
  33. <Select value={sheetName} onChange={handleSheetSelect} style={{minWidth: '200px'}}>
  34. {
  35. (workbook.SheetNames || []).map((nm) => (<Option key={nm} value={nm}>{nm}</Option>))
  36. }
  37. </Select>
  38. <Button disabled={!sheetName} type="primary" onClick={next}>下一步</Button>
  39. </Space>
  40. </div>
  41. <div className={styles['step-box']}>
  42. <Space direction="vertical" size="large" style={{width: '100%'}}>
  43. <Title level={4}>请选择 数据列</Title>
  44. <Checkbox.Group style={{ width: '100%' }} value={columns} onChange={handleColChange}>
  45. {
  46. allCols.map((col) => (<div key={col}><Checkbox value={col}>{col}</Checkbox></div>))
  47. }
  48. </Checkbox.Group>
  49. <Button type="primary" disabled={!columns || !columns.length} onClick={next}>下一步</Button>
  50. </Space>
  51. </div>
  52. </Carousel>
  53. </div>
  54. )
  55. }