@ftjs/core 0.5.0 → 0.5.2
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/index.js +15 -8
- package/dist/utils.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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;
|
|
5
|
-
return
|
|
5
|
+
return ((_a = column.fields) == null ? void 0 : _a[0]) ?? column.field;
|
|
6
6
|
};
|
|
7
7
|
const isEmptyStrOrNull = (val) => {
|
|
8
8
|
return val === "" || val == null;
|
|
@@ -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
|