@vunk/form 1.1.47 → 1.1.48
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/components/form/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import { getValue } from '@vunk/core/shared/helper';
|
|
|
8
8
|
import { VkfTemplatesDefault } from '@vunk/form/components/templates-default';
|
|
9
9
|
import { VkfTemplatesLayout } from '@vunk/form/components/templates-layout';
|
|
10
10
|
import { pickObject } from '@vunk/core/shared/utils-object';
|
|
11
|
+
import { genTemplateIfFunc } from '@vunk/form/shared/form';
|
|
11
12
|
|
|
12
13
|
var __defProp$1 = Object.defineProperty;
|
|
13
14
|
var __defProps$1 = Object.defineProperties;
|
|
@@ -163,6 +164,13 @@ const _sfc_main = defineComponent({
|
|
|
163
164
|
a.push(c);
|
|
164
165
|
return a;
|
|
165
166
|
}
|
|
167
|
+
if (Reflect.has(c, "templateIf")) {
|
|
168
|
+
const templateIfFunc = genTemplateIfFunc(c.templateIf);
|
|
169
|
+
const flag = templateIfFunc(props2.data);
|
|
170
|
+
if (!flag) {
|
|
171
|
+
return a;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
166
174
|
const colItem = genColItem(c, props2.colSource);
|
|
167
175
|
if (!lastRow || getRowEmptySpan(lastRow) < itemSpan) {
|
|
168
176
|
a.push(genRowItem(colItem, props2.rowSource));
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { defineComponent, shallowReactive, provide, h, nextTick } from 'vue';
|
|
2
|
+
import { genTemplateIfFunc } from '@vunk/form/shared/form';
|
|
2
3
|
|
|
3
4
|
const props = {
|
|
4
5
|
source: {
|
|
@@ -56,25 +57,13 @@ const VkfFormItemRenderer = defineComponent({
|
|
|
56
57
|
Reflect.deleteProperty(slotData, "templateType");
|
|
57
58
|
Reflect.deleteProperty(slotData, "templateSlots");
|
|
58
59
|
Reflect.deleteProperty(slotData, "templateIf");
|
|
59
|
-
const createTemplateIf = () => {
|
|
60
|
-
if (typeof c.templateIf === "boolean") {
|
|
61
|
-
const flag = c.templateIf;
|
|
62
|
-
return () => flag;
|
|
63
|
-
} else if (typeof c.templateIf === "string") {
|
|
64
|
-
const templateIf = new Function("data", c.templateIf);
|
|
65
|
-
return templateIf;
|
|
66
|
-
} else if (typeof c.templateIf === "function") {
|
|
67
|
-
return c.templateIf;
|
|
68
|
-
}
|
|
69
|
-
return () => true;
|
|
70
|
-
};
|
|
71
60
|
const nodes = templateInstances[c.templateType].slots.default?.({
|
|
72
61
|
data: slotData,
|
|
73
62
|
raw: c,
|
|
74
63
|
Renderer,
|
|
75
64
|
k: currentK,
|
|
76
65
|
key: currentK.join(",") + "-" + c.templateType + "-" + c?.prop || "no-prop",
|
|
77
|
-
templateIf:
|
|
66
|
+
templateIf: genTemplateIfFunc(c.templateIf)
|
|
78
67
|
});
|
|
79
68
|
nodes && a.push(nodes);
|
|
80
69
|
} else if (c.templateSlots?.default) {
|
package/package.json
CHANGED
package/shared/form/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Func, NormalObject } from '@vunk/core';
|
|
1
2
|
/**
|
|
2
3
|
* 表单验证失败, 处理方式
|
|
3
4
|
* 消息提示
|
|
@@ -7,3 +8,11 @@ export declare const validateCatch: (err: any, init?: {
|
|
|
7
8
|
prefix?: string;
|
|
8
9
|
suffix?: string;
|
|
9
10
|
}) => void;
|
|
11
|
+
/**
|
|
12
|
+
* 根据 templateIf 生成 显隐函数
|
|
13
|
+
* @param templateIfRaw
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
export declare const genTemplateIfFunc: Func<[
|
|
17
|
+
any
|
|
18
|
+
], (e?: NormalObject) => boolean>;
|
package/shared/form/index.js
CHANGED
|
@@ -14,5 +14,17 @@ const validateCatch = (err, init = {}) => {
|
|
|
14
14
|
message: msg
|
|
15
15
|
});
|
|
16
16
|
};
|
|
17
|
+
const genTemplateIfFunc = (templateIfRaw) => {
|
|
18
|
+
if (typeof templateIfRaw === "boolean") {
|
|
19
|
+
const flag = templateIfRaw;
|
|
20
|
+
return () => flag;
|
|
21
|
+
} else if (typeof templateIfRaw === "string") {
|
|
22
|
+
const templateIf = new Function("data", templateIfRaw);
|
|
23
|
+
return templateIf;
|
|
24
|
+
} else if (typeof templateIfRaw === "function") {
|
|
25
|
+
return templateIfRaw;
|
|
26
|
+
}
|
|
27
|
+
return () => true;
|
|
28
|
+
};
|
|
17
29
|
|
|
18
|
-
export { validateCatch };
|
|
30
|
+
export { genTemplateIfFunc, validateCatch };
|