kts-component-invoice-operate 3.1.12 → 3.1.13

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 (115) hide show
  1. package/.dumi/theme/builtins/API.tsx +66 -66
  2. package/.editorconfig +16 -16
  3. package/.fatherrc.ts +4 -4
  4. package/.prettierignore +7 -7
  5. package/.prettierrc +11 -11
  6. package/.umirc.ts +8 -8
  7. package/README.md +5 -5
  8. package/dist/Invoice/ui/GoodsList/hook/useColumns/autoFillFn/index.d.ts +2 -0
  9. package/dist/index.esm.js +2754 -3920
  10. package/dist/index.js +2754 -3920
  11. package/docs/index.md +5 -5
  12. package/index.html +12 -12
  13. package/package.json +59 -59
  14. package/src/Invoice/InvoiceController/InvoiceControllerForm/index.ts +94 -94
  15. package/src/Invoice/InvoiceController/InvoiceControllerState/BuyerState/index.tsx +88 -88
  16. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/EndowCode/index.tsx +93 -93
  17. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/IColumnsReplenish/index.ts +10 -10
  18. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/IGood/index.ts +72 -72
  19. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/ImportGoods/index.ts +80 -80
  20. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/LineAttributeType/index.ts +5 -5
  21. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/ProductComparison/index.ts +9 -9
  22. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/index.ts +88 -88
  23. package/src/Invoice/InvoiceController/InvoiceControllerState/index.ts +48 -48
  24. package/src/Invoice/InvoiceController/fns/addGood.ts +11 -11
  25. package/src/Invoice/InvoiceController/fns/addGoodDiscount.ts +125 -125
  26. package/src/Invoice/InvoiceController/fns/delGood.ts +43 -43
  27. package/src/Invoice/InvoiceController/fns/getGoodsSearch.ts +23 -23
  28. package/src/Invoice/InvoiceController/fns/saveEditGood.ts +23 -23
  29. package/src/Invoice/InvoiceController/fns/setEditGood.ts +16 -16
  30. package/src/Invoice/InvoiceController/fns/setGoods.ts +10 -10
  31. package/src/Invoice/InvoiceController/fns/updateInvoiceNo.ts +8 -8
  32. package/src/Invoice/InvoiceController/index.ts +61 -61
  33. package/src/Invoice/_test/buyerNameSearch/index.tsx +41 -41
  34. package/src/Invoice/_test/deduction/index.tsx +935 -935
  35. package/src/Invoice/_test/draft/index.tsx +40 -40
  36. package/src/Invoice/_test/easiest/index.tsx +5 -5
  37. package/src/Invoice/_test/endowCode/index.tsx +1095 -1095
  38. package/src/Invoice/_test/goodsMenuExpand/index.tsx +32 -32
  39. package/src/Invoice/_test/importBuyer/index.tsx +74 -74
  40. package/src/Invoice/_test/importGoods/index.tsx +515 -515
  41. package/src/Invoice/_test/invoiceType/index.tsx +59 -59
  42. package/src/Invoice/_test/isInvoiceNo/index.tsx +12 -12
  43. package/src/Invoice/_test/replaceHead/index.tsx +22 -22
  44. package/src/Invoice/_test/retrieveData/index.tsx +22 -22
  45. package/src/Invoice/_test/seller/index.tsx +28 -28
  46. package/src/Invoice/_test/setDataSource/index.tsx +22 -22
  47. package/src/Invoice/_test/unit/index.tsx +19 -19
  48. package/src/Invoice/index.less +12 -12
  49. package/src/Invoice/index.md +53 -53
  50. package/src/Invoice/index.tsx +104 -104
  51. package/src/Invoice/tools/calculate/index.ts +97 -97
  52. package/src/Invoice/tools/coolingFn/index.ts +17 -17
  53. package/src/Invoice/tools/evaluate/index.ts +7 -7
  54. package/src/Invoice/tools/idGenerator/index.ts +2 -2
  55. package/src/Invoice/tools/itemName/index.ts +46 -46
  56. package/src/Invoice/tools/lazyFn/index.ts +19 -19
  57. package/src/Invoice/tools/strringFn/index.ts +40 -40
  58. package/src/Invoice/ui/AddComparisonDrawer/index.tsx +149 -149
  59. package/src/Invoice/ui/Buyer/index.less +219 -219
  60. package/src/Invoice/ui/Buyer/index.tsx +114 -114
  61. package/src/Invoice/ui/Buyer/ui/BuyerNameInput/index.tsx +166 -166
  62. package/src/Invoice/ui/Buyer/ui/ImportBuyerButton/index.tsx +21 -21
  63. package/src/Invoice/ui/EndowCodeDrawer/index.less +8 -8
  64. package/src/Invoice/ui/EndowCodeDrawer/index.tsx +445 -445
  65. package/src/Invoice/ui/GoodsList/hook/useColumns/autoFillFn/index.ts +513 -496
  66. package/src/Invoice/ui/GoodsList/hook/useColumns/index.tsx +618 -606
  67. package/src/Invoice/ui/GoodsList/hook/useColumns/ui/ItemNameInput/index.less +9 -9
  68. package/src/Invoice/ui/GoodsList/hook/useColumns/ui/ItemNameInput/index.tsx +34 -34
  69. package/src/Invoice/ui/GoodsList/hook/useColumns/ui/RowEditButton/index.tsx +30 -30
  70. package/src/Invoice/ui/GoodsList/hook/useColumns/ui/RowMenu/hook/_useAddComparison/index.tsx +43 -43
  71. package/src/Invoice/ui/GoodsList/hook/useColumns/ui/RowMenu/hook/useAddDiscount/index.tsx +76 -76
  72. package/src/Invoice/ui/GoodsList/hook/useColumns/ui/RowMenu/hook/useDelItem/index.tsx +35 -35
  73. package/src/Invoice/ui/GoodsList/hook/useColumns/ui/RowMenu/hook/useEndowCode/index.tsx +34 -34
  74. package/src/Invoice/ui/GoodsList/hook/useColumns/ui/RowMenu/index.less +13 -13
  75. package/src/Invoice/ui/GoodsList/hook/useColumns/ui/RowMenu/index.tsx +98 -98
  76. package/src/Invoice/ui/GoodsList/hook/useColumns/ui/RowSaveButton/index.tsx +14 -14
  77. package/src/Invoice/ui/GoodsList/hook/useColumns/ui/TitleText/index.tsx +20 -20
  78. package/src/Invoice/ui/GoodsList/hook/useDeduction/index.tsx +24 -24
  79. package/src/Invoice/ui/GoodsList/hook/useOnRow/index.tsx +39 -39
  80. package/src/Invoice/ui/GoodsList/hook/useRowSelection/index.tsx +111 -111
  81. package/src/Invoice/ui/GoodsList/hook/useToGenerateId/index.ts +8 -8
  82. package/src/Invoice/ui/GoodsList/hook/useWindowClick/index.tsx +23 -23
  83. package/src/Invoice/ui/GoodsList/index.less +177 -177
  84. package/src/Invoice/ui/GoodsList/index.tsx +177 -177
  85. package/src/Invoice/ui/GoodsList/ui/AddRowButton/index.tsx +61 -61
  86. package/src/Invoice/ui/GoodsList/ui/BulkMenu/hooks/useAddDiscountRowButton/index.less +21 -21
  87. package/src/Invoice/ui/GoodsList/ui/BulkMenu/hooks/useAddDiscountRowButton/index.tsx +244 -244
  88. package/src/Invoice/ui/GoodsList/ui/BulkMenu/hooks/useCommodityComparisonButton/index.tsx +75 -75
  89. package/src/Invoice/ui/GoodsList/ui/BulkMenu/hooks/useDelRowButton/index.tsx +66 -66
  90. package/src/Invoice/ui/GoodsList/ui/BulkMenu/hooks/useEndowCodeButton/index.tsx +58 -58
  91. package/src/Invoice/ui/GoodsList/ui/BulkMenu/index.tsx +37 -37
  92. package/src/Invoice/ui/GoodsList/ui/DescribeSwitch/index.tsx +36 -36
  93. package/src/Invoice/ui/GoodsList/ui/Search/index.less +10 -10
  94. package/src/Invoice/ui/GoodsList/ui/Search/index.tsx +50 -50
  95. package/src/Invoice/ui/GoodsList/ui/Statistics/index.less +18 -18
  96. package/src/Invoice/ui/GoodsList/ui/Statistics/index.tsx +109 -109
  97. package/src/Invoice/ui/GoodsList/ui/TableRow/index.tsx +29 -29
  98. package/src/Invoice/ui/GoodsList/ui/TableVirtual/index.less +38 -38
  99. package/src/Invoice/ui/GoodsList/ui/TableVirtual/index.tsx +105 -105
  100. package/src/Invoice/ui/GoodsList/ui/TableVirtual.o/index.less +44 -44
  101. package/src/Invoice/ui/GoodsList/ui/TableVirtual.o/index.tsx +96 -96
  102. package/src/Invoice/ui/GoodsList/ui/TaxIncludedSwitch/index.tsx +30 -30
  103. package/src/Invoice/ui/ImportBuyerDrawer/index.tsx +75 -75
  104. package/src/Invoice/ui/ImportGoodsDrawer/index.tsx +174 -174
  105. package/src/Invoice/ui/InvoiceHeader/index.less +68 -68
  106. package/src/Invoice/ui/InvoiceHeader/index.tsx +246 -246
  107. package/src/Invoice/ui/Seller/index.less +113 -113
  108. package/src/Invoice/ui/Seller/index.tsx +98 -98
  109. package/src/Invoice/ui/Sign/index.less +14 -14
  110. package/src/Invoice/ui/Sign/index.tsx +71 -71
  111. package/src/index.ts +6 -6
  112. package/tsconfig.json +31 -31
  113. package/typings.d.ts +3 -3
  114. package/yarn.e.lock +14331 -14331
  115. package/yarn.o.lock +14800 -14800
