GLForm.wxs
1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
var isShowFn = function (formData, targetItem) {
var flag = false;
if (targetItem.isShowObj && formData) {
for (var i = 0; i <= targetItem.isShowObj.list.length; i++) {
var item = targetItem.isShowObj.list[i];
if (item == formData[targetItem.isShowObj.attr]) {
flag = true;
break;
}
}
} else {
flag = true;
}
return flag;
};
// 根据 formData 的值和 optionList 计算 picker 的选中索引
var getPickerIndex = function (formData, item) {
if (!formData || !item) {
return 0;
}
var optionList = item.optionList;
var optionId = item.optionId;
var fieldName = item.name;
if (!optionList || optionList.length === 0 || !optionId || !fieldName) {
return 0;
}
var currentValue = formData[fieldName];
if (
currentValue === null ||
currentValue === undefined ||
currentValue === ""
) {
return 0;
}
// WXS 不支持 String(),使用 "" + value 的方式转换为字符串
var currentValueStr = "" + currentValue;
for (var i = 0; i < optionList.length; i++) {
var option = optionList[i];
if (!option) continue;
// 在 WXS 中,需要使用字符串键名访问对象属性
var optionValue = null;
if (optionId === "value") {
optionValue = option.value;
} else if (optionId === "name") {
optionValue = option.name;
} else {
optionValue = option[optionId];
}
if (optionValue === null || optionValue === undefined) continue;
// WXS 不支持 String(),使用 "" + value 的方式转换为字符串
var optionValueStr = "" + optionValue;
// 比较字符串值(已确保数据类型一致,直接字符串比较即可)
if (optionValueStr === currentValueStr) {
return i;
}
}
return 0;
};
module.exports = {
isShowFn: isShowFn,
getPickerIndex: getPickerIndex,
};