vap1 0.2.2 → 0.2.3

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.
@@ -33,17 +33,17 @@ const renderGroup = (props) => {
33
33
  return renderGroup(item);
34
34
  }
35
35
  const itemProps = getMenuProps(item);
36
- return react_1.default.createElement(antd_1.Menu.Item, Object.assign({ key: item.key }, itemProps), itemProps.title);
36
+ return react_1.default.createElement(antd_1.Menu.Item, Object.assign({ key: item.key }, lodash_1.default.omit(itemProps, ['title'])), itemProps.title);
37
37
  }));
38
38
  };
39
39
  const _Menu = props => {
40
40
  if (lodash_1.default.isArray(props.items) && props.items.length) {
41
- return react_1.default.createElement(antd_1.Menu, Object.assign({}, lodash_1.default.omit(props, 'children')), props.items.map(item => {
41
+ return react_1.default.createElement(antd_1.Menu, Object.assign({}, lodash_1.default.omit(props, ['children', 'items'])), props.items.map(item => {
42
42
  if (lodash_1.default.isArray(item.children)) {
43
43
  return renderGroup(item);
44
44
  }
45
45
  const itemProps = getMenuProps(item);
46
- return react_1.default.createElement(antd_1.Menu.Item, Object.assign({ key: item.key }, itemProps), itemProps.title);
46
+ return react_1.default.createElement(antd_1.Menu.Item, Object.assign({ key: item.key }, lodash_1.default.omit(itemProps, ['title'])), itemProps.title);
47
47
  }));
48
48
  }
49
49
  return react_1.default.createElement(antd_1.Menu, Object.assign({}, props));
@@ -20,11 +20,11 @@ export type DateRangeProps = {
20
20
  /**
21
21
  * 默认开始时间
22
22
  */
23
- defaultStart?: string | Dayjs;
23
+ start?: string | Dayjs;
24
24
  /**
25
25
  * 默认结束时间
26
26
  */
27
- defaultEnd?: string | Dayjs;
27
+ end?: string | Dayjs;
28
28
  /**
29
29
  * 响应事件,自取参数
30
30
  * 第一个参数为 string 类型
@@ -45,6 +45,14 @@ export type DateRangeProps = {
45
45
  * 宽度
46
46
  */
47
47
  width?: number;
48
+ /**
49
+ * 开始时间提示
50
+ */
51
+ startPlaceholder?: string;
52
+ /**
53
+ * 结束时间提示
54
+ */
55
+ endPlaceholder?: string;
48
56
  };
49
57
  /**
50
58
  * 日期区间选择
@@ -28,7 +28,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.DateRange = void 0;
30
30
  const react_1 = __importStar(require("react"));
31
- const lodash_1 = __importDefault(require("lodash"));
32
31
  const dayjs_1 = __importDefault(require("dayjs"));
33
32
  const antd_1 = require("antd");
34
33
  const hooks_1 = require("../../hooks");
@@ -38,71 +37,52 @@ const Const_1 = require("../_setup/Const");
38
37
  * 日期区间选择
39
38
  */
40
39
  const DateRange = (props) => {
41
- const update = (0, hooks_1.useUpdate)();
42
- const state = (0, react_1.useRef)({ startOpen: false, endOpen: false });
43
- const FORMAT = props.showTime === false ? utils_1.GLOBAL.CONFIG.DATE.DATE_FORMAT : utils_1.GLOBAL.CONFIG.DATE.DATE_TIME_FORMAT;
44
- (0, react_1.useLayoutEffect)(() => {
45
- if (lodash_1.default.has(props, 'defaultStart'))
46
- state.current.start = (0, dayjs_1.default)(props.defaultStart);
47
- if (lodash_1.default.has(props, 'defaultEnd'))
48
- state.current.end = (0, dayjs_1.default)(props.defaultEnd);
49
- if (state.current.start || state.current.end)
50
- update();
51
- }, []);
52
- const disabledStartDate = (startValue) => {
53
- const endValue = state.current.end;
54
- if (!startValue || !endValue) {
55
- if (props.minDate) {
56
- return startValue.valueOf() > props.minDate.valueOf();
57
- }
58
- return false;
40
+ const [start, setStart] = (0, react_1.useState)(props.start ? (0, dayjs_1.default)(props.start) : undefined);
41
+ const [end, setEnd] = (0, react_1.useState)(props.end ? (0, dayjs_1.default)(props.end) : undefined);
42
+ const isFirstMounted = (0, hooks_1.useFirstMountState)();
43
+ // 时间格式,提示
44
+ const [FORMAT, startPlaceholder, endPlaceholder] = (0, react_1.useMemo)(() => {
45
+ const FORMAT = props.showTime === false ? utils_1.GLOBAL.CONFIG.DATE.DATE_FORMAT : utils_1.GLOBAL.CONFIG.DATE.DATE_TIME_FORMAT;
46
+ const startPlaceholder = props.startPlaceholder ? props.startPlaceholder : (props.showTime ? utils_1.i18n.getText(Const_1.V.DATETIME_START) : utils_1.i18n.getText(Const_1.V.DATE_START));
47
+ const endPlaceholder = props.endPlaceholder ? props.endPlaceholder : (props.showTime ? utils_1.i18n.getText(Const_1.V.DATETIME_END) : utils_1.i18n.getText(Const_1.V.DATE_END));
48
+ return [FORMAT, startPlaceholder, endPlaceholder];
49
+ }, [props.showTime, props.startPlaceholder, props.endPlaceholder]);
50
+ // 是否在范围内
51
+ const inRange = (0, react_1.useCallback)((value) => {
52
+ if (props.minDate) {
53
+ if (value.isBefore(props.minDate))
54
+ return false;
59
55
  }
60
- return startValue.valueOf() > endValue.valueOf();
61
- };
62
- const disabledEndDate = (endValue) => {
63
- const startValue = state.current.start;
64
- if (!endValue || !startValue) {
65
- if (props.maxDate) {
66
- return endValue.valueOf() < props.maxDate.valueOf();
67
- }
68
- return false;
56
+ if (props.maxDate) {
57
+ if (value.isAfter(props.maxDate))
58
+ return false;
69
59
  }
70
- return endValue.valueOf() <= startValue.valueOf();
71
- };
72
- const callback = () => {
73
- props.onChange([
74
- state.current.start ? state.current.start.format(FORMAT) : null,
75
- state.current.end ? state.current.end.format(FORMAT) : null,
76
- ], [
77
- state.current.start ? state.current.start : null,
78
- state.current.end ? state.current.end : null,
79
- ]);
80
- };
81
- const onStartChange = (value) => {
82
- state.current.start = value;
83
- callback();
84
- update();
85
- };
86
- const onEndChange = (value) => {
87
- state.current.end = value;
88
- callback();
89
- update();
90
- };
91
- const handleStartOpenChange = (open) => {
92
- state.current.startOpen = open;
93
- state.current.endOpen = !open;
94
- update();
95
- };
96
- const handleEndOpenChange = (open) => {
97
- state.current.startOpen = false;
98
- state.current.endOpen = open;
99
- update();
100
- };
60
+ return true;
61
+ }, [props.minDate, props.maxDate]);
62
+ const disabledStartDate = (0, react_1.useCallback)((value) => {
63
+ if (!inRange(value))
64
+ return true;
65
+ if (end != null && value.isAfter(end))
66
+ return true;
67
+ return false;
68
+ }, [end, inRange]);
69
+ const disabledEndDate = (0, react_1.useCallback)((value) => {
70
+ if (!inRange(value))
71
+ return true;
72
+ if (start != null && value.isBefore(start))
73
+ return true;
74
+ return false;
75
+ }, [start, inRange]);
76
+ (0, react_1.useLayoutEffect)(() => {
77
+ if (isFirstMounted)
78
+ return;
79
+ props.onChange([start ? start.format(FORMAT) : null, end ? end.format(FORMAT) : null,], [start ? start : null, end ? end : null,]);
80
+ }, [start, end]);
101
81
  let style = {};
102
82
  if (props.width)
103
83
  style.width = props.width;
104
84
  return react_1.default.createElement("div", { className: utils_1.StringUtil.className(['c-daterange'], props.className), style: style },
105
- react_1.default.createElement(antd_1.DatePicker, { value: state.current.start, allowClear: props.allowClear, disabled: props.disabled, disabledDate: val => disabledStartDate(val), showTime: props.showTime, format: FORMAT, placeholder: props.showTime ? utils_1.i18n.getText(Const_1.V.DATETIME_START) : utils_1.i18n.getText(Const_1.V.DATE_START), onChange: onStartChange, onOpenChange: open => handleStartOpenChange(open), open: state.current.startOpen }),
106
- react_1.default.createElement(antd_1.DatePicker, { value: state.current.end, allowClear: props.allowClear, disabled: props.disabled, disabledDate: val => disabledEndDate(val), showTime: props.showTime, format: FORMAT, placeholder: props.showTime ? utils_1.i18n.getText(Const_1.V.DATETIME_END) : utils_1.i18n.getText(Const_1.V.DATE_END), onChange: (val) => onEndChange(val), open: state.current.endOpen, onOpenChange: handleEndOpenChange }));
85
+ react_1.default.createElement(antd_1.DatePicker, { value: start, allowClear: props.allowClear, disabled: props.disabled, disabledDate: disabledStartDate, showTime: props.showTime, format: FORMAT, placeholder: startPlaceholder, onChange: setStart }),
86
+ react_1.default.createElement(antd_1.DatePicker, { value: end, allowClear: props.allowClear, disabled: props.disabled, disabledDate: disabledEndDate, showTime: props.showTime, format: FORMAT, placeholder: endPlaceholder, onChange: setEnd }));
107
87
  };
108
88
  exports.DateRange = DateRange;
@@ -87,9 +87,9 @@ const Range = (props) => {
87
87
  })
88
88
  };
89
89
  if (data[startField])
90
- params.defaultStart = data[startField];
90
+ params.start = data[startField];
91
91
  if (data[endField])
92
- params.defaultEnd = data[endField];
92
+ params.end = data[endField];
93
93
  return react_1.default.createElement(DateRange_1.DateRange, Object.assign({}, params));
94
94
  };
95
95
  const AntdRnage = (props) => {
@@ -376,12 +376,12 @@ const DateRangePick = (props) => {
376
376
  if (value[startField]) {
377
377
  let day = (0, dayjs_1.default)(value[startField]);
378
378
  if (day.isValid())
379
- params.defaultStart = day;
379
+ params.start = day;
380
380
  }
381
381
  if (value[endField]) {
382
382
  let day = (0, dayjs_1.default)(value[endField]);
383
383
  if (day.isValid())
384
- params.defaultEnd = day;
384
+ params.end = day;
385
385
  }
386
386
  }
387
387
  return react_1.default.createElement(DateRange_1.DateRange, Object.assign({}, field.config, params));
@@ -78,14 +78,18 @@ const _utils_1 = require("./_utils");
78
78
  config.valueFormat(value),
79
79
  " "));
80
80
  });
