form-driver 0.4.7 → 0.4.9

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/es/m3.css CHANGED
@@ -503,6 +503,12 @@ table.M3_table tr:last-child td {
503
503
  width: 40px;
504
504
  }
505
505
 
506
+ .weight-slider .ant-slider-handle {
507
+ width: 20px;
508
+ height: 20px;
509
+ margin-top: -8px;
510
+ }
511
+
506
512
  .form-driver-plugin-richtext-viewer-wrap .richtext-viewer-more {
507
513
  text-align: center;
508
514
  box-shadow: 0px -5px 5px rgba(232,232,232,0.38039);
package/es/m3.js CHANGED
@@ -20440,9 +20440,9 @@ var InputSlider = /*#__PURE__*/memo(function (props) {
20440
20440
  };
20441
20441
 
20442
20442
  return jsxs(Row, {
20443
- gutter: [12, 12],
20443
+ gutter: [18, 12],
20444
20444
  children: [jsx(Col, {
20445
- span: 4,
20445
+ span: 5,
20446
20446
  children: jsx(InputNumber, {
20447
20447
  precision: 0,
20448
20448
  style: {
@@ -20457,14 +20457,15 @@ var InputSlider = /*#__PURE__*/memo(function (props) {
20457
20457
  onBlur: onAfterChange
20458
20458
  })
20459
20459
  }), jsx(Col, {
20460
- span: 20,
20460
+ span: 19,
20461
20461
  children: jsx(Slider, {
20462
20462
  min: min,
20463
20463
  max: max,
20464
20464
  marks: (_marks = {}, _marks[min] = min, _marks[max] = max, _marks),
20465
20465
  onChange: _onChange,
20466
20466
  onAfterChange: onAfterChange,
20467
- value: typeof value === "number" ? value : 0
20467
+ value: typeof value === "number" ? value : 0,
20468
+ className: "weight-slider"
20468
20469
  })
20469
20470
  })]
20470
20471
  });
@@ -20499,6 +20500,7 @@ var AWeight = /*#__PURE__*/function (_Viewer) {
20499
20500
  })) == null ? void 0 : _values$find.value) != null ? _values$find$value : 0;
20500
20501
  })) != null ? _this$_enumFields$map : new Array(_this._enumFields.length).fill(0);
20501
20502
  _this.state = {
20503
+ hasAssignWeight: 0,
20502
20504
  allSliderValues: _this.allValues,
20503
20505
  ctrlVersion: 1
20504
20506
  }; // 初始化数据,避免出现 null 的情况
@@ -20584,15 +20586,21 @@ var AWeight = /*#__PURE__*/function (_Viewer) {
20584
20586
  return current + (target - current) * factor;
20585
20587
  };
20586
20588
 
