form-driver 0.4.4 → 0.4.5
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/package.json
CHANGED
|
@@ -1,32 +1,31 @@
|
|
|
1
|
-
|
|
2
1
|
import React from "react";
|
|
3
|
-
import { Ajax } from
|
|
2
|
+
import { Ajax } from "../../../framework/Ajax";
|
|
4
3
|
import _ from "lodash";
|
|
5
|
-
import { MUtil } from
|
|
6
|
-
import { Cascader } from
|
|
7
|
-
import { MFieldSchema } from
|
|
8
|
-
import { Picker } from
|
|
4
|
+
import { MUtil } from "../../../framework/MUtil";
|
|
5
|
+
import { Cascader } from "antd";
|
|
6
|
+
import { MFieldSchema } from "../../../framework/Schema";
|
|
7
|
+
import { Picker } from "antd-mobile";
|
|
9
8
|
import { BaseViewer } from "../../..";
|
|
10
9
|
|
|
11
|
-
|
|
12
10
|
export function labelExpr(d: any, remote: MFieldSchema["remote"]) {
|
|
13
|
-
let script =
|
|
11
|
+
let script =
|
|
12
|
+
"const {" + _.keys(d).join(",") + "} = d; return " + remote.labelExpr;
|
|
14
13
|
return new Function("d", "_", script)(d, _);
|
|
15
14
|
}
|
|
16
15
|
|
|
17
16
|
export function convert(node = {}, dataPath, valuePath, childPath) {
|
|
18
17
|
var newNode = {};
|
|
19
|
-
newNode[
|
|
20
|
-
newNode[
|
|
18
|
+
newNode["value"] = node[valuePath];
|
|
19
|
+
newNode["label"] = node[dataPath];
|
|
21
20
|
|
|
22
21
|
if (node[childPath] && node[childPath].length > 0) {
|
|
23
22
|
let child = [];
|
|
24
23
|
node[childPath].map((item) => {
|
|
25
|
-
child.push(convert(item, dataPath, valuePath, childPath))
|
|
26
|
-
})
|
|
27
|
-
newNode[
|
|
24
|
+
child.push(convert(item, dataPath, valuePath, childPath));
|
|
25
|
+
});
|
|
26
|
+
newNode["children"] = child;
|
|
28
27
|
}
|
|
29
|
-
return newNode
|
|
28
|
+
return newNode;
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
/* 树的查找 如该数据格式下查找id为3的元素
|
|
@@ -36,19 +35,25 @@ export function findById(node, id, labelPath, valuePath, childPath) {
|
|
|
36
35
|
if (node[valuePath] == id) {
|
|
37
36
|
let res = {
|
|
38
37
|
label: node[labelPath],
|
|
39
|
-
value: id
|
|
40
|
-
}
|
|
38
|
+
value: id,
|
|
39
|
+
};
|
|
41
40
|
return res;
|
|
42
41
|
}
|
|
43
42
|
if (node[childPath] && node[childPath].length > 0) {
|
|
44
43
|
for (var i = 0; i < node[childPath].length; i++) {
|
|
45
|
-
let findItem = findById(
|
|
44
|
+
let findItem = findById(
|
|
45
|
+
node[childPath][i],
|
|
46
|
+
id,
|
|
47
|
+
labelPath,
|
|
48
|
+
valuePath,
|
|
49
|
+
childPath
|
|
50
|
+
);
|
|
46
51
|
if (findItem !== -1) {
|
|
47
|
-
return findItem
|
|
52
|
+
return findItem;
|
|
48
53
|
}
|
|
49
54
|
}
|
|
50
55
|
}
|
|
51
|
-
return -1
|
|
56
|
+
return -1;
|
|
52
57
|
}
|
|
53
58
|
|
|
54
59
|
export class ACascadePicker extends BaseViewer {
|
|
@@ -68,8 +73,9 @@ export class ACascadePicker extends BaseViewer {
|
|
|
68
73
|
const p = this.props.schema.props ?? {};
|
|
69
74
|
|
|
70
75
|
if (MUtil.phoneLike()) {
|
|
71
|
-
return
|
|
72
|
-
|
|
76
|
+
return (
|
|
77
|
+
<>
|
|
78
|
+
{/* <Picker
|
|
73
79
|
data={this.props.schema.option}
|
|
74
80
|
extra="请选择(可选)"
|
|
75
81
|
cols={2}
|
|
@@ -86,29 +92,41 @@ export class ACascadePicker extends BaseViewer {
|
|
|
86
92
|
>
|
|
87
93
|
<div className="backfill"> {show.length > 0 ? show.join('-') : '请点击选择' } </div>
|
|
88
94
|
</Picker> */}
|
|
89
|
-
|
|
95
|
+
</>
|
|
96
|
+
);
|
|
90
97
|
} else {
|
|
91
|
-
return
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
98
|
+
return (
|
|
99
|
+
<Cascader
|
|
100
|
+
key="v"
|
|
101
|
+
options={candidate}
|
|
102
|
+
defaultValue={show.map((item) => item.value)}
|
|
103
|
+
changeOnSelect
|
|
104
|
+
placeholder={super.getPlaceholder()}
|
|
105
|
+
onClear={() => {
|
|
106
|
+
super.changeValue([]);
|
|
107
|
+
}}
|
|
108
|
+
onChange={(v) => {
|
|
109
|
+
const vLabel = [];
|
|
110
|
+
v.map((item) => {
|
|
111
|
+
let findItem;
|
|
112
|
+
candidate.map((dataItem) => {
|
|
113
|
+
findItem = findById(
|
|
114
|
+
dataItem,
|
|
115
|
+
item,
|
|
116
|
+
"label",
|
|
117
|
+
"value",
|
|
118
|
+
"children"
|
|
119
|
+
);
|
|
120
|
+
if (findItem != -1) {
|
|
121
|
+
vLabel.push(findItem);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
super.changeValue(vLabel);
|
|
126
|
+
}}
|
|
127
|
+
{...p}
|
|
128
|
+
/>
|
|
129
|
+
);
|
|
112
130
|
}
|
|
113
131
|
}
|
|
114
132
|
}
|
|
@@ -95,21 +95,20 @@ export class AWeight extends Viewer<AWeightState> {
|
|
|
95
95
|
private totalWeight: any = 0;
|
|
96
96
|
private allValues: any = [];
|
|
97
97
|
constructor(props: MProp) {
|
|
98
|
-
console.log("AWeight props", props);
|
|
99
98
|
super(props);
|
|
100
99
|
const { schema } = props;
|
|
101
100
|
this._enumFields = MUtil.option(this.props.schema);
|
|
102
|
-
console.log("this._enumFields", this._enumFields);
|
|
103
101
|
this.totalWeight = (schema as any).weight;
|
|
104
102
|
this.allValues =
|
|
105
103
|
this._enumFields?.map((i) => {
|
|
106
104
|
const values = super.getValue();
|
|
107
|
-
return values?.find((v) => i.value === v.label)?.value;
|
|
105
|
+
return values?.find((v) => i.value === v.label)?.value ?? 0;
|
|
108
106
|
}) ?? new Array(this._enumFields.length).fill(0);
|
|
109
107
|
this.state = {
|
|
110
108
|
allSliderValues: this.allValues,
|
|
111
109
|
ctrlVersion: 1,
|
|
112
110
|
};
|
|
111
|
+
console.log("this.state", this.state);
|
|
113
112
|
}
|
|
114
113
|
|
|
115
114
|
componentDidMount(): void {
|