@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.
- package/README.md +13 -13
- package/package.json +4 -4
- package/src/base/index.js +142 -142
- package/src/base/td.js +56 -56
- package/src/base/th.js +48 -48
- package/src/base/thead.js +26 -26
- package/src/base/tr.js +53 -53
- package/src/base/virtualized.js +219 -219
- package/src/hoc/diy_table_x/components/diy_table_x_modal.js +135 -135
- package/src/hoc/diy_table_x/components/modal_list.js +78 -78
- package/src/hoc/diy_table_x/components/modal_selector.js +56 -56
- package/src/hoc/diy_table_x/index.js +196 -196
- package/src/hoc/edit_table_x.js +20 -20
- package/src/hoc/expand_table_x/index.js +140 -140
- package/src/hoc/expand_table_x/util.js +27 -27
- package/src/hoc/fixed_columns_table_x.js +29 -29
- package/src/hoc/select_table_x/cell.js +51 -51
- package/src/hoc/select_table_x/header.js +28 -28
- package/src/hoc/select_table_x/index.js +139 -139
- package/src/hoc/select_table_x/util.js +10 -10
- package/src/hoc/sortable_table_x.js +52 -52
- package/src/hoc/sub_table_x.js +44 -44
- package/src/index.js +53 -53
- package/src/index.less +515 -515
- package/src/stories/table_x.stories.js +324 -324
- package/src/stories/table_x_hoc.stories.js +427 -427
- package/src/stories/table_x_hoc_select_expand.stories.js +256 -256
- package/src/util/batch_action_bar.js +124 -124
- package/src/util/edit.js +83 -83
- package/src/util/index.js +191 -191
- package/src/util/operation.js +249 -249
- package/src/util/sort_header.js +49 -49
- package/src/variables.less +28 -28
- package/svg/business.svg +20 -20
- package/svg/check-detail.svg +18 -18
- package/svg/closeup.svg +20 -20
- package/svg/delete.svg +10 -10
- package/svg/edit-pen.svg +17 -17
- package/svg/empty.svg +27 -27
- package/svg/expand.svg +21 -21
- package/svg/pen.svg +12 -12
- package/svg/recover.svg +33 -33
- package/svg/remove.svg +1 -1
- package/svg/setting.svg +17 -17
|
@@ -1,427 +1,427 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { storiesOf } from '@storybook/react'
|
|
3
|
-
import { observable } from 'mobx'
|
|
4
|
-
import { observer } from 'mobx-react'
|
|
5
|
-
import {
|
|
6
|
-
fixedColumnsTableXHOC,
|
|
7
|
-
sortableTableXHOC,
|
|
8
|
-
editTableXHOC,
|
|
9
|
-
diyTableXHOC,
|
|
10
|
-
TableX,
|
|
11
|
-
TableXVirtualized,
|
|
12
|
-
TableXUtil
|
|
13
|
-
} from '../index'
|
|
14
|
-
import _ from 'lodash'
|
|
15
|
-
import { InputNumberV2, MoreSelect } from '@gmfe/react'
|
|
16
|
-
|
|
17
|
-
const { TABLE_X, OperationHeader, EditOperation } = TableXUtil
|
|
18
|
-
|
|
19
|
-
const initData = [
|
|
20
|
-
{
|
|
21
|
-
total_money: 111,
|
|
22
|
-
id: 'T5991-JHD-2018-07-25-00027',
|
|
23
|
-
sku_money: '2390.00',
|
|
24
|
-
supplier_customer_id: 'LDP20180117',
|
|
25
|
-
submit_time: '2018-07-25',
|
|
26
|
-
status: 2,
|
|
27
|
-
supplier_name: '',
|
|
28
|
-
date_time: '2018-07-25',
|
|
29
|
-
delta_money: 0,
|
|
30
|
-
settle_supplier_id: 'T10953',
|
|
31
|
-
address: null
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
total_money: 176,
|
|
35
|
-
id: 'T5991-JHD-2018-07-25-00026',
|
|
36
|
-
sku_money: '176.00',
|
|
37
|
-
supplier_customer_id: 'A2926',
|
|
38
|
-
submit_time: '2018-07-26',
|
|
39
|
-
status: 2,
|
|
40
|
-
supplier_name: '段虎',
|
|
41
|
-
date_time: '2018-07-25',
|
|
42
|
-
delta_money: 0,
|
|
43
|
-
settle_supplier_id: 'T14319',
|
|
44
|
-
address: {
|
|
45
|
-
value: 9,
|
|
46
|
-
text: '西乡9'
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
total_money: 279,
|
|
51
|
-
id: 'T5991-JHD-2018-07-25-00025',
|
|
52
|
-
sku_money: '279.02',
|
|
53
|
-
supplier_customer_id: 'sc215',
|
|
54
|
-
submit_time: '2018-07-27',
|
|
55
|
-
status: 2,
|
|
56
|
-
supplier_name: '黑市桥蔬菜批发',
|
|
57
|
-
date_time: '2018-07-25',
|
|
58
|
-
delta_money: -2.0,
|
|
59
|
-
settle_supplier_id: 'T13324',
|
|
60
|
-
address: {
|
|
61
|
-
value: 4,
|
|
62
|
-
text: '宝安'
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
total_money: 176,
|
|
67
|
-
id: 'T5991-JHD-2018-07-25-00024',
|
|
68
|
-
sku_money: '279.02',
|
|
69
|
-
supplier_customer_id: 'sc215',
|
|
70
|
-
submit_time: '2018-07-27',
|
|
71
|
-
status: 2,
|
|
72
|
-
supplier_name: '黑市桥蔬菜批发',
|
|
73
|
-
date_time: '2018-07-25',
|
|
74
|
-
delta_money: -2.0,
|
|
75
|
-
settle_supplier_id: 'T13324',
|
|
76
|
-
address: {
|
|
77
|
-
value: 4,
|
|
78
|
-
text: '宝安'
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
]
|
|
82
|
-
|
|
83
|
-
const selectData = [
|
|
84
|
-
{
|
|
85
|
-
value: 1,
|
|
86
|
-
text: '南山'
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
value: 2,
|
|
90
|
-
text: '福田'
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
value: 3,
|
|
94
|
-
text: '罗湖'
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
value: 4,
|
|
98
|
-
text: '宝安'
|
|
99
|
-
}
|
|
100
|
-
]
|
|
101
|
-
|
|
102
|
-
const fixedColumns = [
|
|
103
|
-
{
|
|
104
|
-
Header: '序号',
|
|
105
|
-
accessor: 'index',
|
|
106
|
-
fixed: 'left',
|
|
107
|
-
width: 150,
|
|
108
|
-
Cell: ({ row }) => row.index + 1
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
Header: 'id',
|
|
112
|
-
accessor: 'id',
|
|
113
|
-
width: 100,
|
|
114
|
-
fixed: 'left'
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
Header: '地址',
|
|
118
|
-
accessor: 'address.text',
|
|
119
|
-
fixed: 'left',
|
|
120
|
-
width: 100 // 定宽
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
Header: 'sku_money',
|
|
124
|
-
width: 200,
|
|
125
|
-
accessor: 'sku_money'
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
Header: 'supplier_customer_id',
|
|
129
|
-
width: 200,
|
|
130
|
-
accessor: 'supplier_customer_id'
|
|
131
|
-
},
|
|
132
|
-
{
|
|
133
|
-
Header: 'submit_time',
|
|
134
|
-
minWidth: 100,
|
|
135
|
-
accessor: 'submit_time'
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
Header: 'delta_money',
|
|
139
|
-
width: 100,
|
|
140
|
-
accessor: 'delta_money'
|
|
141
|
-
},
|
|
142
|
-
{
|
|
143
|
-
Header: '供应商信息',
|
|
144
|
-
width: 100,
|
|
145
|
-
fixed: 'right',
|
|
146
|
-
accessor: data => data.supplier_name,
|
|
147
|
-
id: 'supplier_name'
|
|
148
|
-
},
|
|
149
|
-
{
|
|
150
|
-
Header: '入库金额',
|
|
151
|
-
accessor: 'total_money',
|
|
152
|
-
width: 100,
|
|
153
|
-
fixed: 'right',
|
|
154
|
-
Cell: cellProps => {
|
|
155
|
-
const { row } = cellProps
|
|
156
|
-
return <div>{row.original.total_money}</div>
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
]
|
|
160
|
-
|
|
161
|
-
const columns = [
|
|
162
|
-
// 获取索引
|
|
163
|
-
{
|
|
164
|
-
Header: '序号',
|
|
165
|
-
accessor: 'index',
|
|
166
|
-
fixed: 'left',
|
|
167
|
-
width: TABLE_X.WIDTH_NO,
|
|
168
|
-
Cell: ({ row }) => row.index + 1
|
|
169
|
-
},
|
|
170
|
-
// 常规用法
|
|
171
|
-
{
|
|
172
|
-
Header: 'id',
|
|
173
|
-
accessor: 'id',
|
|
174
|
-
fixed: 'left'
|
|
175
|
-
},
|
|
176
|
-
// accessor 有点用法
|
|
177
|
-
{
|
|
178
|
-
Header: '地址',
|
|
179
|
-
accessor: 'address.text',
|
|
180
|
-
width: 200 // 定宽
|
|
181
|
-
},
|
|
182
|
-
// accessor 是 func,需要提供 id
|
|
183
|
-
{
|
|
184
|
-
Header: '供应商信息',
|
|
185
|
-
accessor: data => data.supplier_name,
|
|
186
|
-
id: 'supplier_name'
|
|
187
|
-
},
|
|
188
|
-
// 自定义整个单元格
|
|
189
|
-
{
|
|
190
|
-
Header: '入库金额',
|
|
191
|
-
accessor: 'total_money',
|
|
192
|
-
fixed: 'right',
|
|
193
|
-
Cell: cellProps => {
|
|
194
|
-
const { row } = cellProps
|
|
195
|
-
return <div>{row.original.total_money}</div>
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
]
|
|
199
|
-
|
|
200
|
-
const editColumns = [
|
|
201
|
-
{
|
|
202
|
-
id: 'no',
|
|
203
|
-
Header: '序号',
|
|
204
|
-
fixed: 'left',
|
|
205
|
-
width: TABLE_X.WIDTH_NO,
|
|
206
|
-
maxWidth: TABLE_X.WIDTH_NO,
|
|
207
|
-
Cell: ({ row }) => row.index + 1
|
|
208
|
-
},
|
|
209
|
-
{
|
|
210
|
-
id: 'operation',
|
|
211
|
-
Header: () => <OperationHeader />,
|
|
212
|
-
fixed: 'left',
|
|
213
|
-
width: TABLE_X.WIDTH_OPERATION,
|
|
214
|
-
maxWidth: TABLE_X.WIDTH_OPERATION,
|
|
215
|
-
Cell: (
|
|
216
|
-
{ row: { index } } // eslint-disable-line
|
|
217
|
-
) => (
|
|
218
|
-
<EditOperation
|
|
219
|
-
onAddRow={
|
|
220
|
-
index !== 2 ? () => console.log('增加一行', index) : undefined
|
|
221
|
-
}
|
|
222
|
-
onDeleteRow={
|
|
223
|
-
index !== 1 ? () => console.log('删除一行', index) : undefined
|
|
224
|
-
}
|
|
225
|
-
/>
|
|
226
|
-
)
|
|
227
|
-
},
|
|
228
|
-
{
|
|
229
|
-
Header: '地址',
|
|
230
|
-
width: TABLE_X.WIDTH_SEARCH,
|
|
231
|
-
minWidth: TABLE_X.WIDTH_SEARCH,
|
|
232
|
-
Cell: ({ row: { index, original } }) => (
|
|
233
|
-
<MoreSelect
|
|
234
|
-
data={selectData}
|
|
235
|
-
selected={original.address}
|
|
236
|
-
onSelect={selected => console.log(selected, index)}
|
|
237
|
-
/>
|
|
238
|
-
)
|
|
239
|
-
},
|
|
240
|
-
{
|
|
241
|
-
Header: '入库金额',
|
|
242
|
-
width: TABLE_X.WIDTH_NUMBER,
|
|
243
|
-
minWidth: TABLE_X.WIDTH_NUMBER,
|
|
244
|
-
Cell: ({ row: { index, original } }) => (
|
|
245
|
-
<InputNumberV2
|
|
246
|
-
value={original.total_money}
|
|
247
|
-
onChange={value => console.log(value, index)}
|
|
248
|
-
/>
|
|
249
|
-
)
|
|
250
|
-
},
|
|
251
|
-
{
|
|
252
|
-
Header: 'sku_money',
|
|
253
|
-
width: TABLE_X.WIDTH_NUMBER,
|
|
254
|
-
minWidth: TABLE_X.WIDTH_NUMBER,
|
|
255
|
-
Cell: ({ row: { index, original } }) => (
|
|
256
|
-
<input
|
|
257
|
-
className='gm-input'
|
|
258
|
-
value={original.sku_money}
|
|
259
|
-
onChange={value => console.log(value, index)}
|
|
260
|
-
/>
|
|
261
|
-
)
|
|
262
|
-
}
|
|
263
|
-
]
|
|
264
|
-
|
|
265
|
-
const diyColumns = [
|
|
266
|
-
// 常规用法,column默认diy开启
|
|
267
|
-
{
|
|
268
|
-
Header: '序号',
|
|
269
|
-
accessor: 'index',
|
|
270
|
-
diyGroupName: '基础',
|
|
271
|
-
Cell: ({ row }) => row.index + 1
|
|
272
|
-
},
|
|
273
|
-
// 常规用法
|
|
274
|
-
{
|
|
275
|
-
Header: 'id',
|
|
276
|
-
accessor: 'id',
|
|
277
|
-
diyEnable: true,
|
|
278
|
-
diyGroupName: '基础'
|
|
279
|
-
},
|
|
280
|
-
// 该column不允许diy
|
|
281
|
-
{
|
|
282
|
-
Header: '地址',
|
|
283
|
-
accessor: 'address.text',
|
|
284
|
-
diyEnable: false,
|
|
285
|
-
diyGroupName: '基础'
|
|
286
|
-
},
|
|
287
|
-
// 其他diyGroup
|
|
288
|
-
{
|
|
289
|
-
Header: '供应商信息',
|
|
290
|
-
accessor: data => data.supplier_name,
|
|
291
|
-
id: 'supplier_name',
|
|
292
|
-
diyGroupName: '其他'
|
|
293
|
-
},
|
|
294
|
-
// 初始花的时候不显示该column
|
|
295
|
-
{
|
|
296
|
-
show: false,
|
|
297
|
-
diyGroupName: '其他',
|
|
298
|
-
diyEnable: true,
|
|
299
|
-
Header: '入库金额',
|
|
300
|
-
accessor: 'total_money',
|
|
301
|
-
Cell: cellProps => {
|
|
302
|
-
const { row } = cellProps
|
|
303
|
-
return <div>{row.original.total_money}</div>
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
]
|
|
307
|
-
|
|
308
|
-
const store = observable({
|
|
309
|
-
data: initData.slice(),
|
|
310
|
-
setData(data) {
|
|
311
|
-
this.data = data
|
|
312
|
-
},
|
|
313
|
-
selected: [],
|
|
314
|
-
setSelected(selected) {
|
|
315
|
-
console.log(selected)
|
|
316
|
-
this.selected = selected
|
|
317
|
-
},
|
|
318
|
-
selectAll: false,
|
|
319
|
-
setSelectAll(checked) {
|
|
320
|
-
this.selectAll = checked
|
|
321
|
-
},
|
|
322
|
-
diyColumns: diyColumns
|
|
323
|
-
})
|
|
324
|
-
|
|
325
|
-
const FixedColumnTableX = fixedColumnsTableXHOC(TableX)
|
|
326
|
-
const SortableTableX = sortableTableXHOC(TableX)
|
|
327
|
-
const EditTableX = editTableXHOC(TableX)
|
|
328
|
-
const DiyTableX = diyTableXHOC(TableX)
|
|
329
|
-
|
|
330
|
-
const virtualizedStore = observable({
|
|
331
|
-
data: _.times(20, index => ({
|
|
332
|
-
id: index,
|
|
333
|
-
name: 'lalalla'
|
|
334
|
-
})),
|
|
335
|
-
addData() {
|
|
336
|
-
this.data.push({
|
|
337
|
-
id: this.data.length,
|
|
338
|
-
name: 'lalala'
|
|
339
|
-
})
|
|
340
|
-
}
|
|
341
|
-
})
|
|
342
|
-
|
|
343
|
-
const virtualizedColumn = [
|
|
344
|
-
{
|
|
345
|
-
Header: '序号',
|
|
346
|
-
accessor: 'id'
|
|
347
|
-
},
|
|
348
|
-
{
|
|
349
|
-
Header: 'name',
|
|
350
|
-
accessor: 'name'
|
|
351
|
-
}
|
|
352
|
-
]
|
|
353
|
-
|
|
354
|
-
const VirtualizedWrap = observer(() => {
|
|
355
|
-
const [highLightIndex, setIndex] = React.useState(-1)
|
|
356
|
-
const ref = React.useRef(null)
|
|
357
|
-
|
|
358
|
-
const limit = 5
|
|
359
|
-
const height =
|
|
360
|
-
TABLE_X.HEIGHT_HEAD_TR +
|
|
361
|
-
Math.min(limit, virtualizedStore.data.length) * TABLE_X.HEIGHT_TR
|
|
362
|
-
|
|
363
|
-
return (
|
|
364
|
-
<div>
|
|
365
|
-
<div>
|
|
366
|
-
<button onClick={() => virtualizedStore.addData()}>+1 data</button>
|
|
367
|
-
<button
|
|
368
|
-
onClick={() => {
|
|
369
|
-
setIndex(10)
|
|
370
|
-
ref.current.scrollToItem(11, 'center')
|
|
371
|
-
}}
|
|
372
|
-
>
|
|
373
|
-
滚到第10行
|
|
374
|
-
</button>
|
|
375
|
-
</div>
|
|
376
|
-
<TableXVirtualized
|
|
377
|
-
refVirtualized={ref}
|
|
378
|
-
isTrHighlight={(item, index) => index === highLightIndex}
|
|
379
|
-
data={virtualizedStore.data.slice()}
|
|
380
|
-
columns={virtualizedColumn}
|
|
381
|
-
virtualizedHeight={height}
|
|
382
|
-
virtualizedItemSize={TableXUtil.TABLE_X.HEIGHT_TR}
|
|
383
|
-
/>
|
|
384
|
-
</div>
|
|
385
|
-
)
|
|
386
|
-
})
|
|
387
|
-
|
|
388
|
-
storiesOf('TableX|HOC', module)
|
|
389
|
-
.add('fixed column', () => (
|
|
390
|
-
<FixedColumnTableX data={store.data} columns={fixedColumns} />
|
|
391
|
-
))
|
|
392
|
-
.add('sortable', () => (
|
|
393
|
-
<SortableTableX
|
|
394
|
-
data={store.data.slice()}
|
|
395
|
-
columns={columns}
|
|
396
|
-
keyField='id'
|
|
397
|
-
onSortChange={newData => {
|
|
398
|
-
console.log(newData.map(v => v.id))
|
|
399
|
-
store.setData(newData)
|
|
400
|
-
}}
|
|
401
|
-
/>
|
|
402
|
-
))
|
|
403
|
-
.add('virtualized', () => <VirtualizedWrap />)
|
|
404
|
-
.add('edit', () => <EditTableX data={store.data} columns={editColumns} />)
|
|
405
|
-
.add('diy', () => {
|
|
406
|
-
return (
|
|
407
|
-
<div>
|
|
408
|
-
<button
|
|
409
|
-
onClick={() =>
|
|
410
|
-
(store.diyColumns = store.diyColumns.map(o => ({
|
|
411
|
-
...o,
|
|
412
|
-
Header: '改变header'
|
|
413
|
-
})))
|
|
414
|
-
}
|
|
415
|
-
>
|
|
416
|
-
改变组件的columns
|
|
417
|
-
</button>
|
|
418
|
-
<DiyTableX
|
|
419
|
-
className='gm-margin-top-20'
|
|
420
|
-
id='diy_must_have_id'
|
|
421
|
-
diyGroupSorting={['基础', '其他']}
|
|
422
|
-
data={store.data}
|
|
423
|
-
columns={store.diyColumns}
|
|
424
|
-
/>
|
|
425
|
-
</div>
|
|
426
|
-
)
|
|
427
|
-
})
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { storiesOf } from '@storybook/react'
|
|
3
|
+
import { observable } from 'mobx'
|
|
4
|
+
import { observer } from 'mobx-react'
|
|
5
|
+
import {
|
|
6
|
+
fixedColumnsTableXHOC,
|
|
7
|
+
sortableTableXHOC,
|
|
8
|
+
editTableXHOC,
|
|
9
|
+
diyTableXHOC,
|
|
10
|
+
TableX,
|
|
11
|
+
TableXVirtualized,
|
|
12
|
+
TableXUtil
|
|
13
|
+
} from '../index'
|
|
14
|
+
import _ from 'lodash'
|
|
15
|
+
import { InputNumberV2, MoreSelect } from '@gmfe/react'
|
|
16
|
+
|
|
17
|
+
const { TABLE_X, OperationHeader, EditOperation } = TableXUtil
|
|
18
|
+
|
|
19
|
+
const initData = [
|
|
20
|
+
{
|
|
21
|
+
total_money: 111,
|
|
22
|
+
id: 'T5991-JHD-2018-07-25-00027',
|
|
23
|
+
sku_money: '2390.00',
|
|
24
|
+
supplier_customer_id: 'LDP20180117',
|
|
25
|
+
submit_time: '2018-07-25',
|
|
26
|
+
status: 2,
|
|
27
|
+
supplier_name: '',
|
|
28
|
+
date_time: '2018-07-25',
|
|
29
|
+
delta_money: 0,
|
|
30
|
+
settle_supplier_id: 'T10953',
|
|
31
|
+
address: null
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
total_money: 176,
|
|
35
|
+
id: 'T5991-JHD-2018-07-25-00026',
|
|
36
|
+
sku_money: '176.00',
|
|
37
|
+
supplier_customer_id: 'A2926',
|
|
38
|
+
submit_time: '2018-07-26',
|
|
39
|
+
status: 2,
|
|
40
|
+
supplier_name: '段虎',
|
|
41
|
+
date_time: '2018-07-25',
|
|
42
|
+
delta_money: 0,
|
|
43
|
+
settle_supplier_id: 'T14319',
|
|
44
|
+
address: {
|
|
45
|
+
value: 9,
|
|
46
|
+
text: '西乡9'
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
total_money: 279,
|
|
51
|
+
id: 'T5991-JHD-2018-07-25-00025',
|
|
52
|
+
sku_money: '279.02',
|
|
53
|
+
supplier_customer_id: 'sc215',
|
|
54
|
+
submit_time: '2018-07-27',
|
|
55
|
+
status: 2,
|
|
56
|
+
supplier_name: '黑市桥蔬菜批发',
|
|
57
|
+
date_time: '2018-07-25',
|
|
58
|
+
delta_money: -2.0,
|
|
59
|
+
settle_supplier_id: 'T13324',
|
|
60
|
+
address: {
|
|
61
|
+
value: 4,
|
|
62
|
+
text: '宝安'
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
total_money: 176,
|
|
67
|
+
id: 'T5991-JHD-2018-07-25-00024',
|
|
68
|
+
sku_money: '279.02',
|
|
69
|
+
supplier_customer_id: 'sc215',
|
|
70
|
+
submit_time: '2018-07-27',
|
|
71
|
+
status: 2,
|
|
72
|
+
supplier_name: '黑市桥蔬菜批发',
|
|
73
|
+
date_time: '2018-07-25',
|
|
74
|
+
delta_money: -2.0,
|
|
75
|
+
settle_supplier_id: 'T13324',
|
|
76
|
+
address: {
|
|
77
|
+
value: 4,
|
|
78
|
+
text: '宝安'
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
|
|
83
|
+
const selectData = [
|
|
84
|
+
{
|
|
85
|
+
value: 1,
|
|
86
|
+
text: '南山'
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
value: 2,
|
|
90
|
+
text: '福田'
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
value: 3,
|
|
94
|
+
text: '罗湖'
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
value: 4,
|
|
98
|
+
text: '宝安'
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
|
|
102
|
+
const fixedColumns = [
|
|
103
|
+
{
|
|
104
|
+
Header: '序号',
|
|
105
|
+
accessor: 'index',
|
|
106
|
+
fixed: 'left',
|
|
107
|
+
width: 150,
|
|
108
|
+
Cell: ({ row }) => row.index + 1
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
Header: 'id',
|
|
112
|
+
accessor: 'id',
|
|
113
|
+
width: 100,
|
|
114
|
+
fixed: 'left'
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
Header: '地址',
|
|
118
|
+
accessor: 'address.text',
|
|
119
|
+
fixed: 'left',
|
|
120
|
+
width: 100 // 定宽
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
Header: 'sku_money',
|
|
124
|
+
width: 200,
|
|
125
|
+
accessor: 'sku_money'
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
Header: 'supplier_customer_id',
|
|
129
|
+
width: 200,
|
|
130
|
+
accessor: 'supplier_customer_id'
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
Header: 'submit_time',
|
|
134
|
+
minWidth: 100,
|
|
135
|
+
accessor: 'submit_time'
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
Header: 'delta_money',
|
|
139
|
+
width: 100,
|
|
140
|
+
accessor: 'delta_money'
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
Header: '供应商信息',
|
|
144
|
+
width: 100,
|
|
145
|
+
fixed: 'right',
|
|
146
|
+
accessor: data => data.supplier_name,
|
|
147
|
+
id: 'supplier_name'
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
Header: '入库金额',
|
|
151
|
+
accessor: 'total_money',
|
|
152
|
+
width: 100,
|
|
153
|
+
fixed: 'right',
|
|
154
|
+
Cell: cellProps => {
|
|
155
|
+
const { row } = cellProps
|
|
156
|
+
return <div>{row.original.total_money}</div>
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
]
|
|
160
|
+
|
|
161
|
+
const columns = [
|
|
162
|
+
// 获取索引
|
|
163
|
+
{
|
|
164
|
+
Header: '序号',
|
|
165
|
+
accessor: 'index',
|
|
166
|
+
fixed: 'left',
|
|
167
|
+
width: TABLE_X.WIDTH_NO,
|
|
168
|
+
Cell: ({ row }) => row.index + 1
|
|
169
|
+
},
|
|
170
|
+
// 常规用法
|
|
171
|
+
{
|
|
172
|
+
Header: 'id',
|
|
173
|
+
accessor: 'id',
|
|
174
|
+
fixed: 'left'
|
|
175
|
+
},
|
|
176
|
+
// accessor 有点用法
|
|
177
|
+
{
|
|
178
|
+
Header: '地址',
|
|
179
|
+
accessor: 'address.text',
|
|
180
|
+
width: 200 // 定宽
|
|
181
|
+
},
|
|
182
|
+
// accessor 是 func,需要提供 id
|
|
183
|
+
{
|
|
184
|
+
Header: '供应商信息',
|
|
185
|
+
accessor: data => data.supplier_name,
|
|
186
|
+
id: 'supplier_name'
|
|
187
|
+
},
|
|
188
|
+
// 自定义整个单元格
|
|
189
|
+
{
|
|
190
|
+
Header: '入库金额',
|
|
191
|
+
accessor: 'total_money',
|
|
192
|
+
fixed: 'right',
|
|
193
|
+
Cell: cellProps => {
|
|
194
|
+
const { row } = cellProps
|
|
195
|
+
return <div>{row.original.total_money}</div>
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
]
|
|
199
|
+
|
|
200
|
+
const editColumns = [
|
|
201
|
+
{
|
|
202
|
+
id: 'no',
|
|
203
|
+
Header: '序号',
|
|
204
|
+
fixed: 'left',
|
|
205
|
+
width: TABLE_X.WIDTH_NO,
|
|
206
|
+
maxWidth: TABLE_X.WIDTH_NO,
|
|
207
|
+
Cell: ({ row }) => row.index + 1
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
id: 'operation',
|
|
211
|
+
Header: () => <OperationHeader />,
|
|
212
|
+
fixed: 'left',
|
|
213
|
+
width: TABLE_X.WIDTH_OPERATION,
|
|
214
|
+
maxWidth: TABLE_X.WIDTH_OPERATION,
|
|
215
|
+
Cell: (
|
|
216
|
+
{ row: { index } } // eslint-disable-line
|
|
217
|
+
) => (
|
|
218
|
+
<EditOperation
|
|
219
|
+
onAddRow={
|
|
220
|
+
index !== 2 ? () => console.log('增加一行', index) : undefined
|
|
221
|
+
}
|
|
222
|
+
onDeleteRow={
|
|
223
|
+
index !== 1 ? () => console.log('删除一行', index) : undefined
|
|
224
|
+
}
|
|
225
|
+
/>
|
|
226
|
+
)
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
Header: '地址',
|
|
230
|
+
width: TABLE_X.WIDTH_SEARCH,
|
|
231
|
+
minWidth: TABLE_X.WIDTH_SEARCH,
|
|
232
|
+
Cell: ({ row: { index, original } }) => (
|
|
233
|
+
<MoreSelect
|
|
234
|
+
data={selectData}
|
|
235
|
+
selected={original.address}
|
|
236
|
+
onSelect={selected => console.log(selected, index)}
|
|
237
|
+
/>
|
|
238
|
+
)
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
Header: '入库金额',
|
|
242
|
+
width: TABLE_X.WIDTH_NUMBER,
|
|
243
|
+
minWidth: TABLE_X.WIDTH_NUMBER,
|
|
244
|
+
Cell: ({ row: { index, original } }) => (
|
|
245
|
+
<InputNumberV2
|
|
246
|
+
value={original.total_money}
|
|
247
|
+
onChange={value => console.log(value, index)}
|
|
248
|
+
/>
|
|
249
|
+
)
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
Header: 'sku_money',
|
|
253
|
+
width: TABLE_X.WIDTH_NUMBER,
|
|
254
|
+
minWidth: TABLE_X.WIDTH_NUMBER,
|
|
255
|
+
Cell: ({ row: { index, original } }) => (
|
|
256
|
+
<input
|
|
257
|
+
className='gm-input'
|
|
258
|
+
value={original.sku_money}
|
|
259
|
+
onChange={value => console.log(value, index)}
|
|
260
|
+
/>
|
|
261
|
+
)
|
|
262
|
+
}
|
|
263
|
+
]
|
|
264
|
+
|
|
265
|
+
const diyColumns = [
|
|
266
|
+
// 常规用法,column默认diy开启
|
|
267
|
+
{
|
|
268
|
+
Header: '序号',
|
|
269
|
+
accessor: 'index',
|
|
270
|
+
diyGroupName: '基础',
|
|
271
|
+
Cell: ({ row }) => row.index + 1
|
|
272
|
+
},
|
|
273
|
+
// 常规用法
|
|
274
|
+
{
|
|
275
|
+
Header: 'id',
|
|
276
|
+
accessor: 'id',
|
|
277
|
+
diyEnable: true,
|
|
278
|
+
diyGroupName: '基础'
|
|
279
|
+
},
|
|
280
|
+
// 该column不允许diy
|
|
281
|
+
{
|
|
282
|
+
Header: '地址',
|
|
283
|
+
accessor: 'address.text',
|
|
284
|
+
diyEnable: false,
|
|
285
|
+
diyGroupName: '基础'
|
|
286
|
+
},
|
|
287
|
+
// 其他diyGroup
|
|
288
|
+
{
|
|
289
|
+
Header: '供应商信息',
|
|
290
|
+
accessor: data => data.supplier_name,
|
|
291
|
+
id: 'supplier_name',
|
|
292
|
+
diyGroupName: '其他'
|
|
293
|
+
},
|
|
294
|
+
// 初始花的时候不显示该column
|
|
295
|
+
{
|
|
296
|
+
show: false,
|
|
297
|
+
diyGroupName: '其他',
|
|
298
|
+
diyEnable: true,
|
|
299
|
+
Header: '入库金额',
|
|
300
|
+
accessor: 'total_money',
|
|
301
|
+
Cell: cellProps => {
|
|
302
|
+
const { row } = cellProps
|
|
303
|
+
return <div>{row.original.total_money}</div>
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
]
|
|
307
|
+
|
|
308
|
+
const store = observable({
|
|
309
|
+
data: initData.slice(),
|
|
310
|
+
setData(data) {
|
|
311
|
+
this.data = data
|
|
312
|
+
},
|
|
313
|
+
selected: [],
|
|
314
|
+
setSelected(selected) {
|
|
315
|
+
console.log(selected)
|
|
316
|
+
this.selected = selected
|
|
317
|
+
},
|
|
318
|
+
selectAll: false,
|
|
319
|
+
setSelectAll(checked) {
|
|
320
|
+
this.selectAll = checked
|
|
321
|
+
},
|
|
322
|
+
diyColumns: diyColumns
|
|
323
|
+
})
|
|
324
|
+
|
|
325
|
+
const FixedColumnTableX = fixedColumnsTableXHOC(TableX)
|
|
326
|
+
const SortableTableX = sortableTableXHOC(TableX)
|
|
327
|
+
const EditTableX = editTableXHOC(TableX)
|
|
328
|
+
const DiyTableX = diyTableXHOC(TableX)
|
|
329
|
+
|
|
330
|
+
const virtualizedStore = observable({
|
|
331
|
+
data: _.times(20, index => ({
|
|
332
|
+
id: index,
|
|
333
|
+
name: 'lalalla'
|
|
334
|
+
})),
|
|
335
|
+
addData() {
|
|
336
|
+
this.data.push({
|
|
337
|
+
id: this.data.length,
|
|
338
|
+
name: 'lalala'
|
|
339
|
+
})
|
|
340
|
+
}
|
|
341
|
+
})
|
|
342
|
+
|
|
343
|
+
const virtualizedColumn = [
|
|
344
|
+
{
|
|
345
|
+
Header: '序号',
|
|
346
|
+
accessor: 'id'
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
Header: 'name',
|
|
350
|
+
accessor: 'name'
|
|
351
|
+
}
|
|
352
|
+
]
|
|
353
|
+
|
|
354
|
+
const VirtualizedWrap = observer(() => {
|
|
355
|
+
const [highLightIndex, setIndex] = React.useState(-1)
|
|
356
|
+
const ref = React.useRef(null)
|
|
357
|
+
|
|
358
|
+
const limit = 5
|
|
359
|
+
const height =
|
|
360
|
+
TABLE_X.HEIGHT_HEAD_TR +
|
|
361
|
+
Math.min(limit, virtualizedStore.data.length) * TABLE_X.HEIGHT_TR
|
|
362
|
+
|
|
363
|
+
return (
|
|
364
|
+
<div>
|
|
365
|
+
<div>
|
|
366
|
+
<button onClick={() => virtualizedStore.addData()}>+1 data</button>
|
|
367
|
+
<button
|
|
368
|
+
onClick={() => {
|
|
369
|
+
setIndex(10)
|
|
370
|
+
ref.current.scrollToItem(11, 'center')
|
|
371
|
+
}}
|
|
372
|
+
>
|
|
373
|
+
滚到第10行
|
|
374
|
+
</button>
|
|
375
|
+
</div>
|
|
376
|
+
<TableXVirtualized
|
|
377
|
+
refVirtualized={ref}
|
|
378
|
+
isTrHighlight={(item, index) => index === highLightIndex}
|
|
379
|
+
data={virtualizedStore.data.slice()}
|
|
380
|
+
columns={virtualizedColumn}
|
|
381
|
+
virtualizedHeight={height}
|
|
382
|
+
virtualizedItemSize={TableXUtil.TABLE_X.HEIGHT_TR}
|
|
383
|
+
/>
|
|
384
|
+
</div>
|
|
385
|
+
)
|
|
386
|
+
})
|
|
387
|
+
|
|
388
|
+
storiesOf('TableX|HOC', module)
|
|
389
|
+
.add('fixed column', () => (
|
|
390
|
+
<FixedColumnTableX data={store.data} columns={fixedColumns} />
|
|
391
|
+
))
|
|
392
|
+
.add('sortable', () => (
|
|
393
|
+
<SortableTableX
|
|
394
|
+
data={store.data.slice()}
|
|
395
|
+
columns={columns}
|
|
396
|
+
keyField='id'
|
|
397
|
+
onSortChange={newData => {
|
|
398
|
+
console.log(newData.map(v => v.id))
|
|
399
|
+
store.setData(newData)
|
|
400
|
+
}}
|
|
401
|
+
/>
|
|
402
|
+
))
|
|
403
|
+
.add('virtualized', () => <VirtualizedWrap />)
|
|
404
|
+
.add('edit', () => <EditTableX data={store.data} columns={editColumns} />)
|
|
405
|
+
.add('diy', () => {
|
|
406
|
+
return (
|
|
407
|
+
<div>
|
|
408
|
+
<button
|
|
409
|
+
onClick={() =>
|
|
410
|
+
(store.diyColumns = store.diyColumns.map(o => ({
|
|
411
|
+
...o,
|
|
412
|
+
Header: '改变header'
|
|
413
|
+
})))
|
|
414
|
+
}
|
|
415
|
+
>
|
|
416
|
+
改变组件的columns
|
|
417
|
+
</button>
|
|
418
|
+
<DiyTableX
|
|
419
|
+
className='gm-margin-top-20'
|
|
420
|
+
id='diy_must_have_id'
|
|
421
|
+
diyGroupSorting={['基础', '其他']}
|
|
422
|
+
data={store.data}
|
|
423
|
+
columns={store.diyColumns}
|
|
424
|
+
/>
|
|
425
|
+
</div>
|
|
426
|
+
)
|
|
427
|
+
})
|