@gmfe/table-x 2.14.20 → 2.14.24

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.
Files changed (44) hide show
  1. package/README.md +13 -13
  2. package/package.json +4 -4
  3. package/src/base/index.js +142 -142
  4. package/src/base/td.js +56 -56
  5. package/src/base/th.js +48 -48
  6. package/src/base/thead.js +26 -26
  7. package/src/base/tr.js +53 -53
  8. package/src/base/virtualized.js +219 -219
  9. package/src/hoc/diy_table_x/components/diy_table_x_modal.js +135 -135
  10. package/src/hoc/diy_table_x/components/modal_list.js +78 -78
  11. package/src/hoc/diy_table_x/components/modal_selector.js +56 -56
  12. package/src/hoc/diy_table_x/index.js +196 -196
  13. package/src/hoc/edit_table_x.js +20 -20
  14. package/src/hoc/expand_table_x/index.js +140 -140
  15. package/src/hoc/expand_table_x/util.js +27 -27
  16. package/src/hoc/fixed_columns_table_x.js +29 -29
  17. package/src/hoc/select_table_x/cell.js +51 -51
  18. package/src/hoc/select_table_x/header.js +28 -28
  19. package/src/hoc/select_table_x/index.js +139 -139
  20. package/src/hoc/select_table_x/util.js +10 -10
  21. package/src/hoc/sortable_table_x.js +52 -52
  22. package/src/hoc/sub_table_x.js +44 -44
  23. package/src/index.js +53 -53
  24. package/src/index.less +515 -515
  25. package/src/stories/table_x.stories.js +324 -324
  26. package/src/stories/table_x_hoc.stories.js +427 -427
  27. package/src/stories/table_x_hoc_select_expand.stories.js +256 -256
  28. package/src/util/batch_action_bar.js +124 -124
  29. package/src/util/edit.js +83 -83
  30. package/src/util/index.js +191 -191
  31. package/src/util/operation.js +249 -249
  32. package/src/util/sort_header.js +49 -49
  33. package/src/variables.less +28 -28
  34. package/svg/business.svg +20 -20
  35. package/svg/check-detail.svg +18 -18
  36. package/svg/closeup.svg +20 -20
  37. package/svg/delete.svg +10 -10
  38. package/svg/edit-pen.svg +17 -17
  39. package/svg/empty.svg +27 -27
  40. package/svg/expand.svg +21 -21
  41. package/svg/pen.svg +12 -12
  42. package/svg/recover.svg +33 -33
  43. package/svg/remove.svg +1 -1
  44. package/svg/setting.svg +17 -17