20589
+ _proto.calAssignWeight = function calAssignWeight() {
20590
+ var values = _Viewer.prototype.getValue.call(this);
20591
+
20592
+ return values.reduce(function (total, current) {
20593
+ return total + current.value;
20594
+ }, 0);
20595
+ };
20596
+
20587
20597
  _proto.element = function element() {
20588
20598
  var _this3 = this;
20589
20599
 
20590
- var hasAssignWeight = this.state.allSliderValues.reduce(function (total, current) {
20591
- return total + current;
20592
- }, 0);
20593
20600
  return jsxs("div", {
20594
20601
  style: {
20595
- padding: 16
20602
+ padding: 16,
20603
+ paddingBottom: 32
20596
20604
  },
20597
20605
  children: [this._enumFields.map(function (option, index) {
20598
20606
  return jsxs("div", {
@@ -20612,32 +20620,37 @@ var AWeight = /*#__PURE__*/function (_Viewer) {
20612
20620
  label: _this3._enumFields[index].value,
20613
20621
  value: n
20614
20622
  };
20615
- })); // 使用节流控制联动更新频率
20616
-
20617
-
20618
- var now = Date.now();
20619
-
20620
- if (now - _this3.lastUpdateTime >= _this3.THROTTLE_DELAY) {
20621
- _this3.updateLinkedSliders(numbers, index, isInputChange);
20623
+ }));
20622
20624
 
20623
- _this3.lastUpdateTime = now;
20624
- } else {
20625
- // 使用防抖确保最后一次更新被执行
20626
- if (_this3.debounceTimer) {
20627
- clearTimeout(_this3.debounceTimer);
20628
- }
20629
-
20630
- _this3.debounceTimer = setTimeout(function () {
20631
- _this3.updateLinkedSliders(numbers, index, isInputChange);
20625
+ _this3.setState({
20626
+ allSliderValues: numbers
20627
+ }); // 使用节流控制联动更新频率
20628
+ // const now = Date.now();
20629
+ // if (now - this.lastUpdateTime >= this.THROTTLE_DELAY) {
20630
+ // this.updateLinkedSliders(numbers, index, isInputChange);
20631
+ // this.lastUpdateTime = now;
20632
+ // } else {
20633
+ // // 使用防抖确保最后一次更新被执行
20634
+ // if (this.debounceTimer) {
20635
+ // clearTimeout(this.debounceTimer);
20636
+ // }
20637
+ // this.debounceTimer = setTimeout(() => {
20638
+ // this.updateLinkedSliders(numbers, index, isInputChange);
20639
+ // this.lastUpdateTime = Date.now();
20640
+ // }, this.THROTTLE_DELAY);
20641
+ // }
20632
20642
 
20633
- _this3.lastUpdateTime = Date.now();
20634
- }, _this3.THROTTLE_DELAY);
20635
- }
20636
20643
  },
20637
20644
  value: _this3.state.allSliderValues[index],
20638
20645
  onAfterChange: function onAfterChange(value) {
20639
20646
  // 结束更新后,再重设一遍数据,确保数据的准确性
20640
20647
  _this3.updateLinkedSliders(_this3.state.allSliderValues, index, true);
20648
+
20649
+ console.log("onAfterChange", _this3.calAssignWeight());
20650
+
20651
+ _this3.setState({
20652
+ hasAssignWeight: _this3.calAssignWeight()
20653
+ });
20641
20654
  },
20642
20655
  max: _this3.totalWeight,
20643
20656
  min: 0
@@ -20646,9 +20659,9 @@ var AWeight = /*#__PURE__*/function (_Viewer) {
20646
20659
  }), this.totalWeight > 0 && this._enumFields.length > 0 ? jsxs("div", {
20647
20660
  children: ["\u63D0\u793A\uFF1A\u603B\u6BD4\u91CD\u5FC5\u987B\u4E3A", this.totalWeight, "\uFF0C\u5DF2\u5206\u914D\u6BD4\u91CD\uFF1A", jsxs("span", {
20648
20661
  style: {
20649
- color: hasAssignWeight > this.totalWeight ? "red" : "#000"
20662
+ color: this.state.hasAssignWeight > this.totalWeight ? "red" : "#000"
20650
20663
  },
20651
- children: [hasAssignWeight, hasAssignWeight > this.totalWeight ? "\uFF0C\u8BF7\u4FEE\u6539" : ""]
20664
+ children: [this.state.hasAssignWeight, this.state.hasAssignWeight > this.totalWeight ? "\uFF0C\u8BF7\u4FEE\u6539" : ""]
20652
20665
  })]
20653
20666
  }) : null]
20654
20667
  });