@@ -1,109 +1,109 @@
1
- import React from 'react';
2
- import { } from 'kts-components-antd-x3';
3
- import { chain, bignumber } from 'mathjs';
4
- import Invoice from '../../../../';
5
- import './index.less';
6
-
7
- const nzhcn = require('nzh').cn;
8
-
9
- export default () => {
10
- const controller = Invoice.useInvoiceController();
11
-
12
- /** 是否不含税) */
13
- const isTaxIncluded = controller.useMemo(s => s.goodsListState.isTaxIncluded, []);
14
-
15
- /** 金额(含税) */
16
- const lineAmountIncludeTax = controller.useMemo((s) => {
17
- if (typeof s.goodsListState.amountIncludeTax === 'number') {
18
- return s.goodsListState.amountIncludeTax
19
- }
20
-
21
- let sum = chain(bignumber(0));
22
- const editGood = s.goodsListState.editGood; // 正在编辑的货物
23
- const err = s.goodsListState.form?.getFieldsError() ?? {};
24
-
25
- s.goodsListState.goodsList.forEach((e) => {
26
- if (e.$index === editGood?.$index) {
27
- if (!err.lineAmountIncludeTax) {
28
- sum = sum.add(bignumber(editGood.lineAmountIncludeTax || 0));
29
- }
30
- } else {
31
- sum = sum.add(bignumber(e.lineAmountIncludeTax || 0));
32
- }
33
- });
34
- return sum.done().toNumber();
35
- }, []);
36
-
37
- /** 金额(不含税) */
38
- const lineAmountExcludeTax = controller.useMemo((s) => {
39
- if (typeof s.goodsListState.amountExcludeTax === 'number') {
40
- return s.goodsListState.amountExcludeTax
41
- }
42
-
43
- let sum = chain(bignumber(0));
44
- const editGood = s.goodsListState.editGood; // 正在编辑的货物
45
- const err = s.goodsListState.form?.getFieldsError() ?? {};
46
-
47
- s.goodsListState.goodsList.forEach((e) => {
48
- if (e.$index === editGood?.$index) {
49
- if (!err.lineAmountExcludeTax) {
50
- sum = sum.add(bignumber(editGood.lineAmountExcludeTax || 0));
51
- }
52
- } else {
53
- sum = sum.add(bignumber(e.lineAmountExcludeTax || 0));
54
- }
55
- });
56
- return sum.done().toNumber();
57
- }, []);
58
-
59
- /** 税额 */
60
- const taxAmount = controller.useMemo((s) => {
61
- if (typeof s.goodsListState.amountTax === 'number') {
62
- return s.goodsListState.amountTax;
63
- }
64
-
65
- let sum = chain(bignumber(0));
66
- const editGood = s.goodsListState.editGood; // 正在编辑的货物
67
- s.goodsListState.goodsList.forEach((e) => {
68
- if (e.$index === editGood?.$index) {
69
- sum = sum.add(bignumber(editGood.taxAmount || 0));
70
- } else {
71
- sum = sum.add(bignumber(e.taxAmount || 0));
72
- }
73
- });
74
- return sum.done().toNumber();
75
- }, []);
76
-
77
- return (
78
- <div className="kts-invoice-operate-goods-list-statistics">
79
- <div className="kts-invoice-operate-goods-list-statistics-row">
80
- <div style={{ width: 45.92 }} />
81
- <div style={{ flex: 1 }}>
82
- <label>合计</label>
83
- </div>
84
- <div style={{ width: 119, textAlign: 'right', border: 'none' }}>
85
- <label>
86
- {parseFloat(isTaxIncluded ? lineAmountIncludeTax : lineAmountExcludeTax).toFixed(2)}
87
- </label>
88
- </div>
89
- <div style={{ width: 70, border: 'none' }} />
90
- <div style={{ width: 119, textAlign: 'right', border: 'none' }}>
91
- <label>{parseFloat(taxAmount).toFixed(2)}</label>
92
- </div>
93
- <div style={{ width: 111, border: 'none' }} />
94
- </div>
95
- <div className="kts-invoice-operate-goods-list-statistics-row">
96
- <div style={{ width: 45.92 }} />
97
- <div style={{ flex: 5, border: 'none' }}>
98
- <label>价税合计(大写)</label>
99
- <label>
100
- {nzhcn.toMoney(lineAmountIncludeTax, { outSymbol: false })}
101
- </label>
102
- </div>
103
- <div style={{ flex: 5, border: 'none' }}>
104
- <label>(小写) {parseFloat(lineAmountIncludeTax).toFixed(2)}</label>
105
- </div>
106
- </div>
107
- </div>
108
- );
109
- };
1
+ import React from 'react';
2
+ import { } from 'kts-components-antd-x3';
3
+ import { chain, bignumber } from 'mathjs';
4
+ import Invoice from '../../../../';
5
+ import './index.less';
6
+
7
+ const nzhcn = require('nzh').cn;
8
+
9
+ export default () => {
10
+ const controller = Invoice.useInvoiceController();
11
+
12
+ /** 是否不含税) */
13
+ const isTaxIncluded = controller.useMemo(s => s.goodsListState.isTaxIncluded, []);
14
+
15
+ /** 金额(含税) */
16
+ const lineAmountIncludeTax = controller.useMemo((s) => {
17
+ if (typeof s.goodsListState.amountIncludeTax === 'number') {
18
+ return s.goodsListState.amountIncludeTax
19
+ }
20
+
21
+ let sum = chain(bignumber(0));
22
+ const editGood = s.goodsListState.editGood; // 正在编辑的货物
23
+ const err = s.goodsListState.form?.getFieldsError() ?? {};
24
+
25
+ s.goodsListState.goodsList.forEach((e) => {
26
+ if (e.$index === editGood?.$index) {
27
+ if (!err.lineAmountIncludeTax) {
28
+ sum = sum.add(bignumber(editGood.lineAmountIncludeTax || 0));
29
+ }
30
+ } else {
31
+ sum = sum.add(bignumber(e.lineAmountIncludeTax || 0));
32
+ }
33
+ });
34
+ return sum.done().toNumber();
35
+ }, []);
36
+
37
+ /** 金额(不含税) */
38
+ const lineAmountExcludeTax = controller.useMemo((s) => {
39
+ if (typeof s.goodsListState.amountExcludeTax === 'number') {
40
+ return s.goodsListState.amountExcludeTax
41
+ }
42
+
43
+ let sum = chain(bignumber(0));
44
+ const editGood = s.goodsListState.editGood; // 正在编辑的货物
45
+ const err = s.goodsListState.form?.getFieldsError() ?? {};
46
+
47
+ s.goodsListState.goodsList.forEach((e) => {
48
+ if (e.$index === editGood?.$index) {
49
+ if (!err.lineAmountExcludeTax) {
50
+ sum = sum.add(bignumber(editGood.lineAmountExcludeTax || 0));
51
+ }
52
+ } else {
53
+ sum = sum.add(bignumber(e.lineAmountExcludeTax || 0));
54
+ }
55
+ });
56
+ return sum.done().toNumber();
57
+ }, []);
58
+
59
+ /** 税额 */
60
+ const taxAmount = controller.useMemo((s) => {
61
+ if (typeof s.goodsListState.amountTax === 'number') {
62
+ return s.goodsListState.amountTax;
63
+ }
64
+
65
+ let sum = chain(bignumber(0));
66
+ const editGood = s.goodsListState.editGood; // 正在编辑的货物
67
+ s.goodsListState.goodsList.forEach((e) => {
68
+ if (e.$index === editGood?.$index) {
69
+ sum = sum.add(bignumber(editGood.taxAmount || 0));
70
+ } else {
71
+ sum = sum.add(bignumber(e.taxAmount || 0));
72
+ }
73
+ });
74
+ return sum.done().toNumber();
75
+ }, []);
76
+
77
+ return (
78
+ <div className="kts-invoice-operate-goods-list-statistics">
79
+ <div className="kts-invoice-operate-goods-list-statistics-row">
80
+ <div style={{ width: 45.92 }} />
81
+ <div style={{ flex: 1 }}>
82
+ <label>合计</label>
83
+ </div>
84
+ <div style={{ width: 119, textAlign: 'right', border: 'none' }}>
85
+ <label>
86
+ {parseFloat(isTaxIncluded ? lineAmountIncludeTax : lineAmountExcludeTax).toFixed(2)}
87
+ </label>
88
+ </div>
89
+ <div style={{ width: 70, border: 'none' }} />
90
+ <div style={{ width: 119, textAlign: 'right', border: 'none' }}>
91
+ <label>{parseFloat(taxAmount).toFixed(2)}</label>
92
+ </div>
93
+ <div style={{ width: 111, border: 'none' }} />
94
+ </div>
95
+ <div className="kts-invoice-operate-goods-list-statistics-row">
96
+ <div style={{ width: 45.92 }} />
97
+ <div style={{ flex: 5, border: 'none' }}>
98
+ <label>价税合计(大写)</label>
99
+ <label>
100
+ {nzhcn.toMoney(lineAmountIncludeTax, { outSymbol: false })}
101
+ </label>
102
+ </div>
103
+ <div style={{ flex: 5, border: 'none' }}>
104
+ <label>(小写) {parseFloat(lineAmountIncludeTax).toFixed(2)}</label>
105
+ </div>
106
+ </div>
107
+ </div>
108
+ );
109
+ };
@@ -1,30 +1,30 @@
1
- import React from "react";
2
- import Invoice from '../../../../';
3
- import { LineAttributeType } from '../../../../InvoiceController'
4
- import classnames from 'classnames'
5
-
6
- export default function TableRow(props: any) {
7
-
8
- const controller = Invoice.useInvoiceController();
9
-
10
- const goodsMap = controller.useMemo(s => s.goodsListState.goodsMap, [])
11
-
12
- const discount = React.useMemo(() => {
13
- const i = goodsMap.get(props['data-row-key']);
14
- if (!i) return undefined;
15
-
16
- if (i.lineAttribute === LineAttributeType.折扣行) {
17
- return 'kts-invoice-operate-goods-be-discount'
18
- } else if (i.lineAttribute === LineAttributeType.被折扣行) {
19
- return 'kts-invoice-operate-goods-discount'
20
- } else {
21
- return undefined;
22
- }
23
- }, [props['data-row-key'], goodsMap])
24
-
25
- console.log('===> discount', discount)
26
-
27
- return (
28
- <tr {...props} className={classnames(props.className, discount)} />
29
- )
1
+ import React from "react";
2
+ import Invoice from '../../../../';
3
+ import { LineAttributeType } from '../../../../InvoiceController'
4
+ import classnames from 'classnames'
5
+
6
+ export default function TableRow(props: any) {
7
+
8
+ const controller = Invoice.useInvoiceController();
9
+
10
+ const goodsMap = controller.useMemo(s => s.goodsListState.goodsMap, [])
11
+
12
+ const discount = React.useMemo(() => {
13
+ const i = goodsMap.get(props['data-row-key']);
14
+ if (!i) return undefined;
15
+
16
+ if (i.lineAttribute === LineAttributeType.折扣行) {
17
+ return 'kts-invoice-operate-goods-be-discount'
18
+ } else if (i.lineAttribute === LineAttributeType.被折扣行) {
19
+ return 'kts-invoice-operate-goods-discount'
20
+ } else {
21
+ return undefined;
22
+ }
23
+ }, [props['data-row-key'], goodsMap])
24
+
25
+ console.log('===> discount', discount)
26
+
27
+ return (
28
+ <tr {...props} className={classnames(props.className, discount)} />
29
+ )
30
30
  }
@@ -1,39 +1,39 @@
1
- .kts-invoice-operate-goods-table-virtual {
2
-
3
- .ktsAntX-table-body {
4
- height: 280px;
5
- }
6
-
7
- .ktsAntX-table.ktsAntX-table-bordered>.ktsAntX-table-container>.ktsAntX-table-header>table>thead>tr>th {
8
- padding : 0 10px;
9
- height : 32px;
10
- background: #f4f4f4;
11
- }
12
-
13
- .ktsAntX-table.ktsAntX-table-bordered>.ktsAntX-table-container>.ktsAntX-table-body>table>tbody>tr>td {
14
- padding: 0;
15
- height : 32px;
16
- }
17
-
18
- .ktsAntX-table .ktsAntX-table-body {
19
- position: relative;
20
- }
21
-
22
- .ktsAntX-table .ktsAntX-table-body>table {
23
- position: absolute;
24
- left : 0;
25
- top : 0;
26
- }
27
-
28
- .ktsAntX-table .ktsAntX-table-tbody {
29
- position: relative;
30
- }
31
-
32
- .ktsAntX-checkbox-wrapper .ktsAntX-checkbox-inner {
33
- width : 16px;
34
- height : 16px;
35
- border : 1px solid #d9d9d9;
36
- border-radius: 2px;
37
- top : 1px;
38
- }
1
+ .kts-invoice-operate-goods-table-virtual {
2
+
3
+ .ktsAntX-table-body {
4
+ height: 280px;
5
+ }
6
+
7
+ .ktsAntX-table.ktsAntX-table-bordered>.ktsAntX-table-container>.ktsAntX-table-header>table>thead>tr>th {
8
+ padding : 0 10px;
9
+ height : 32px;
10
+ background: #f4f4f4;
11
+ }
12
+
13
+ .ktsAntX-table.ktsAntX-table-bordered>.ktsAntX-table-container>.ktsAntX-table-body>table>tbody>tr>td {
14
+ padding: 0;
15
+ height : 32px;
16
+ }
17
+
18
+ .ktsAntX-table .ktsAntX-table-body {
19
+ position: relative;
20
+ }
21
+
22
+ .ktsAntX-table .ktsAntX-table-body>table {
23
+ position: absolute;
24
+ left : 0;
25
+ top : 0;
26
+ }
27
+
28
+ .ktsAntX-table .ktsAntX-table-tbody {
29
+ position: relative;
30
+ }
31
+
32
+ .ktsAntX-checkbox-wrapper .ktsAntX-checkbox-inner {
33
+ width : 16px;
34
+ height : 16px;
35
+ border : 1px solid #d9d9d9;
36
+ border-radius: 2px;
37
+ top : 1px;
38
+ }
39
39
  }
@@ -1,106 +1,106 @@
1
-
2
- import React from "react";
3
- import { TableManual as Table, TableProps } from "kts-xui";
4
- import './index.less';
5
-
6
- export default function <T extends object = any>(props: TableProps<T>) {
7
-
8
- const [self, setSelf] = React.useState<HTMLSpanElement | null>(null);
9
-
10
- const tableBody = React.useMemo(() => {
11
- if (!self) return;
12
- return self.querySelector('.ktsAntX-table-body') as HTMLDivElement;
13
- }, [self]);
14
-
15
- /** 显示指针 */
16
- const [pointer, setPointer] = React.useState(0);
17
-
18
- /** 行高 */
19
- const rowHeight = React.useMemo(() => {
20
- if (!self) return 33;
21
-
22
- const td = self.querySelector('.ktsAntX-table-tbody .ktsAntX-table-row');
23
- if (!td) return 33;
24
-
25
- return td.clientHeight;
26
- }, [self, props.dataSource]);
27
-
28
- /** 间隔容器 */
29
- const placeholder = React.useMemo(() => {
30
- if (!self || !tableBody) return;
31
- let placeholder = tableBody.querySelector('.table-virtual-placeholder') as HTMLDivElement;
32
- if (!placeholder) {
33
- placeholder = document.createElement('div');
34
- placeholder.className = 'table-virtual-placeholder';
35
- tableBody.appendChild(placeholder);
36
- }
37
- return placeholder;
38
- }, [self, tableBody]);
39
-
40
- // 设置占位dom的搞
41
- const placeholderHeight = React.useMemo(() => {
42
- if (!self || !rowHeight || !props.dataSource || !placeholder) return;
43
- const placeholderHeight = rowHeight * props.dataSource.length;
44
- placeholder.style.height = `${placeholderHeight}px`;
45
- return placeholderHeight;
46
- }, [self, rowHeight, props.dataSource, placeholder]);
47
-
48
- /** 可以容纳的行数 */
49
- const rowSize = React.useMemo(() => {
50
- if (!tableBody! || !rowHeight) return 0;
51
- return Math.ceil(tableBody.clientHeight / rowHeight);
52
- }, [tableBody, rowHeight, placeholderHeight]);
53
-
54
- // 计算渲染的行
55
- const dataSource = React.useMemo(() => {
56
- if (!props.dataSource) return [];
57
- if (props.dataSource.length < 10) return props.dataSource;
58
-
59
- if (!rowSize) return [props.dataSource[0]];
60
- return props.dataSource?.slice(pointer, pointer + 2 * rowSize);
61
- }, [props.dataSource, pointer, rowSize]);
62
-
63
- // 监听滚动
64
- React.useEffect(() => {
65
- if (!self || !placeholder || !props.dataSource || !rowHeight || !tableBody)
66
- return;
67
-
68
- const onScroll = () => {
69
- if (!props.dataSource || !tableBody) return;
70
- setPointer(Math.floor((props.dataSource.length - rowSize) * (tableBody.scrollTop / (placeholder.clientHeight - tableBody.clientHeight))));
71
- };
72
- onScroll();
73
-
74
- tableBody.addEventListener('scroll', onScroll);
75
- return () => {
76
- tableBody.removeEventListener('scroll', onScroll);
77
- };
78
- }, [self, placeholder, props.dataSource, rowHeight, rowSize]);
79
-
80
- // 移动列表
81
- React.useEffect(() => {
82
- if (!self) return;
83
-
84
- const table = self.querySelector('.ktsAntX-table .ktsAntX-table-body>table') as HTMLDivElement;
85
- if (!table) return;
86
-
87
- table.style.top = `${pointer * rowHeight}px`;
88
- }, [pointer, self, rowHeight]);
89
-
90
- React.useEffect(() => {
91
- if (!self) return;
92
- const cont = self.querySelector('.kts-invoice-operate-goods-table-virtual .ktsAntX-table-body');
93
- if (!cont) return;
94
-
95
- cont.scrollTop = 0;
96
- }, [props.dataSource?.length])
97
-
98
- return (
99
- <span className="kts-invoice-operate-goods-table-virtual" ref={(e) => { setSelf(e) }} >
100
- <Table
101
- {...props}
102
- dataSource={dataSource}
103
- />
104
- </span>
105
- )
1
+
2
+ import React from "react";
3
+ import { TableManual as Table, TableProps } from "kts-xui";
4
+ import './index.less';
5
+
6
+ export default function <T extends object = any>(props: TableProps<T>) {
7
+
8
+ const [self, setSelf] = React.useState<HTMLSpanElement | null>(null);
9
+
10
+ const tableBody = React.useMemo(() => {
11
+ if (!self) return;
12
+ return self.querySelector('.ktsAntX-table-body') as HTMLDivElement;
13
+ }, [self]);
14
+
15
+ /** 显示指针 */
16
+ const [pointer, setPointer] = React.useState(0);
17
+
18
+ /** 行高 */
19
+ const rowHeight = React.useMemo(() => {
20
+ if (!self) return 33;
21
+
22
+ const td = self.querySelector('.ktsAntX-table-tbody .ktsAntX-table-row');
23
+ if (!td) return 33;
24
+
25
+ return td.clientHeight;
26
+ }, [self, props.dataSource]);
27
+
28
+ /** 间隔容器 */
29
+ const placeholder = React.useMemo(() => {
30
+ if (!self || !tableBody) return;
31
+ let placeholder = tableBody.querySelector('.table-virtual-placeholder') as HTMLDivElement;
32
+ if (!placeholder) {
33
+ placeholder = document.createElement('div');
34
+ placeholder.className = 'table-virtual-placeholder';
35
+ tableBody.appendChild(placeholder);
36
+ }
37
+ return placeholder;
38
+ }, [self, tableBody]);
39
+
40
+ // 设置占位dom的搞
41
+ const placeholderHeight = React.useMemo(() => {
42
+ if (!self || !rowHeight || !props.dataSource || !placeholder) return;
43
+ const placeholderHeight = rowHeight * props.dataSource.length;
44
+ placeholder.style.height = `${placeholderHeight}px`;
45
+ return placeholderHeight;
46
+ }, [self, rowHeight, props.dataSource, placeholder]);
47
+
48
+ /** 可以容纳的行数 */
49
+ const rowSize = React.useMemo(() => {
50
+ if (!tableBody! || !rowHeight) return 0;
51
+ return Math.ceil(tableBody.clientHeight / rowHeight);
52
+ }, [tableBody, rowHeight, placeholderHeight]);
53
+
54
+ // 计算渲染的行
55
+ const dataSource = React.useMemo(() => {
56
+ if (!props.dataSource) return [];
57
+ if (props.dataSource.length < 10) return props.dataSource;
58
+
59
+ if (!rowSize) return [props.dataSource[0]];
60
+ return props.dataSource?.slice(pointer, pointer + 2 * rowSize);
61
+ }, [props.dataSource, pointer, rowSize]);
62
+
63
+ // 监听滚动
64
+ React.useEffect(() => {
65
+ if (!self || !placeholder || !props.dataSource || !rowHeight || !tableBody)
66
+ return;
67
+
68
+ const onScroll = () => {
69
+ if (!props.dataSource || !tableBody) return;
70
+ setPointer(Math.floor((props.dataSource.length - rowSize) * (tableBody.scrollTop / (placeholder.clientHeight - tableBody.clientHeight))));
71
+ };
72
+ onScroll();
73
+
74
+ tableBody.addEventListener('scroll', onScroll);
75
+ return () => {
76
+ tableBody.removeEventListener('scroll', onScroll);
77
+ };
78
+ }, [self, placeholder, props.dataSource, rowHeight, rowSize]);
79
+
80
+ // 移动列表
81
+ React.useEffect(() => {
82
+ if (!self) return;
83
+
84
+ const table = self.querySelector('.ktsAntX-table .ktsAntX-table-body>table') as HTMLDivElement;
85
+ if (!table) return;
86
+
87
+ table.style.top = `${pointer * rowHeight}px`;
88
+ }, [pointer, self, rowHeight]);
89
+
90
+ React.useEffect(() => {
91
+ if (!self) return;
92
+ const cont = self.querySelector('.kts-invoice-operate-goods-table-virtual .ktsAntX-table-body');
93
+ if (!cont) return;
94
+
95
+ cont.scrollTop = 0;
96
+ }, [props.dataSource?.length])
97
+
98
+ return (
99
+ <span className="kts-invoice-operate-goods-table-virtual" ref={(e) => { setSelf(e) }} >
100
+ <Table
101
+ {...props}
102
+ dataSource={dataSource}
103
+ />
104
+ </span>
105
+ )
106
106
  }
@@ -1,44 +1,44 @@
1
- .kts-invoice-operate-goods-table-virtual {
2
- .ktsAnt3x-table-placeholder {
3
- position: absolute;
4
- top: 50px;
5
- left: 0;
6
- width: 100%;
7
- border: none;
8
- }
9
-
10
- .ktsAnt3x-table {
11
- font-size: 12px;
12
- border: none;
13
- border-radius: 0;
14
-
15
- .ktsAnt3x-table-content {
16
- border-right: none;
17
-
18
- .ktsAnt3x-table-body {
19
- margin: 0;
20
-
21
- table {
22
- position: absolute;
23
- top: 0;
24
- left: 0;
25
- border-bottom: 1px solid #e8e8e8;
26
-
27
- tr {
28
- height: 32px;
29
- }
30
-
31
- tr:hover {
32
- td{
33
- background: none;
34
- }
35
- }
36
- }
37
- }
38
- }
39
-
40
- .ktsAnt3x-table-thead>tr {
41
- background-color: #f6f7f9;
42
- }
43
- }
44
- }
1
+ .kts-invoice-operate-goods-table-virtual {
2
+ .ktsAnt3x-table-placeholder {
3
+ position: absolute;
4
+ top: 50px;
5
+ left: 0;
6
+ width: 100%;
7
+ border: none;
8
+ }
9
+
10
+ .ktsAnt3x-table {
11
+ font-size: 12px;
12
+ border: none;
13
+ border-radius: 0;
14
+
15
+ .ktsAnt3x-table-content {
16
+ border-right: none;
17
+
18
+ .ktsAnt3x-table-body {
19
+ margin: 0;
20
+
21
+ table {
22
+ position: absolute;
23
+ top: 0;
24
+ left: 0;
25
+ border-bottom: 1px solid #e8e8e8;
26
+
27
+ tr {
28
+ height: 32px;
29
+ }
30
+
31
+ tr:hover {
32
+ td{
33
+ background: none;
34
+ }
35
+ }
36
+ }
37
+ }
38
+ }
39
+
40
+ .ktsAnt3x-table-thead>tr {
41
+ background-color: #f6f7f9;
42
+ }
43
+ }
44
+ }