@@ -1,135 +1,135 @@
1
- import React, { useState } from 'react'
2
- import { Flex, Button } from '@gmfe/react'
3
- import _ from 'lodash'
4
- import Selector from './modal_selector'
5
- import List from './modal_list'
6
- import PropTypes from 'prop-types'
7
- import { getLocale } from '@gmfe/locales'
8
-
9
- const DiyTableModal = ({ columns, onSave, diyGroupSorting, onCancel }) => {
10
- const [diyCols, setDiyCols] = useState(columns)
11
- const [showCols, setShowCols] = useState(columns.filter(o => o.show))
12
-
13
- const handleColsChange = (key, curShow) => {
14
- const index = _.findIndex(diyCols, o => o.key === key)
15
- const _diyCols = diyCols.slice()
16
-
17
- const curItem = _diyCols[index]
18
- curItem.show = !curShow
19
-
20
- setDiyCols(_diyCols)
21
-
22
- if (curItem.show) {
23
- // 把当前项增加到排序列表中
24
- setShowCols(_diyCols.filter(o => o.show))
25
- } else {
26
- // 把当前项从排序列表去掉
27
- const _showCols = showCols.slice()
28
- _.remove(_showCols, item => item.key === key)
29
- setShowCols(_showCols)
30
- }
31
- }
32
-
33
- const handleColsRemove = key => {
34
- const _showCols = showCols.slice()
35
- _.remove(_showCols, o => o.key === key)
36
- setShowCols(_showCols)
37
-
38
- const index = _.findIndex(diyCols, o => o.key === key)
39
- const _diyCols = diyCols.slice()
40
- _diyCols[index].show = false
41
- setDiyCols(_diyCols)
42
- }
43
-
44
- const handleColsSort = (beforeKey, afterKey) => {
45
- //移动到前面,移动到后面
46
- let beforeIndex, afterIndex;
47
- _.forEach(diyCols, (item, index)=>{
48
- if(beforeKey === item.key){
49
- beforeIndex = index
50
- }
51
- if(afterKey === item.key){
52
- afterIndex = index
53
- }
54
- })
55
- diyCols.splice(afterIndex + 1, 0, diyCols[beforeIndex]);
56
- if(afterIndex > beforeIndex){
57
- diyCols.splice(beforeIndex, 1);
58
- }
59
- if(afterIndex < beforeIndex){
60
- diyCols.splice(beforeIndex + 1, 1);
61
- }
62
- setDiyCols(diyCols)
63
- setShowCols(columns.filter(o => o.show))
64
- }
65
-
66
- const handleSave = () => {
67
- const columns = diyCols.map(col => {
68
- return {
69
- ...col,
70
- show: _.findIndex(showCols, v => v.key === col.key) > -1 // 大于-1才会显示
71
- }
72
- })
73
-
74
- onSave(columns)
75
- onCancel()
76
- }
77
-
78
- return (
79
- <div className='gm-react-table-x-diy-modal'>
80
- <Flex
81
- className='gm-react-table-x-diy-modal-header gm-padding-tb-5'
82
- justifyBetween
83
- alignCenter
84
- >
85
- <div className='gm-react-table-x-diy-modal-header-title gm-margin-left-10 gm-padding-left-5'>
86
- {getLocale('表头设置')}
87
- </div>
88
- <button
89
- className='gm-react-table-x-diy-modal-header-close gm-margin-right-10'
90
- onClick={onCancel}
91
- >
92
- ×
93
- </button>
94
- </Flex>
95
- <Flex className='gm-react-table-x-diy-modal-content'>
96
- <div className='gm-react-table-x-diy-modal-selector'>
97
- <div className='gm-react-table-x-diy-modal-title'>
98
- 可选字段
99
- </div>
100
- <Selector
101
- diyGroupSorting={diyGroupSorting}
102
- cols={diyCols}
103
- onColsChange={handleColsChange}
104
- />
105
- </div>
106
- <div className='gm-react-table-x-diy-modal-list'>
107
- <div className='gm-react-table-x-diy-modal-title'>
108
- 当前选定的字段
109
- </div>
110
- <List cols={showCols} onColsRemove={handleColsRemove} onColsSort={handleColsSort}/>
111
- </div>
112
- </Flex>
113
- <Flex justifyEnd className='gm-padding-10'>
114
- <Button onClick={onCancel}>取消</Button>
115
- <div className='gm-gap-10' />
116
- <Button
117
- type='primary'
118
- onClick={handleSave}
119
- className='gm-margin-right-10'
120
- >
121
- 保存
122
- </Button>
123
- </Flex>
124
- </div>
125
- )
126
- }
127
-
128
- DiyTableModal.propTypes = {
129
- columns: PropTypes.array.isRequired,
130
- diyGroupSorting: PropTypes.array.isRequired,
131
- onSave: PropTypes.func.isRequired,
132
- onCancel: PropTypes.func.isRequired
133
- }
134
-
135
- export default DiyTableModal
1
+ import React, { useState } from 'react'
2
+ import { Flex, Button } from '@gmfe/react'
3
+ import _ from 'lodash'
4
+ import Selector from './modal_selector'
5
+ import List from './modal_list'
6
+ import PropTypes from 'prop-types'
7
+ import { getLocale } from '@gmfe/locales'
8
+
9
+ const DiyTableModal = ({ columns, onSave, diyGroupSorting, onCancel }) => {
10
+ const [diyCols, setDiyCols] = useState(columns)
11
+ const [showCols, setShowCols] = useState(columns.filter(o => o.show))
12
+
13
+ const handleColsChange = (key, curShow) => {
14
+ const index = _.findIndex(diyCols, o => o.key === key)
15
+ const _diyCols = diyCols.slice()
16
+
17
+ const curItem = _diyCols[index]
18
+ curItem.show = !curShow
19
+
20
+ setDiyCols(_diyCols)
21
+
22
+ if (curItem.show) {
23
+ // 把当前项增加到排序列表中
24
+ setShowCols(_diyCols.filter(o => o.show))
25
+ } else {
26
+ // 把当前项从排序列表去掉
27
+ const _showCols = showCols.slice()
28
+ _.remove(_showCols, item => item.key === key)
29
+ setShowCols(_showCols)
30
+ }
31
+ }
32
+
33
+ const handleColsRemove = key => {
34
+ const _showCols = showCols.slice()
35
+ _.remove(_showCols, o => o.key === key)
36
+ setShowCols(_showCols)
37
+
38
+ const index = _.findIndex(diyCols, o => o.key === key)
39
+ const _diyCols = diyCols.slice()
40
+ _diyCols[index].show = false
41
+ setDiyCols(_diyCols)
42
+ }
43
+
44
+ const handleColsSort = (beforeKey, afterKey) => {
45
+ //移动到前面,移动到后面
46
+ let beforeIndex, afterIndex;
47
+ _.forEach(diyCols, (item, index)=>{
48
+ if(beforeKey === item.key){
49
+ beforeIndex = index
50
+ }
51
+ if(afterKey === item.key){
52
+ afterIndex = index
53
+ }
54
+ })
55
+ diyCols.splice(afterIndex + 1, 0, diyCols[beforeIndex]);
56
+ if(afterIndex > beforeIndex){
57
+ diyCols.splice(beforeIndex, 1);
58
+ }
59
+ if(afterIndex < beforeIndex){
60
+ diyCols.splice(beforeIndex + 1, 1);
61
+ }
62
+ setDiyCols(diyCols)
63
+ setShowCols(columns.filter(o => o.show))
64
+ }
65
+
66
+ const handleSave = () => {
67
+ const columns = diyCols.map(col => {
68
+ return {
69
+ ...col,
70
+ show: _.findIndex(showCols, v => v.key === col.key) > -1 // 大于-1才会显示
71
+ }
72
+ })
73
+
74
+ onSave(columns)
75
+ onCancel()
76
+ }
77
+
78
+ return (
79
+ <div className='gm-react-table-x-diy-modal'>
80
+ <Flex
81
+ className='gm-react-table-x-diy-modal-header gm-padding-tb-5'
82
+ justifyBetween
83
+ alignCenter
84
+ >
85
+ <div className='gm-react-table-x-diy-modal-header-title gm-margin-left-10 gm-padding-left-5'>
86
+ {getLocale('表头设置')}
87
+ </div>
88
+ <button
89
+ className='gm-react-table-x-diy-modal-header-close gm-margin-right-10'
90
+ onClick={onCancel}
91
+ >
92
+ ×
93
+ </button>
94
+ </Flex>
95
+ <Flex className='gm-react-table-x-diy-modal-content'>
96
+ <div className='gm-react-table-x-diy-modal-selector'>
97
+ <div className='gm-react-table-x-diy-modal-title'>
98
+ 可选字段
99
+ </div>
100
+ <Selector
101
+ diyGroupSorting={diyGroupSorting}
102
+ cols={diyCols}
103
+ onColsChange={handleColsChange}
104
+ />
105
+ </div>
106
+ <div className='gm-react-table-x-diy-modal-list'>
107
+ <div className='gm-react-table-x-diy-modal-title'>
108
+ 当前选定的字段
109
+ </div>
110
+ <List cols={showCols} onColsRemove={handleColsRemove} onColsSort={handleColsSort}/>
111
+ </div>
112
+ </Flex>
113
+ <Flex justifyEnd className='gm-padding-10'>
114
+ <Button onClick={onCancel}>取消</Button>
115
+ <div className='gm-gap-10' />
116
+ <Button
117
+ type='primary'
118
+ onClick={handleSave}
119
+ className='gm-margin-right-10'
120
+ >
121
+ 保存
122
+ </Button>
123
+ </Flex>
124
+ </div>
125
+ )
126
+ }
127
+
128
+ DiyTableModal.propTypes = {
129
+ columns: PropTypes.array.isRequired,
130
+ diyGroupSorting: PropTypes.array.isRequired,
131
+ onSave: PropTypes.func.isRequired,
132
+ onCancel: PropTypes.func.isRequired
133
+ }
134
+
135
+ export default DiyTableModal
@@ -1,78 +1,78 @@
1
- import React from 'react'
2
- import PropTypes from 'prop-types'
3
- import SVGRemove from '../../../../svg/remove.svg'
4
- import _ from 'lodash'
5
-
6
- const ModalList = ({ cols, onColsRemove, onColsSort }) => {
7
- const onRemove = (key, e) => {
8
- e.stopPropagation()
9
- onColsRemove(key)
10
- }
11
-
12
- const handleDragEnter = (key, e) => {
13
- if(!e.target){
14
- return
15
- }
16
- e.target.style.borderBottom = '2px dashed #008dff';
17
- e.stopPropagation()
18
- e.preventDefault()
19
- }
20
-
21
- const throttleDragEnter = _.throttle(handleDragEnter,1500)
22
-
23
- const handleDragLeave = (key, e) => {
24
- e.target.style.border = '';
25
- e.target.style.boxShadow = '';
26
- e.stopPropagation()
27
- e.preventDefault()
28
- }
29
-
30
- const handleDragStart = (key, e) => {
31
- e.dataTransfer.setData("key", key);
32
- }
33
-
34
- const handleDrop = (key, e) => {
35
- if(!e.target){
36
- return
37
- }
38
- const beforekey = e.dataTransfer.getData("key");
39
- const afterkey = e.target?.attributes?.dragkey?.value
40
- e.target && (e.target.style.border = '')
41
- e.target && (e.target.style.boxShadow = '')
42
- onColsSort(beforekey, afterkey)
43
- e.stopPropagation()
44
- e.preventDefault()
45
- }
46
- return (
47
- <ul className='gm-react-table-x-diy-modal-list-ul'>
48
- {cols.map(item => {
49
- const { diyItemText, Header, key, diyEnable } = item
50
- const text = diyItemText || Header
51
- return (
52
- <li style={{boxSizing:"border-box"}} className='gm-react-table-x-diy-modal-list-li' dragkey={key} key={key} onDragEnter={throttleDragEnter.bind(this, key)}
53
- onDragLeave={handleDragLeave.bind(this, key)}
54
- onDragOver={handleDragEnter.bind(this, key)}
55
- onDragStart={handleDragStart.bind(this, key)}
56
- onDrop={handleDrop.bind(this, key)}
57
- draggable="true">
58
- {text}
59
- {diyEnable && (
60
- <SVGRemove
61
- onClick={onRemove.bind(this, key)}
62
- className='gm-cursor gm-react-table-x-diy-modal-list-li-remove'
63
- />
64
- )}
65
- </li>
66
- )
67
- })}
68
- </ul>
69
- )
70
- }
71
-
72
- ModalList.propTypes = {
73
- cols: PropTypes.array.isRequired,
74
- onColsRemove: PropTypes.func.isRequired,
75
- onColsSort: PropTypes.func.isRequired,
76
- }
77
-
78
- export default ModalList
1
+ import React from 'react'
2
+ import PropTypes from 'prop-types'
3
+ import SVGRemove from '../../../../svg/remove.svg'
4
+ import _ from 'lodash'
5
+
6
+ const ModalList = ({ cols, onColsRemove, onColsSort }) => {
7
+ const onRemove = (key, e) => {
8
+ e.stopPropagation()
9
+ onColsRemove(key)
10
+ }
11
+
12
+ const handleDragEnter = (key, e) => {
13
+ if(!e.target){
14
+ return
15
+ }
16
+ e.target.style.borderBottom = '2px dashed #008dff';
17
+ e.stopPropagation()
18
+ e.preventDefault()
19
+ }
20
+
21
+ const throttleDragEnter = _.throttle(handleDragEnter,1500)
22
+
23
+ const handleDragLeave = (key, e) => {
24
+ e.target.style.border = '';
25
+ e.target.style.boxShadow = '';
26
+ e.stopPropagation()
27
+ e.preventDefault()
28
+ }
29
+
30
+ const handleDragStart = (key, e) => {
31
+ e.dataTransfer.setData("key", key);
32
+ }
33
+
34
+ const handleDrop = (key, e) => {
35
+ if(!e.target){
36
+ return
37
+ }
38
+ const beforekey = e.dataTransfer.getData("key");
39
+ const afterkey = e.target?.attributes?.dragkey?.value
40
+ e.target && (e.target.style.border = '')
41
+ e.target && (e.target.style.boxShadow = '')
42
+ onColsSort(beforekey, afterkey)
43
+ e.stopPropagation()
44
+ e.preventDefault()
45
+ }
46
+ return (
47
+ <ul className='gm-react-table-x-diy-modal-list-ul'>
48
+ {cols.map(item => {
49
+ const { diyItemText, Header, key, diyEnable } = item
50
+ const text = diyItemText || Header
51
+ return (
52
+ <li style={{boxSizing:"border-box"}} className='gm-react-table-x-diy-modal-list-li' dragkey={key} key={key} onDragEnter={throttleDragEnter.bind(this, key)}
53
+ onDragLeave={handleDragLeave.bind(this, key)}
54
+ onDragOver={handleDragEnter.bind(this, key)}
55
+ onDragStart={handleDragStart.bind(this, key)}
56
+ onDrop={handleDrop.bind(this, key)}
57
+ draggable="true">
58
+ {text}
59
+ {diyEnable && (
60
+ <SVGRemove
61
+ onClick={onRemove.bind(this, key)}
62
+ className='gm-cursor gm-react-table-x-diy-modal-list-li-remove'
63
+ />
64
+ )}
65
+ </li>
66
+ )
67
+ })}
68
+ </ul>
69
+ )
70
+ }
71
+
72
+ ModalList.propTypes = {
73
+ cols: PropTypes.array.isRequired,
74
+ onColsRemove: PropTypes.func.isRequired,
75
+ onColsSort: PropTypes.func.isRequired,
76
+ }
77
+
78
+ export default ModalList
@@ -1,56 +1,56 @@
1
- import React from 'react'
2
- import _ from 'lodash'
3
- import { Checkbox, Flex } from '@gmfe/react'
4
- import PropTypes from 'prop-types'
5
- import styled from 'styled-components'
6
-
7
- const Item = styled.div`
8
- width: 25%;
9
- padding: 5px 0;
10
- `
11
-
12
- const ModalSelector = ({ cols, onColsChange, diyGroupSorting }) => {
13
- const colGroup = _.groupBy(cols, 'diyGroupName')
14
-
15
- return (
16
- <div>
17
- {_.map(diyGroupSorting, (groupName) => {
18
- const cols = colGroup[groupName]
19
- return (
20
- <div key={groupName}>
21
- <div className='gm-margin-tb-5'>{groupName}</div>
22
- <Flex wrap>
23
- {_.map(cols, (item) => {
24
- const { show, Header, diyItemText, diyEnable, key } = item
25
- const text = diyItemText || Header
26
-
27
- return (
28
- <Item key={key}>
29
- <Checkbox
30
- value={key}
31
- disabled={!diyEnable} // 不能编辑的字段,disable
32
- checked={show}
33
- onChange={() => {
34
- onColsChange(key, show)
35
- }}
36
- >
37
- {text}
38
- </Checkbox>
39
- </Item>
40
- )
41
- })}
42
- </Flex>
43
- </div>
44
- )
45
- })}
46
- </div>
47
- )
48
- }
49
-
50
- ModalSelector.propTypes = {
51
- cols: PropTypes.array.isRequired,
52
- diyGroupSorting: PropTypes.array.isRequired,
53
- onColsChange: PropTypes.func.isRequired,
54
- }
55
-
56
- export default ModalSelector
1
+ import React from 'react'
2
+ import _ from 'lodash'
3
+ import { Checkbox, Flex } from '@gmfe/react'
4
+ import PropTypes from 'prop-types'
5
+ import styled from 'styled-components'
6
+
7
+ const Item = styled.div`
8
+ width: 25%;
9
+ padding: 5px 0;
10
+ `
11
+
12
+ const ModalSelector = ({ cols, onColsChange, diyGroupSorting }) => {
13
+ const colGroup = _.groupBy(cols, 'diyGroupName')
14
+
15
+ return (
16
+ <div>
17
+ {_.map(diyGroupSorting, (groupName) => {
18
+ const cols = colGroup[groupName]
19
+ return (
20
+ <div key={groupName}>
21
+ <div className='gm-margin-tb-5'>{groupName}</div>
22
+ <Flex wrap>
23
+ {_.map(cols, (item) => {
24
+ const { show, Header, diyItemText, diyEnable, key } = item
25
+ const text = diyItemText || Header
26
+
27
+ return (
28
+ <Item key={key}>
29
+ <Checkbox
30
+ value={key}
31
+ disabled={!diyEnable} // 不能编辑的字段,disable
32
+ checked={show}
33
+ onChange={() => {
34
+ onColsChange(key, show)
35
+ }}
36
+ >
37
+ {text}
38
+ </Checkbox>
39
+ </Item>
40
+ )
41
+ })}
42
+ </Flex>
43
+ </div>
44
+ )
45
+ })}
46
+ </div>
47
+ )
48
+ }
49
+
50
+ ModalSelector.propTypes = {
51
+ cols: PropTypes.array.isRequired,
52
+ diyGroupSorting: PropTypes.array.isRequired,
53
+ onColsChange: PropTypes.func.isRequired,
54
+ }
55
+
56
+ export default ModalSelector