@@ -21608,7 +21621,7 @@ function validateWeightValue(a, schema, value, path) {
21608
21621
  // 验证总比重是否小于目标值
21609
21622
 
21610
21623
 
21611
- if (schema.weight && currentTotal < schema.weight && currentTotal !== 0) {
21624
+ if (schema.weight && currentTotal < schema.weight) {
21612
21625
  return {
21613
21626
  message: "\u5DF2\u5206\u914D\u6BD4\u91CD\u4E0D\u5F97\u5C0F\u4E8E\u603B\u6BD4\u91CD",
21614
21627
  path: path
package/lib/m3.css CHANGED
@@ -503,6 +503,12 @@ table.M3_table tr:last-child td {
503
503
  width: 40px;
504
504
  }
505
505
 
506
+ .weight-slider .ant-slider-handle {
507
+ width: 20px;
508
+ height: 20px;
509
+ margin-top: -8px;
510
+ }
511
+
506
512
  .form-driver-plugin-richtext-viewer-wrap .richtext-viewer-more {
507
513
  text-align: center;
508
514
  box-shadow: 0px -5px 5px rgba(232,232,232,0.38039);
package/lib/m3.js CHANGED
@@ -20464,9 +20464,9 @@ var InputSlider = /*#__PURE__*/React.memo(function (props) {
20464
20464
  };
20465
20465
 
20466
20466
  return jsxRuntime.jsxs(antd.Row, {
20467
- gutter: [12, 12],
20467
+ gutter: [18, 12],
20468
20468
  children: [jsxRuntime.jsx(antd.Col, {
20469
- span: 4,
20469
+ span: 5,
20470
20470
  children: jsxRuntime.jsx(antd.InputNumber, {
20471
20471
  precision: 0,
20472
20472
  style: {
@@ -20481,14 +20481,15 @@ var InputSlider = /*#__PURE__*/React.memo(function (props) {
20481
20481
  onBlur: onAfterChange
20482
20482
  })
20483
20483
  }), jsxRuntime.jsx(antd.Col, {
20484
- span: 20,
20484
+ span: 19,
20485
20485
  children: jsxRuntime.jsx(antd.Slider, {
20486
20486
  min: min,
20487
20487
  max: max,
20488
20488
  marks: (_marks = {}, _marks[min] = min, _marks[max] = max, _marks),
20489
20489
  onChange: _onChange,
20490
20490
  onAfterChange: onAfterChange,
20491
- value: typeof value === "number" ? value : 0
20491
+ value: typeof value === "number" ? value : 0,
20492
+ className: "weight-slider"
20492
20493
  })
20493
20494
  })]
20494
20495
  });
@@ -20523,6 +20524,7 @@ var AWeight = /*#__PURE__*/function (_Viewer) {
20523
20524
  })) == null ? void 0 : _values$find.value) != null ? _values$find$value : 0;
20524
20525
  })) != null ? _this$_enumFields$map : new Array(_this._enumFields.length).fill(0);
20525
20526
  _this.state = {
20527
+ hasAssignWeight: 0,
20526
20528
  allSliderValues: _this.allValues,
20527
20529
  ctrlVersion: 1
20528
20530
  }; // 初始化数据,避免出现 null 的情况
@@ -20608,15 +20610,21 @@ var AWeight = /*#__PURE__*/function (_Viewer) {
20608
20610
  return current + (target - current) * factor;
20609
20611
  };
20610
20612
 
20613
+ _proto.calAssignWeight = function calAssignWeight() {
20614
+ var values = _Viewer.prototype.getValue.call(this);
20615
+
20616
+ return values.reduce(function (total, current) {
20617
+ return total + current.value;
20618
+ }, 0);
20619
+ };
20620
+
20611
20621
  _proto.element = function element() {
20612
20622
  var _this3 = this;
20613
20623
 
20614
- var hasAssignWeight = this.state.allSliderValues.reduce(function (total, current) {
20615
- return total + current;
20616
- }, 0);
20617
20624
  return jsxRuntime.jsxs("div", {
20618
20625
  style: {
20619
- padding: 16
20626
+ padding: 16,
20627
+ paddingBottom: 32
20620
20628
  },
20621
20629
  children: [this._enumFields.map(function (option, index) {
20622
20630
  return jsxRuntime.jsxs("div", {
@@ -20636,32 +20644,37 @@ var AWeight = /*#__PURE__*/function (_Viewer) {
20636
20644
  label: _this3._enumFields[index].value,
20637
20645
  value: n
20638
20646
  };
20639
- })); // 使用节流控制联动更新频率
20640
-
20641
-
20642
- var now = Date.now();
20643
-
20644
- if (now - _this3.lastUpdateTime >= _this3.THROTTLE_DELAY) {
20645
- _this3.updateLinkedSliders(numbers, index, isInputChange);
20647
+ }));
20646
20648
 
20647
- _this3.lastUpdateTime = now;
20648
- } else {
20649
- // 使用防抖确保最后一次更新被执行
20650
- if (_this3.debounceTimer) {
20651
- clearTimeout(_this3.debounceTimer);
20652
- }
20653
-
20654
- _this3.debounceTimer = setTimeout(function () {
20655
- _this3.updateLinkedSliders(numbers, index, isInputChange);
20649
+ _this3.setState({
20650
+ allSliderValues: numbers
20651
+ }); // 使用节流控制联动更新频率
20652
+ // const now = Date.now();
20653
+ // if (now - this.lastUpdateTime >= this.THROTTLE_DELAY) {
20654
+ // this.updateLinkedSliders(numbers, index, isInputChange);
20655
+ // this.lastUpdateTime = now;
20656
+ // } else {
20657
+ // // 使用防抖确保最后一次更新被执行
20658
+ // if (this.debounceTimer) {
20659
+ // clearTimeout(this.debounceTimer);
20660
+ // }
20661
+ // this.debounceTimer = setTimeout(() => {
20662
+ // this.updateLinkedSliders(numbers, index, isInputChange);
20663
+ // this.lastUpdateTime = Date.now();
20664
+ // }, this.THROTTLE_DELAY);
20665
+ // }
20656
20666
 
20657
- _this3.lastUpdateTime = Date.now();
20658
- }, _this3.THROTTLE_DELAY);
20659
- }
20660
20667
  },
20661
20668
  value: _this3.state.allSliderValues[index],
20662
20669
  onAfterChange: function onAfterChange(value) {
20663
20670
  // 结束更新后,再重设一遍数据,确保数据的准确性
20664
20671
  _this3.updateLinkedSliders(_this3.state.allSliderValues, index, true);
20672
+
20673
+ console.log("onAfterChange", _this3.calAssignWeight());
20674
+
20675
+ _this3.setState({
20676
+ hasAssignWeight: _this3.calAssignWeight()
20677
+ });
20665
20678
  },
20666
20679
  max: _this3.totalWeight,
20667
20680
  min: 0
@@ -20670,9 +20683,9 @@ var AWeight = /*#__PURE__*/function (_Viewer) {
20670
20683
  }), this.totalWeight > 0 && this._enumFields.length > 0 ? jsxRuntime.jsxs("div", {
20671
20684
  children: ["\u63D0\u793A\uFF1A\u603B\u6BD4\u91CD\u5FC5\u987B\u4E3A", this.totalWeight, "\uFF0C\u5DF2\u5206\u914D\u6BD4\u91CD\uFF1A", jsxRuntime.jsxs("span", {
20672
20685
  style: {
20673
- color: hasAssignWeight > this.totalWeight ? "red" : "#000"
20686
+ color: this.state.hasAssignWeight > this.totalWeight ? "red" : "#000"
20674
20687
  },
20675
- children: [hasAssignWeight, hasAssignWeight > this.totalWeight ? "\uFF0C\u8BF7\u4FEE\u6539" : ""]
20688
+ children: [this.state.hasAssignWeight, this.state.hasAssignWeight > this.totalWeight ? "\uFF0C\u8BF7\u4FEE\u6539" : ""]
20676
20689
  })]
20677
20690
  }) : null]
20678
20691
  });
