@ftjs/core 0.4.3 → 0.5.0
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 +25 -9
- package/dist/type-helper.d.ts +6 -0
- 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, onUnmounted, provide, toValue, nextTick } from "vue";
|
|
1
|
+
import { unref, inject, computed, ref, watch, onUnmounted, provide, toValue, watchEffect, nextTick } from "vue";
|
|
2
2
|
const isBrowser = typeof window !== "undefined";
|
|
3
3
|
const getField = (column) => {
|
|
4
4
|
var _a;
|
|
@@ -104,10 +104,18 @@ const useColumnsChecked = (columns, cache) => {
|
|
|
104
104
|
});
|
|
105
105
|
return Object.fromEntries(entries);
|
|
106
106
|
});
|
|
107
|
-
const storageV =
|
|
107
|
+
const storageV = computed(() => {
|
|
108
|
+
return getStorage(storageKey, toValue(cache));
|
|
109
|
+
});
|
|
108
110
|
const vRef = ref(
|
|
109
|
-
|
|
111
|
+
{}
|
|
110
112
|
);
|
|
113
|
+
watchEffect(() => {
|
|
114
|
+
vRef.value = {
|
|
115
|
+
...columnsV.value,
|
|
116
|
+
...storageV.value
|
|
117
|
+
};
|
|
118
|
+
});
|
|
111
119
|
const columnsChecked = computed({
|
|
112
120
|
get() {
|
|
113
121
|
return Object.entries(vRef.value).filter(([_, show]) => show).map(([field]) => field);
|
|
@@ -121,7 +129,7 @@ const useColumnsChecked = (columns, cache) => {
|
|
|
121
129
|
return [field, show];
|
|
122
130
|
});
|
|
123
131
|
vRef.value = Object.fromEntries(entries);
|
|
124
|
-
setStorage(storageKey, storageV2, cache);
|
|
132
|
+
setStorage(storageKey, storageV2, toValue(cache));
|
|
125
133
|
}
|
|
126
134
|
});
|
|
127
135
|
const resetColumnsChecked = () => {
|
|
@@ -142,10 +150,18 @@ const useColumnsSorted = (columns, cache) => {
|
|
|
142
150
|
});
|
|
143
151
|
return Object.fromEntries(entries);
|
|
144
152
|
});
|
|
145
|
-
const storageV =
|
|
153
|
+
const storageV = computed(() => {
|
|
154
|
+
return getStorage(storageKey, toValue(cache));
|
|
155
|
+
});
|
|
146
156
|
const vRef = ref(
|
|
147
|
-
|
|
157
|
+
{}
|
|
148
158
|
);
|
|
159
|
+
watchEffect(() => {
|
|
160
|
+
vRef.value = {
|
|
161
|
+
...columnsV.value,
|
|
162
|
+
...storageV.value
|
|
163
|
+
};
|
|
164
|
+
});
|
|
149
165
|
const columnsSort = computed({
|
|
150
166
|
get() {
|
|
151
167
|
return vRef.value;
|
|
@@ -160,7 +176,7 @@ const useColumnsSorted = (columns, cache) => {
|
|
|
160
176
|
return [field, v[field]];
|
|
161
177
|
});
|
|
162
178
|
vRef.value = Object.fromEntries(entries);
|
|
163
|
-
setStorage(storageKey, storageV2, cache);
|
|
179
|
+
setStorage(storageKey, storageV2, toValue(cache));
|
|
164
180
|
}
|
|
165
181
|
});
|
|
166
182
|
const resetColumnsSort = () => {
|
|
@@ -200,11 +216,11 @@ const useForm = (props) => {
|
|
|
200
216
|
});
|
|
201
217
|
const { columnsChecked, resetColumnsChecked } = useColumnsChecked(
|
|
202
218
|
columns,
|
|
203
|
-
props.cache
|
|
219
|
+
() => props.cache
|
|
204
220
|
);
|
|
205
221
|
const { columnsSort, resetColumnsSort } = useColumnsSorted(
|
|
206
222
|
columns,
|
|
207
|
-
props.cache
|
|
223
|
+
() => props.cache
|
|
208
224
|
);
|
|
209
225
|
let tmpDefaultForm;
|
|
210
226
|
const watchMap = /* @__PURE__ */ new Map();
|
package/dist/type-helper.d.ts
CHANGED
|
@@ -29,4 +29,10 @@ export type Unrefs<T> = {
|
|
|
29
29
|
export type Refs<T> = {
|
|
30
30
|
[K in keyof T]: T[K] extends Ref<any> ? T[K] : MaybeRef<T[K]>;
|
|
31
31
|
};
|
|
32
|
+
/**
|
|
33
|
+
* 工具类型:提取 Column 的类型
|
|
34
|
+
*/
|
|
35
|
+
export type ExtractColumnType<T> = T extends {
|
|
36
|
+
type: infer U;
|
|
37
|
+
} ? U : never;
|
|
32
38
|
export {};
|