81
+ const formatRange = (value) => {
82
+ if (value == undefined)
83
+ return utils_1.Const.NONE;
84
+ let start = value[0] === undefined ? '?' : value[0];
85
+ let end = value[1] === undefined ? '?' : value[1];
86
+ return `${start} - ${end}`;
87
+ };
81
88
  (0, _register_1.registerFormField)('slider-range', (props) => {
82
89
  const { field, disabled, value, onChange } = props;
83
- let config = lodash_1.default.merge({ valueWidth: 128, valueFormat: (range) => range ? `${range[0]} - ${range[1]}` : '0' }, field.config);
90
+ let config = lodash_1.default.merge({ valueWidth: 128, valueFormat: formatRange }, field.config);
84
91
  let params = { range: true, disabled, min: 0, max: 100, step: 1 };
85
92
  const [fields, values] = (0, _input_1.getMultiFieldValues)(field, value);
86
- if (!lodash_1.default.isFunction(config.valueFormat) || config.valueWidth == 0) {
87
- return react_1.default.createElement(Slider_1.Slider, Object.assign({}, params, field.config, { range: true, value: values, onChange: ([start, end]) => onChange({ [fields[0]]: start, [fields[1]]: end }) }));
88
- }
89
93
  return react_1.default.createElement("div", { className: 'i-slider' },
90
94
  react_1.default.createElement(Slider_1.Slider, Object.assign({}, params, field.config, { range: true, value: values, onChange: ([start, end]) => onChange({ [fields[0]]: start, [fields[1]]: end }) })),
91
95
  react_1.default.createElement("div", { className: 'i-slider-value', style: { width: config.valueWidth } },
@@ -47,22 +47,25 @@ const Const_1 = require("../Const");
47
47
  params.allowClear = false;
48
48
  return react_1.default.createElement(Select_1.Select, Object.assign({}, params, field.config, { mode: "default", value: value === null ? undefined : value, onChange: onChange, options: options }));
49
49
  });
50
- // 下拉
50
+ // 多选下拉
51
51
  (0, _register_1.registerFormField)('multi-select', (props) => {
52
52
  const { field, disabled, value, onChange, options } = props;
53
+ const onValueChange = (0, react_1.useCallback)((val) => {
54
+ if (field.dataType == 'array') {
55
+ onChange(val);
56
+ return;
57
+ }
58
+ onChange(val.join(','));
59
+ }, [field.dataType]);
53
60
  let params = { placeholder: (0, _input_1.getPlaceholder)(field, true), disabled, allowClear: true };
54
61
  if (field.required || field.rules && lodash_1.default.find(field.rules, { required: true }))
55
62
  params.allowClear = false;
56
- let selectKey = [];
57
- if (value) {
58
- if (lodash_1.default.isArray(value)) {
59
- selectKey = value;
60
- }
61
- else {
62
- selectKey = (value || '').split(',').map(lodash_1.default.trim);
63
- }
64
- }
65
- return react_1.default.createElement(Select_1.Select, Object.assign({}, params, field.config, { value: selectKey, mode: "multiple", onChange: (val) => onChange(val.join(',')) }), options.map(item => react_1.default.createElement(Select_1.Select.Option, { value: item.value + '' }, item.label)));
63
+ const selectKey = (0, react_1.useMemo)(() => {
64
+ if (lodash_1.default.isArray(value))
65
+ return value;
66
+ return (value || '').split(',').map(lodash_1.default.trim);
67
+ }, [value]);
68
+ return react_1.default.createElement(Select_1.Select, Object.assign({}, params, field.config, { value: selectKey, mode: "multiple", onChange: onValueChange }), options.map(item => react_1.default.createElement(Select_1.Select.Option, { value: item.value + '' }, item.label)));
66
69
  }, {
67
70
  render: _utils_1.MULTI_CHOOSE_SHOW
68
71
  });
package/deps/echarts.js CHANGED
@@ -40,7 +40,7 @@ const EChart = props => {
40
40
  window.clearTimeout(resizePid.current);
41
41
  resizePid.current = setTimeout(() => {
42
42
  graphRef.current.resize();
43
- }, 66);
43
+ }, 33);
44
44
  };
45
45
  (0, react_1.useEffect)(() => {
46
46
  graphRef.current = echarts.init(rootRef.current);
@@ -64,6 +64,12 @@ const EChart = props => {
64
64
  (0, react_1.useEffect)(() => {
65
65
  if (graphRef.current == null)
66
66
  return;
67
+ if (props.data == null)
68
+ return;
69
+ if (graphRef.current.setOption == null) {
70
+ console.error('尚未引入 ECharts,需要在package.json里面声明');
71
+ return;
72
+ }
67
73
  graphRef.current.setOption(props.data);
68
74
  }, [props.data]);
69
75
  return react_1.default.createElement("div", { ref: rootRef, className: utils_1.StringUtil.className(['_ev'], props.className) });
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"vap1","version":"0.2.2","description":"vap1, Both support MicroService and SAP FrameWork, Support IE>9","main":"index.js","author":"Xiang da","license":"ISC"}
1
+ {"name":"vap1","version":"0.2.3","description":"vap1, Both support MicroService and SAP FrameWork, Support IE>9","main":"index.js","author":"Xiang da","license":"ISC"}