@@ -21632,7 +21645,7 @@ function validateWeightValue(a, schema, value, path) {
21632
21645
  // 验证总比重是否小于目标值
21633
21646
 
21634
21647
 
21635
- if (schema.weight && currentTotal < schema.weight && currentTotal !== 0) {
21648
+ if (schema.weight && currentTotal < schema.weight) {
21636
21649
  return {
21637
21650
  message: "\u5DF2\u5206\u914D\u6BD4\u91CD\u4E0D\u5F97\u5C0F\u4E8E\u603B\u6BD4\u91CD",
21638
21651
  path: path
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "form-driver",
3
- "version": "0.4.7",
3
+ "version": "0.4.9",
4
4
  "description": "An efficient framework for creating forms.",
5
5
  "license": "MIT",
6
6
  "authors": [
@@ -32,7 +32,7 @@ function validateWeightValue(
32
32
 
33
33
  // 比重题的校验文案都是固定显示在表单上,所以返回的 message 都是空的
34
34
  // 验证总比重是否小于目标值
35
- if (schema.weight && currentTotal < schema.weight && currentTotal !== 0) {
35
+ if (schema.weight && currentTotal < schema.weight) {
36
36
  return {
37
37
  message: `已分配比重不得小于总比重`,
38
38
  path,
@@ -0,0 +1,7 @@
1
+ .weight-slider {
2
+ .ant-slider-handle {
3
+ width: 20px;
4
+ height: 20px;
5
+ margin-top: -8px;
6
+ }
7
+ }
@@ -4,7 +4,7 @@ import { MEnumField, MProp, ValueConst } from "../../../framework/Schema";
4
4
  import { ViewerState } from "../../BaseViewer";
5
5
  import { Slider, Row, Col, InputNumber } from "antd";
6
6
  import { MUtil } from "../../../framework/MUtil";
7
-
7
+ import "./AWeight.less";
8
8
  export interface AWeightProps {
9
9
  /** 总比值,默认100 */
10
10
  total?: number;
@@ -34,6 +34,7 @@ export interface AWeightProps {
34
34
  // 扩展 ViewerState 接口
35
35
  interface AWeightState extends ViewerState {
36
36
  allSliderValues: any;
37
+ hasAssignWeight: number;
37
38
  }
38
39
 
39
40
  const mockOptions = [
@@ -58,8 +59,8 @@ const InputSlider = memo((props: any) => {
58
59
  };
59
60
 
60
61
  return (
61
- <Row gutter={[12, 12]}>
62
- <Col span={4}>
62
+ <Row gutter={[18, 12]}>
63
+ <Col span={5}>
63
64
  <InputNumber
64
65
  precision={0}
65
66
  style={{ width: "100%" }}
@@ -70,7 +71,7 @@ const InputSlider = memo((props: any) => {
70
71
  onBlur={onAfterChange}
71
72
  />
72
73
  </Col>
73
- <Col span={20}>
74
+ <Col span={19}>
74
75
  <Slider
75
76
  min={min}
76
77
  max={max}
@@ -78,6 +79,7 @@ const InputSlider = memo((props: any) => {
78
79
  onChange={onChange}
79
80
  onAfterChange={onAfterChange}
80
81
  value={typeof value === "number" ? value : 0}
82
+ className="weight-slider"
81
83
  />
82
84
  </Col>
83
85
  </Row>
@@ -105,6 +107,7 @@ export class AWeight extends Viewer<AWeightState> {
105
107
  return values?.find((v) => i.value === v.label)?.value ?? 0;
106
108
  }) ?? new Array(this._enumFields.length).fill(0);
107
109
  this.state = {
110
+ hasAssignWeight: 0,
108
111
  allSliderValues: this.allValues,
109
112
  ctrlVersion: 1,
110
113
  };
@@ -190,13 +193,14 @@ export class AWeight extends Viewer<AWeightState> {
190
193
  return current + (target - current) * factor;
191
194
  }
192
195
 
196
+ private calAssignWeight() {
197
+ const values = super.getValue();
198
+ return values.reduce((total, current) => total + current.value, 0);
199
+ }
200
+
193
201
  element() {
194
- const hasAssignWeight = this.state.allSliderValues.reduce(
195
- (total, current) => total + current,
196
- 0
197
- );
198
202
  return (
199
- <div style={{ padding: 16 }}>
203
+ <div style={{ padding: 16, paddingBottom: 32 }}>
200
204
  {this._enumFields.map((option, index) => {
201
205
  return (
202
206
  <div key={(option as any).value}>
@@ -215,22 +219,25 @@ export class AWeight extends Viewer<AWeightState> {
215
219
  };
216
220
  })
217
221
  );
222
+ this.setState({
223
+ allSliderValues: numbers,
224
+ });
218
225
 
219
226
  // 使用节流控制联动更新频率
220
- const now = Date.now();
221
- if (now - this.lastUpdateTime >= this.THROTTLE_DELAY) {
222
- this.updateLinkedSliders(numbers, index, isInputChange);
223
- this.lastUpdateTime = now;
224
- } else {
225
- // 使用防抖确保最后一次更新被执行
226
- if (this.debounceTimer) {
227
- clearTimeout(this.debounceTimer);
228
- }
229
- this.debounceTimer = setTimeout(() => {
230
- this.updateLinkedSliders(numbers, index, isInputChange);
231
- this.lastUpdateTime = Date.now();
232
- }, this.THROTTLE_DELAY);
233
- }
227
+ // const now = Date.now();
228
+ // if (now - this.lastUpdateTime >= this.THROTTLE_DELAY) {
229
+ // this.updateLinkedSliders(numbers, index, isInputChange);
230
+ // this.lastUpdateTime = now;
231
+ // } else {
232
+ // // 使用防抖确保最后一次更新被执行
233
+ // if (this.debounceTimer) {
234
+ // clearTimeout(this.debounceTimer);
235
+ // }
236
+ // this.debounceTimer = setTimeout(() => {
237
+ // this.updateLinkedSliders(numbers, index, isInputChange);
238
+ // this.lastUpdateTime = Date.now();
239
+ // }, this.THROTTLE_DELAY);
240
+ // }
234
241
  }}
235
242
  value={this.state.allSliderValues[index]}
236
243
  onAfterChange={(value) => {
@@ -240,6 +247,10 @@ export class AWeight extends Viewer<AWeightState> {
240
247
  index,
241
248
  true
242
249
  );
250
+ console.log("onAfterChange", this.calAssignWeight());
251
+ this.setState({
252
+ hasAssignWeight: this.calAssignWeight(),
253
+ });
243
254
  }}
244
255
  max={this.totalWeight}
245
256
  min={0}
@@ -252,11 +263,14 @@ export class AWeight extends Viewer<AWeightState> {
252
263
  提示:总比重必须为{this.totalWeight},已分配比重:
253
264
  <span
254
265
  style={{
255
- color: hasAssignWeight > this.totalWeight ? "red" : "#000",
266
+ color:
267
+ this.state.hasAssignWeight > this.totalWeight
268
+ ? "red"
269
+ : "#000",
256
270
  }}
257
271
  >
258
- {hasAssignWeight}
259
- {hasAssignWeight > this.totalWeight ? `,请修改` : ""}
272
+ {this.state.hasAssignWeight}
273
+ {this.state.hasAssignWeight > this.totalWeight ? `,请修改` : ""}
260
274
  </span>
261
275
  </div>
262
276
  ) : null}
@@ -2,6 +2,7 @@
2
2
  import { Viewer } from "../../BaseViewer";
3
3
  import { MEnumField, MProp, ValueConst } from "../../../framework/Schema";
4
4
  import { ViewerState } from "../../BaseViewer";
5
+ import "./AWeight.less";
5
6
  export interface AWeightProps {
6
7
  /** 总比值,默认100 */
7
8
  total?: number;
@@ -22,6 +23,7 @@ export interface AWeightProps {
22
23
  }
23
24
  interface AWeightState extends ViewerState {
24
25
  allSliderValues: any;
26
+ hasAssignWeight: number;
25
27
  }
26
28
  export declare class AWeight extends Viewer<AWeightState> {
27
29
  _enumFields: MEnumField[];
@@ -37,6 +39,7 @@ export declare class AWeight extends Viewer<AWeightState> {
37
39
  componentDidUpdate(pre: any, cur: any): void;
38
40
  private updateLinkedSliders;
39
41
  private smoothValue;
42
+ private calAssignWeight;
40
43
  element(): JSX.Element;
41
44
  }
42
45
  export {};