@cqsjjb/jjb-react-admin-component 3.0.29 → 3.1.0

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.
@@ -152,7 +152,7 @@ function RenderText(props) {
152
152
  value.load().then(res => res.json()).then(res => {
153
153
  if (res.success) {
154
154
  setOptions(res.data);
155
- setText(value.selected.map(i => `${i.key}&${i.label}`));
155
+ setText(value?.selected?.map?.(i => `${i.key}&${i.label}`));
156
156
  }
157
157
  setLoading(false);
158
158
  });
package/Table/index.d.ts CHANGED
@@ -4,11 +4,13 @@ import * as React from 'react';
4
4
  import type { TableProps } from 'antd';
5
5
 
6
6
  interface OverTableProps extends TableProps {
7
- // 是否禁用内容区滚动,默认true
7
+ /**
8
+ * 是否禁用内容区滚动,默认false
9
+ */
8
10
  disabledResizer?: boolean;
9
- // 当一个路由下存在多个表格的情况下
10
- // 需要给每一个表格设置一个唯一存储索引
11
- // 若没有设置则使用默认索引,请注意缓存数据会被覆盖
11
+ /**
12
+ * 当一个路由下存在多个表格的情况下 需要给每一个表格设置一个唯一存储索引 若没有设置则使用默认索引,请注意缓存数据会被覆盖
13
+ */
12
14
  storeIndex?: string;
13
15
  }
14
16
 
package/Table/index.js CHANGED
@@ -1,46 +1,74 @@
1
1
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
2
  import React from 'react';
3
+ import { tools } from '@cqsjjb/jjb-common-lib';
3
4
  import { ProTable } from '@ant-design/pro-components';
4
5
  import { useAntdResizableHeader } from 'use-antd-resizable-header';
5
- import { getElementAbsRect, antPrefix, className, setTableSize, getTableSize, getPersistenceKey } from './utils';
6
+ import { antPrefix, setTableSize, getTableSize, getPersistenceKey } from './utils';
6
7
  import './index.less';
7
8
  require('use-antd-resizable-header/dist/style.css');
8
9
  export default function TablePro(props) {
10
+ const prefix = antPrefix || 'ant';
11
+ const baseCls = `.${prefix}-table`;
12
+ const tableCls = `${baseCls}-wrapper`;
13
+ const tableBodyCls = `${baseCls}-body`;
9
14
  const {
10
15
  storeIndex
11
16
  } = props;
12
17
  const [size, setSize] = React.useState(getTableSize(storeIndex) || 'default');
13
18
  const [tableHeight, setTableHeight] = React.useState(0);
14
19
  const persistenceKey = getPersistenceKey(storeIndex);
20
+ const enabledResizer = tools.isUndefined(props.disabledResizer);
15
21
  React.useEffect(() => {
16
- let observer;
17
- const table = document.querySelector(className('pro-table'));
18
- if (!props.disabledResizer) {
19
- observer = new ResizeObserver(() => {
20
- setTimeout(() => {
21
- const tBody = document.querySelector(className('table-body'));
22
- const tFooter = document.querySelector(className('table-footer'));
23
- const tPagination = document.querySelector(className('table-pagination'));
24
- const tBodyNativeRect = tBody.getBoundingClientRect();
25
- const tFooterAbsRect = getElementAbsRect(tFooter);
26
- const tPaginationAbsRect = getElementAbsRect(tPagination);
27
- const gap = 38;
28
- const height = window.innerHeight - (gap + tBodyNativeRect.y + tFooterAbsRect.absHeight + tPaginationAbsRect.absHeight);
29
- setTableHeight(height);
30
- }, 100);
22
+ let mutationObserver, resizeObserver;
23
+ if (enabledResizer) {
24
+ // 监听-DOM树
25
+ mutationObserver = new MutationObserver(mutations => mutations.forEach(() => calcTableHeight()));
26
+ // 监听-缩放
27
+ resizeObserver = new ResizeObserver(entries => entries.forEach(() => calcTableHeight()));
28
+
29
+ // 初始化首次计算
30
+ setTimeout(() => calcTableHeight(), 500);
31
+
32
+ // 执行-监听-缩放
33
+ resizeObserver.observe(document.body);
34
+ // 执行-监听-DOM树是否发生变化
35
+ mutationObserver.observe(document.body, {
36
+ subtree: true,
37
+ childList: true
31
38
  });
32
- observer.observe(table);
33
39
  }
34
40
  return () => {
35
- if (observer && !props.disabledResizer) {
36
- observer.unobserve(table);
37
- observer.disconnect();
41
+ if (mutationObserver && resizeObserver && enabledResizer) {
42
+ resizeObserver.unobserve(document.body);
43
+ mutationObserver.unobserve(document.body);
38
44
  }
39
45
  };
40
46
  }, []);
41
47
  React.useEffect(() => {
42
48
  setTableSize(size, storeIndex);
43
49
  }, [size]);
50
+
51
+ // 计算高度
52
+ const calcTableHeight = () => {
53
+ try {
54
+ // table元素
55
+ const tableEl = document.querySelector(tableCls);
56
+ // table-body元素
57
+ const tableBodyEl = document.querySelector(tableBodyCls);
58
+ if (tableBodyEl && tableEl) {
59
+ // 获取table元素的矩形数据
60
+ const tableRect = tableEl.getBoundingClientRect();
61
+ // 获取table-body元素的矩形数据
62
+ const tableBodyRect = tableBodyEl.getBoundingClientRect();
63
+ // 获取底部的高度差
64
+ const bottomHeight = tableRect.bottom - tableBodyRect.bottom;
65
+ // 计算最终值
66
+ setTableHeight(innerHeight - tableBodyRect.top - bottomHeight - 22);
67
+ }
68
+ } catch (e) {
69
+ window.console['error'](e);
70
+ }
71
+ };
44
72
  const {
45
73
  components,
46
74
  resizableColumns,
@@ -57,7 +85,7 @@ export default function TablePro(props) {
57
85
  const scroll = {
58
86
  x: tableWidth
59
87
  };
60
- if (!props.disabledResizer) {
88
+ if (enabledResizer) {
61
89
  scroll.y = tableHeight;
62
90
  }
63
91
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ProTable, _extends({}, props, {
package/Table/utils.js CHANGED
@@ -1,79 +1,5 @@
1
1
  import { tools } from '@cqsjjb/jjb-common-lib';
2
2
 
3
- /**
4
- * @param ele {HTMLElement}
5
- * @return {{absHeight: number, absWidth: number}}
6
- */
7
- export function getElementAbsRect(ele) {
8
- if (!ele) {
9
- return {
10
- absWidth: 0,
11
- absHeight: 0
12
- };
13
- }
14
-
15
- const style = getElementRect(ele);
16
-
17
- return {
18
- absHeight: tools.arrayHelper.sum([
19
- style.height,
20
- style.marginTop,
21
- style.marginBottom,
22
- style.borderTopWidth,
23
- style.borderBottomWidth,
24
- ...(style.boxSizing === 'content-box'
25
- ? [
26
- style.paddingTop,
27
- style.paddingBottom
28
- ]
29
- : [])
30
- ]),
31
- absWidth: tools.arrayHelper.sum([
32
- style.width,
33
- style.marginLeft,
34
- style.marginRight,
35
- style.borderLeftWidth,
36
- style.borderRightWidth,
37
- ...(style.boxSizing === 'content-box'
38
- ? [
39
- style.paddingLeft,
40
- style.paddingRight
41
- ]
42
- : [])
43
- ])
44
- };
45
- }
46
-
47
- /**
48
- * @param ele {HTMLElement}
49
- * @return {{paddingRight: number, marginLeft: number, marginRight: number, paddingBottom: number, borderLeftWidth: number, borderTopWidth: number, borderRightWidth: number, width: number, marginBottom: number, paddingTop: number, borderBottomWidth: number, paddingLeft: number, marginTop: number, height: number, boxSizing: string}}
50
- */
51
- export function getElementRect(ele) {
52
- let style;
53
- try {
54
- style = window.getComputedStyle(ele);
55
- } catch (e) {
56
- style = {};
57
- }
58
- return {
59
- width: parseFloat(style[ 'width' ] || '0'),
60
- height: parseFloat(style[ 'height' ] || '0'),
61
- marginTop: parseFloat(style[ 'margin-top' ] || '0'),
62
- marginBottom: parseFloat(style[ 'margin-bottom' ] || '0'),
63
- marginLeft: parseFloat(style[ 'margin-left' ] || '0'),
64
- marginRight: parseFloat(style[ 'margin-bottom' ] || '0'),
65
- borderTopWidth: parseFloat(style[ 'border-top-width' ] || '0'),
66
- borderBottomWidth: parseFloat(style[ 'border-bottom-width' ] || '0'),
67
- borderLeftWidth: parseFloat(style[ 'border-left-width' ] || '0'),
68
- borderRightWidth: parseFloat(style[ 'border-right-width' ] || '0'),
69
- paddingTop: parseFloat(style[ 'padding-top' ] || '0'),
70
- paddingBottom: parseFloat(style[ 'padding-bottom' ] || '0'),
71
- paddingLeft: parseFloat(style[ 'padding-left' ] || '0'),
72
- paddingRight: parseFloat(style[ 'padding-right' ] || '0'),
73
- boxSizing: style[ 'box-sizing' ]
74
- };
75
- }
76
-
77
3
  export const antPrefix = process.env.app.antd[ 'ant-prefix' ];
78
4
 
79
5
  export function className(name) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cqsjjb/jjb-react-admin-component",
3
- "version": "3.0.29",
3
+ "version": "3.1.0",
4
4
  "description": "jjb-react-admin-组件库@new",
5
5
  "main": "index.js",
6
6
  "author": "jjb-front-team",
@@ -1,399 +0,0 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import {
4
- Cascader as OriginCascader,
5
- Col,
6
- DatePicker as OriginDatePicker,
7
- Input as OriginInput,
8
- Row,
9
- Select as OriginSelect,
10
- TreeSelect as OriginTreeSelect
11
- } from 'antd';
12
- import './index.less';
13
-
14
- const prefixCls = process?.env?.app?.antd[ 'ant-prefix' ] || 'ant';
15
-
16
- /**
17
- * @param classList {string[]}
18
- * @return {string}
19
- */
20
- function classnames (classList) {
21
- return classList.filter(i => i).join(' ');
22
- }
23
-
24
- function algorithm () {
25
- const value = document.documentElement.style.getPropertyValue('--saas-algorithm');
26
- return value
27
- ? value === '#FFF'
28
- ? 'default'
29
- : 'dark'
30
- : 'default';
31
- }
32
-
33
- class Input extends React.Component {
34
- get algorithm () {
35
- return algorithm();
36
- }
37
-
38
- render () {
39
- return (
40
- <div
41
- style={this.props.style}
42
- className={classnames([
43
- `${prefixCls}-form-item-control-label-wrapper`,
44
- `${prefixCls}-form-item-control-label-wrapper-${this.algorithm}`,
45
- this.props.label && `${prefixCls}-form-item-control-label-has`
46
- ])}
47
- >
48
- <Row
49
- align="middle"
50
- wrap={false}
51
- >
52
- {this.props.label && (
53
- <Col
54
- span={this.props.labelSpan}
55
- className={`${prefixCls}-form-item-control-label-span`}
56
- >
57
- {this.props.label}
58
- </Col>
59
- )}
60
- <Col flex={1}>
61
- <OriginInput
62
- style={{
63
- width: '100%'
64
- }}
65
- value={this.props.value}
66
- maxLength={this.props.maxLength}
67
- allowClear={this.props.allowClear}
68
- placeholder={this.props.placeholder}
69
- onChange={e => this.props.onChange(e.target.value || undefined)}
70
- />
71
- </Col>
72
- </Row>
73
- </div>
74
- );
75
- }
76
- }
77
-
78
- Input.propTypes = {
79
- value: PropTypes.any,
80
- label: PropTypes.string,
81
- labelSpan: PropTypes.number,
82
- maxLength: PropTypes.number,
83
- allowClear: PropTypes.bool,
84
- placeholder: PropTypes.string,
85
- onChange: PropTypes.func
86
- };
87
-
88
- class Select extends React.Component {
89
- get algorithm () {
90
- return algorithm();
91
- }
92
-
93
- render () {
94
- return (
95
- <div
96
- style={this.props.style}
97
- className={classnames([
98
- `${prefixCls}-form-item-control-label-wrapper`,
99
- `${prefixCls}-form-item-control-label-wrapper-${this.algorithm}`,
100
- this.props.label && `${prefixCls}-form-item-control-label-has`
101
- ])}
102
- >
103
- <Row
104
- align="middle"
105
- wrap={false}
106
- >
107
- {this.props.label && (
108
- <Col
109
- span={this.props.labelSpan}
110
- className={`${prefixCls}-form-item-control-label-span`}
111
- >
112
- {this.props.label}
113
- </Col>
114
- )}
115
- <Col flex={1}>
116
- <OriginSelect
117
- mode={this.props.mode}
118
- style={{
119
- width: '100%'
120
- }}
121
- value={this.props.value}
122
- allowClear={this.props.allowClear}
123
- maxTagCount={this.props.maxTagCount || 3}
124
- placeholder={this.props.placeholder}
125
- onChange={value => this.props.onChange(value || undefined)}
126
- >
127
- {this.props.options
128
- ? this.props.options
129
- : this.props.children}
130
- </OriginSelect>
131
- </Col>
132
- </Row>
133
- </div>
134
- );
135
- }
136
- }
137
-
138
- Select.propTypes = {
139
- mode: PropTypes.string,
140
- value: PropTypes.any,
141
- label: PropTypes.string,
142
- labelSpan: PropTypes.number,
143
- allowClear: PropTypes.bool,
144
- maxTagCount: PropTypes.number,
145
- placeholder: PropTypes.string,
146
- onChange: PropTypes.func
147
- };
148
-
149
- class Cascader extends React.Component {
150
- get algorithm () {
151
- return algorithm();
152
- }
153
-
154
- render () {
155
- return (
156
- <div
157
- style={this.props.style}
158
- className={classnames([
159
- `${prefixCls}-form-item-control-label-wrapper`,
160
- `${prefixCls}-form-item-control-label-wrapper-${this.algorithm}`,
161
- this.props.label && `${prefixCls}-form-item-control-label-has`
162
- ])}
163
- >
164
- <Row
165
- align="middle"
166
- wrap={false}
167
- >
168
- {this.props.label && (
169
- <Col
170
- span={this.props.labelSpan}
171
- className={`${prefixCls}-form-item-control-label-span`}
172
- >
173
- {this.props.label}
174
- </Col>
175
- )}
176
- <Col flex={1}>
177
- <OriginCascader
178
- style={{
179
- width: '100%'
180
- }}
181
- value={this.props.value}
182
- options={this.props.options}
183
- multiple={this.props.multiple}
184
- allowClear={this.props.allowClear}
185
- fieldNames={this.props.fieldNames}
186
- maxTagCount={this.props.maxTagCount || 3}
187
- placeholder={this.props.placeholder}
188
- showCheckedStrategy={this.props.showCheckedStrategy}
189
- onChange={value => this.props.onChange(value || undefined)}
190
- />
191
- </Col>
192
- </Row>
193
- </div>
194
- );
195
- }
196
- }
197
-
198
- Cascader.propTypes = {
199
- mode: PropTypes.string,
200
- value: PropTypes.any,
201
- label: PropTypes.string,
202
- options: PropTypes.array,
203
- multiple: PropTypes.bool,
204
- labelSpan: PropTypes.number,
205
- allowClear: PropTypes.bool,
206
- fieldNames: PropTypes.object,
207
- maxTagCount: PropTypes.number,
208
- placeholder: PropTypes.string,
209
- showCheckedStrategy: PropTypes.string,
210
- onChange: PropTypes.func
211
- };
212
-
213
-
214
- class RangePicker extends React.Component {
215
- get algorithm () {
216
- return algorithm();
217
- }
218
-
219
- render () {
220
- return (
221
- <div
222
- style={this.props.style}
223
- className={classnames([
224
- `${prefixCls}-form-item-control-label-wrapper`,
225
- `${prefixCls}-form-item-control-label-wrapper-${this.algorithm}`,
226
- this.props.label && `${prefixCls}-form-item-control-label-has`
227
- ])}
228
- >
229
- <Row
230
- align="middle"
231
- wrap={false}
232
- >
233
- {this.props.label && (
234
- <Col
235
- span={this.props.labelSpan}
236
- className={`${prefixCls}-form-item-control-label-span`}
237
- >
238
- {this.props.label}
239
- </Col>
240
- )}
241
- <Col style={{ flex: 1 }}>
242
- <OriginDatePicker.RangePicker
243
- style={{
244
- width: '100%'
245
- }}
246
- value={this.props.value}
247
- format={this.props.format}
248
- showTime={this.props.showTime || undefined}
249
- placeholder={this.props.placeholder}
250
- onChange={value => this.props.onChange(value || undefined)}
251
- />
252
- </Col>
253
- </Row>
254
- </div>
255
- );
256
- }
257
- }
258
-
259
- RangePicker.propTypes = {
260
- value: PropTypes.any,
261
- label: PropTypes.string,
262
- format: PropTypes.string,
263
- labelSpan: PropTypes.number,
264
- placeholder: PropTypes.string,
265
- onChange: PropTypes.func
266
- };
267
-
268
- class DatePicker extends React.Component {
269
- static RangePicker = RangePicker;
270
-
271
- get algorithm () {
272
- return algorithm();
273
- }
274
-
275
- render () {
276
- return (
277
- <div
278
- style={this.props.style}
279
- className={classnames([
280
- `${prefixCls}-form-item-control-label-wrapper`,
281
- `${prefixCls}-form-item-control-label-wrapper-${this.algorithm}`,
282
- this.props.label && `${prefixCls}-form-item-control-label-has`
283
- ])}
284
- >
285
- <Row
286
- align="middle"
287
- wrap={false}
288
- >
289
- {this.props.label && (
290
- <Col
291
- span={this.props.labelSpan}
292
- className={`${prefixCls}-form-item-control-label-span`}
293
- >
294
- {this.props.label}
295
- </Col>
296
- )}
297
- <Col flex={1}>
298
- <OriginDatePicker
299
- style={{
300
- width: '100%'
301
- }}
302
- value={this.props.value}
303
- format={this.props.format}
304
- picker={this.props.picker || undefined}
305
- showTime={this.props.showTime || undefined}
306
- placeholder={this.props.placeholder}
307
- onChange={value => this.props.onChange(value || undefined)}
308
- />
309
- </Col>
310
- </Row>
311
- </div>
312
- );
313
- }
314
- }
315
-
316
- DatePicker.propTypes = {
317
- value: PropTypes.any,
318
- label: PropTypes.string,
319
- format: PropTypes.string,
320
- labelSpan: PropTypes.number,
321
- placeholder: PropTypes.string,
322
- onChange: PropTypes.func
323
- };
324
-
325
- class TreeSelect extends React.Component {
326
- get algorithm () {
327
- return algorithm();
328
- }
329
-
330
- render () {
331
- return (
332
- <div
333
- style={this.props.style}
334
- className={classnames([
335
- `${prefixCls}-form-item-control-label-wrapper`,
336
- `${prefixCls}-form-item-control-label-wrapper-${this.algorithm}`,
337
- this.props.label && `${prefixCls}-form-item-control-label-has`
338
- ])}
339
- >
340
- <Row
341
- align="middle"
342
- wrap={false}
343
- >
344
- {this.props.label && (
345
- <Col
346
- span={this.props.labelSpan}
347
- className={`${prefixCls}-form-item-control-label-span`}
348
- >
349
- {this.props.label}
350
- </Col>
351
- )}
352
- <Col flex={1}>
353
- <OriginTreeSelect
354
- showSearch
355
- allowClear
356
- style={{
357
- width: '100%'
358
- }}
359
- treeData={this.props.treeData}
360
- fieldNames={this.props.fieldNames}
361
- dropdownStyle={this.props.dropdownStyle}
362
- maxTagCount={2}
363
- value={this.props.value}
364
- placeholder={this.props.placeholder
365
- ? this.props.placeholder
366
- : '请选择分类'}
367
- defaultValue={this.props.defaultValue
368
- ? this.props.defaultValue
369
- : undefined}
370
- treeCheckable={this.props.checkbox}
371
- treeNodeFilterProp="title"
372
- showCheckedStrategy={OriginTreeSelect.SHOW_PARENT}
373
- onChange={value => this.props.onChange(value)}
374
- />
375
- </Col>
376
- </Row>
377
- </div>
378
- );
379
- }
380
- }
381
-
382
- TreeSelect.propTypes = {
383
- label: PropTypes.string,
384
- checkbox: PropTypes.bool,
385
- treeData: PropTypes.array,
386
- labelSpan: PropTypes.number,
387
- fieldNames: PropTypes.object,
388
- defaultValue: PropTypes.array,
389
- dropdownStyle: PropTypes.object,
390
- onChange: PropTypes.func
391
- };
392
-
393
- export default {
394
- Input,
395
- Select,
396
- Cascader,
397
- DatePicker,
398
- TreeSelect
399
- };
@@ -1,58 +0,0 @@
1
- import React from 'react';
2
- import { Result, Tooltip, Button } from 'antd';
3
-
4
- export default class ErrorBoundary extends React.Component {
5
- state = {
6
- hasError: false,
7
- errorInfo: '',
8
- errorStack: undefined
9
- };
10
-
11
- componentDidCatch(error, info) {
12
- this.setState({
13
- hasError: true,
14
- errorInfo: error.message,
15
- errorStack: info.componentStack
16
- });
17
- }
18
-
19
- render() {
20
- if (this.state.hasError) {
21
- return (
22
- <Result
23
- status="error"
24
- title="应用运行异常"
25
- subTitle={(
26
- <React.Fragment>
27
- <div>{this.state.errorInfo}</div>
28
- <div
29
- style={{
30
- width: 700,
31
- display: 'inline-block',
32
- overflow: 'auto',
33
- maxHeight: 400,
34
- textAlign: 'left',
35
- whiteSpace: 'pre-line'
36
- }}
37
- >
38
- {this.state.errorStack}
39
- </div>
40
- </React.Fragment>
41
- )}
42
- extra={(
43
- <Tooltip title="若刷新任然无法解决,请联系技术人员解决">
44
- <Button
45
- type="primary"
46
- onClick={() => window.location.reload()}
47
- >
48
- 刷新重试
49
- </Button>
50
- </Tooltip>
51
- )}
52
- />
53
- );
54
- }
55
-
56
- return this.props.children;
57
- }
58
- }