@ftjs/core 0.4.5 → 0.5.1
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/dist/form/columns.d.ts +22 -10
- package/dist/form/use-form.d.ts +3 -3
- package/dist/index.js +14 -7
- package/dist/utils.d.ts +1 -1
- package/package.json +1 -1
package/dist/form/columns.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { MaybeRefOrGetter } from 'vue';
|
|
1
|
+
import { MaybeRefOrGetter, VNodeChild } from 'vue';
|
|
2
2
|
import { RecordPath } from '../type-helper';
|
|
3
|
-
type WatchHandler<
|
|
3
|
+
type WatchHandler<F extends Record<string, any>> = (params: {
|
|
4
4
|
val: any;
|
|
5
5
|
oldVal: any;
|
|
6
|
-
form:
|
|
6
|
+
form: F;
|
|
7
7
|
}) => void;
|
|
8
|
-
type Watch<
|
|
9
|
-
handler: WatchHandler<
|
|
8
|
+
type Watch<F extends Record<string, any>> = WatchHandler<F> | {
|
|
9
|
+
handler: WatchHandler<F>;
|
|
10
10
|
deep?: boolean;
|
|
11
11
|
immediate?: boolean;
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
14
14
|
* 实现方需要继承这个interface
|
|
15
15
|
*/
|
|
16
|
-
export interface FtFormColumnBase<
|
|
16
|
+
export interface FtFormColumnBase<F extends Record<string, any>> {
|
|
17
17
|
/**
|
|
18
18
|
* 字段名 `fields` 和 `field` 至少有一个存在
|
|
19
19
|
*
|
|
@@ -21,7 +21,7 @@ export interface FtFormColumnBase<FormData extends Record<string, any>> {
|
|
|
21
21
|
*
|
|
22
22
|
* 如果是在 TableColumns 中,则默认继承其中的 field
|
|
23
23
|
*/
|
|
24
|
-
field?: RecordPath<
|
|
24
|
+
field?: RecordPath<F>;
|
|
25
25
|
/**
|
|
26
26
|
* 字段名数组,当表单需要返回多个值时,使用这个字段
|
|
27
27
|
*
|
|
@@ -31,7 +31,7 @@ export interface FtFormColumnBase<FormData extends Record<string, any>> {
|
|
|
31
31
|
*
|
|
32
32
|
* 如人员信息: [staffId, staffInfoObj, deptInfoObj, ...]
|
|
33
33
|
*/
|
|
34
|
-
fields?: (RecordPath<
|
|
34
|
+
fields?: (RecordPath<F> | "-")[];
|
|
35
35
|
/**
|
|
36
36
|
* 字段标题
|
|
37
37
|
*
|
|
@@ -45,7 +45,7 @@ export interface FtFormColumnBase<FormData extends Record<string, any>> {
|
|
|
45
45
|
/**
|
|
46
46
|
* 监听字段值变化,如果是 `fields` ,则只会监听第一个字段的值变化
|
|
47
47
|
*/
|
|
48
|
-
watch?: Watch<
|
|
48
|
+
watch?: Watch<F>;
|
|
49
49
|
/**
|
|
50
50
|
* 字段默认值
|
|
51
51
|
*/
|
|
@@ -66,7 +66,7 @@ export interface FtFormColumnBase<FormData extends Record<string, any>> {
|
|
|
66
66
|
*
|
|
67
67
|
*/
|
|
68
68
|
value: boolean | string | number | boolean[] | string[] | number[] | /** 返回值表示这个字段是否显示 */ (({ formData, val, }: {
|
|
69
|
-
formData:
|
|
69
|
+
formData: F;
|
|
70
70
|
val: any;
|
|
71
71
|
}) => boolean);
|
|
72
72
|
}[];
|
|
@@ -94,5 +94,17 @@ export interface FtFormColumnBase<FormData extends Record<string, any>> {
|
|
|
94
94
|
* 是否查看模式
|
|
95
95
|
*/
|
|
96
96
|
isView?: MaybeRefOrGetter<boolean>;
|
|
97
|
+
/**
|
|
98
|
+
* 自定义查看模式下的渲染
|
|
99
|
+
*/
|
|
100
|
+
viewRender?: (props: {
|
|
101
|
+
formData: F;
|
|
102
|
+
}) => VNodeChild;
|
|
103
|
+
/**
|
|
104
|
+
* 自定义编辑模式下的渲染
|
|
105
|
+
*/
|
|
106
|
+
editRender?: (props: {
|
|
107
|
+
formData: F;
|
|
108
|
+
}) => VNodeChild;
|
|
97
109
|
}
|
|
98
110
|
export {};
|
package/dist/form/use-form.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ComputedRef } from 'vue';
|
|
2
2
|
import { FtFormColumnBase } from './columns';
|
|
3
|
-
interface FormInject {
|
|
4
|
-
form: ComputedRef<
|
|
3
|
+
interface FormInject<F extends Record<string, any>> {
|
|
4
|
+
form: ComputedRef<F>;
|
|
5
5
|
}
|
|
6
|
-
export declare const useFormInject: () => FormInject | undefined;
|
|
6
|
+
export declare const useFormInject: <F extends Record<string, any> = Record<string, any>>() => FormInject<F> | undefined;
|
|
7
7
|
export interface FtBaseFormProps<F extends Record<string, any>> {
|
|
8
8
|
/**
|
|
9
9
|
* v-model:formData 的值
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { unref, inject, computed, ref, watch,
|
|
1
|
+
import { unref, inject, computed, ref, watch, onScopeDispose, provide, toValue, watchEffect, nextTick } from "vue";
|
|
2
2
|
const isBrowser = typeof window !== "undefined";
|
|
3
3
|
const getField = (column) => {
|
|
4
4
|
var _a;
|
|
@@ -28,16 +28,23 @@ const get = (obj, path) => {
|
|
|
28
28
|
}
|
|
29
29
|
return result;
|
|
30
30
|
};
|
|
31
|
-
const set = (
|
|
31
|
+
const set = (target, path, value) => {
|
|
32
|
+
if (path === "") return;
|
|
32
33
|
const keys = path.split(".");
|
|
34
|
+
let obj = target;
|
|
33
35
|
for (let i = 0; i < keys.length - 1; i++) {
|
|
34
36
|
const key = keys[i];
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
const nextKey = keys[i + 1];
|
|
38
|
+
if (typeof obj !== "object" || obj == null) {
|
|
39
|
+
throw new Error("set 赋值错误, target", obj);
|
|
37
40
|
}
|
|
38
|
-
|
|
41
|
+
if (obj[key] == null) {
|
|
42
|
+
obj[key] = /^\d+$/.test(nextKey) ? [] : {};
|
|
43
|
+
}
|
|
44
|
+
obj = obj[key];
|
|
39
45
|
}
|
|
40
|
-
|
|
46
|
+
const lastKey = keys[keys.length - 1];
|
|
47
|
+
obj[lastKey] = value;
|
|
41
48
|
};
|
|
42
49
|
const has = (obj, path) => {
|
|
43
50
|
const keys = path.split(".");
|
|
@@ -253,7 +260,7 @@ const useForm = (props) => {
|
|
|
253
260
|
immediate: true
|
|
254
261
|
}
|
|
255
262
|
);
|
|
256
|
-
|
|
263
|
+
onScopeDispose(() => {
|
|
257
264
|
watchMap.forEach((cancel) => cancel());
|
|
258
265
|
});
|
|
259
266
|
function runFieldWatch() {
|
package/dist/utils.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export declare const isEmptyStrOrNull: (val: any) => boolean;
|
|
|
8
8
|
*/
|
|
9
9
|
export declare const cloneDeep: <T>(obj: T) => T;
|
|
10
10
|
export declare const get: (obj: any, path: string) => any;
|
|
11
|
-
export declare const set: (
|
|
11
|
+
export declare const set: (target: any, path: string, value: any) => void;
|
|
12
12
|
export declare const has: (obj: any, path: string) => boolean;
|
|
13
13
|
/**
|
|
14
14
|
* 浅层的将对象的属性值(可能是响应式)转换为普通值,不转化getter
|