@ftjs/core 0.1.2 → 0.2.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.
@@ -27,11 +27,11 @@ export interface FtFormColumnBase<FormData extends Record<string, any>> {
27
27
  *
28
28
  * 如: [startTime, endTime]
29
29
  *
30
- * 注意: 第一个字段需要尽量是基础类型的值(这个值会用于watch, expect等操作),后面可以包含详情
30
+ * 注意: 第一个字段需要尽量是基础类型的值(这个值会用于watch, expect等操作),中间字段则可以用'-'来忽略,后面字段可以直接忽略
31
31
  *
32
32
  * 如人员信息: [staffId, staffInfoObj, deptInfoObj, ...]
33
33
  */
34
- fields?: string[];
34
+ fields?: (RecordPath<FormData> | "-")[];
35
35
  /**
36
36
  * 字段标题
37
37
  *
@@ -25,6 +25,10 @@ export interface FtFormIntrinsicProps<FormData extends Record<string, any>, Type
25
25
  * 如果`formData`不为`undefined`或者`null`,则双向绑定这个值,否则 FtForm内部会生成一个内部值
26
26
  */
27
27
  formData?: FormData;
28
+ /**
29
+ * 是否查看模式
30
+ */
31
+ isView?: boolean;
28
32
  /**
29
33
  * 内部 form 组件 props
30
34
  */
@@ -17,6 +17,5 @@ interface UseFormItemOptions<FormData extends Record<string, any>, Type extends
17
17
  */
18
18
  export declare const useFormItem: <FromData extends Record<string, any>, Type extends keyof FormTypeMap<FromData>>(options: UseFormItemOptions<FtFormColumnBase<FormData>, Type>) => {
19
19
  valueComputed: import('vue').WritableComputedRef<any, any>;
20
- isView: import('vue').ComputedRef<boolean>;
21
20
  };
22
21
  export {};
package/dist/index.js CHANGED
@@ -90,7 +90,7 @@ const setStorage = (key, value, cache) => {
90
90
  localStorage.setItem(key, JSON.stringify(obj));
91
91
  }
92
92
  };
93
- const transferVueArrayPropsToObject = (arr) => {
93
+ function transferVueArrayPropsToObject(arr) {
94
94
  const props = {};
95
95
  arr.forEach((item) => {
96
96
  if (typeof item === "string") {
@@ -100,7 +100,7 @@ const transferVueArrayPropsToObject = (arr) => {
100
100
  }
101
101
  });
102
102
  return props;
103
- };
103
+ }
104
104
  const getPropsKeys = (arr) => {
105
105
  return arr.map((item) => {
106
106
  if (typeof item === "string") {
@@ -388,13 +388,26 @@ const useFormItem = (options) => {
388
388
  valueSetter = props.column.valueSetter;
389
389
  }
390
390
  const { form } = useFormInject();
391
+ const fieldsData = ref([]);
391
392
  const valueComputed = computed({
392
393
  get() {
393
394
  let val;
394
395
  if (props.column.fields) {
395
- val = props.column.fields.map((field) => {
396
- return get(form.value, field);
397
- }).filter((e) => !isEmptyStrOrNull(e));
396
+ const length = Math.max(
397
+ props.column.fields.length,
398
+ fieldsData.value.length
399
+ );
400
+ const valArr = Array(length).fill(void 0);
401
+ for (let i = 0; i < length; i++) {
402
+ const field = props.column.fields[i];
403
+ if (field && field !== "-") {
404
+ valArr[i] = get(form.value, field);
405
+ }
406
+ if (fieldsData.value[i]) {
407
+ valArr[i] = fieldsData.value[i];
408
+ }
409
+ }
410
+ val = valArr;
398
411
  } else if (props.column.field) {
399
412
  val = get(form.value, props.column.field);
400
413
  } else {
@@ -406,8 +419,14 @@ const useFormItem = (options) => {
406
419
  set(val) {
407
420
  if (valueSetter) val = valueSetter(val);
408
421
  if (props.column.fields) {
422
+ const valArr = val ?? [];
423
+ fieldsData.value = valArr;
409
424
  props.column.fields.forEach((field, index) => {
410
- set(form.value, field, val == null ? void 0 : val[index]);
425
+ const v = valArr[index];
426
+ if (field === "-") {
427
+ return;
428
+ }
429
+ set(form.value, field, v);
411
430
  });
412
431
  } else if (props.column.field) {
413
432
  set(form.value, props.column.field, val);
@@ -416,12 +435,8 @@ const useFormItem = (options) => {
416
435
  }
417
436
  }
418
437
  });
419
- const isView = computed(() => {
420
- return toValue(props.column.isView) ?? props.isView;
421
- });
422
438
  return {
423
- valueComputed,
424
- isView
439
+ valueComputed
425
440
  };
426
441
  };
427
442
  const defineFtForm = (setup, renderMap, _runtimeProps) => {
@@ -435,6 +450,7 @@ const defineFtForm = (setup, renderMap, _runtimeProps) => {
435
450
  "formData",
436
451
  "internalFormProps",
437
452
  "onSubmit",
453
+ "isView",
438
454
  "onUpdate:formData",
439
455
  ..._runtimeProps
440
456
  ];
@@ -455,7 +471,6 @@ const defineFtForm = (setup, renderMap, _runtimeProps) => {
455
471
  return () => h(FormComponent, null, {
456
472
  ...ctx.slots,
457
473
  formContent: () => visibleColumns.value.map((column) => {
458
- var _a;
459
474
  if (!renderMap.has(column.type)) {
460
475
  console.warn(
461
476
  `[@ftjs/core]: 没有配置 column.type ${column.type}, 请检查该组件是否注册`
@@ -463,11 +478,12 @@ const defineFtForm = (setup, renderMap, _runtimeProps) => {
463
478
  return null;
464
479
  }
465
480
  const component = renderMap.get(column.type);
481
+ const isView = toValue(column.isView) ?? props.isView;
466
482
  return h(component, {
467
483
  column,
468
484
  // 是否为查看模式
469
- isView: column.isView,
470
- key: column.field ?? ((_a = column.fields) == null ? void 0 : _a[0])
485
+ isView,
486
+ key: getField(column)
471
487
  });
472
488
  })
473
489
  });
@@ -7,7 +7,10 @@ export interface TableTypeMap<TableData extends Record<string, any>, SearchData
7
7
  tableSlots: {};
8
8
  tableColumn: FtTableColumn<TableData>;
9
9
  formColumn: FtFormColumnBase<SearchData>;
10
- extendedProps: {};
10
+ extendedProps: {
11
+ testProps: string;
12
+ onTestEvent: () => void;
13
+ };
11
14
  internalFormProps: {};
12
15
  internalTableProps: {};
13
16
  };
@@ -1,10 +1,9 @@
1
1
  import { ComputedRef } from 'vue';
2
2
  import { TableTypeMap, FtTableIntrinsicProps } from './define-components';
3
3
  import { SplitEventKeys } from '../type-helper';
4
- type TableInject<TableData extends Record<string, any>, FormData extends Record<string, any> = TableData, Type extends keyof TableTypeMap<TableData, FormData> = "default"> = SplitEventKeys<FtTableIntrinsicProps<TableData, FormData, Type> & TableTypeMap<TableData, FormData>[Type]["extendedProps"]> & {
4
+ export type TableInject<TableData extends Record<string, any>, FormData extends Record<string, any> = TableData, Type extends keyof TableTypeMap<TableData, FormData> = "default"> = SplitEventKeys<FtTableIntrinsicProps<TableData, FormData, Type> & TableTypeMap<TableData, FormData>[Type]["extendedProps"]> & {
5
5
  formColumns: ComputedRef<TableTypeMap<TableData, FormData>[Type]["formColumn"][]>;
6
6
  tableColumns: ComputedRef<TableTypeMap<TableData, FormData>[Type]["tableColumn"][]>;
7
7
  };
8
8
  export declare const useTable: <TableData extends Record<string, any>, FormData extends Record<string, any>, Type extends keyof TableTypeMap<TableData, FormData>>(props: FtTableIntrinsicProps<TableData, FormData, Type>, runtimePropsKeys: string[]) => void;
9
9
  export declare const useTableInject: <TableData extends Record<string, any>, FormData extends Record<string, any> = TableData, Type extends keyof TableTypeMap<TableData, FormData> = "default">() => TableInject<TableData, FormData, Type> | undefined;
10
- export {};
@@ -1,4 +1,4 @@
1
- import { ComputedRef, MaybeRef } from 'vue';
1
+ import { ComputedRef, MaybeRef, Ref } from 'vue';
2
2
  /**
3
3
  * 临时工具类型减1
4
4
  */
@@ -27,7 +27,7 @@ export type Unrefs<T> = {
27
27
  * 工具类型:将对象的属性值转换为 {@link MaybeRef}
28
28
  */
29
29
  export type Refs<T> = {
30
- [K in keyof T]: MaybeRef<T[K]>;
30
+ [K in keyof T]: T[K] extends Ref<any> ? T[K] : MaybeRef<T[K]>;
31
31
  };
32
32
  /**
33
33
  * 工具类型:将对象的属性转换为元组
@@ -47,12 +47,6 @@ type UnionToTuple<T> = ((T extends any ? (t: T) => T : never) extends infer U ?
47
47
  export type WithLengthKeys<T> = (keyof T)[] & {
48
48
  length: TupleKeys<T>["length"];
49
49
  };
50
- /**
51
- * 工具类型:将对象中所有属性值转为 {@link ComputedRef}
52
- */
53
- export type ComputedRefKeys<T> = {
54
- [K in keyof T]-?: T[K] extends ComputedRef<any> ? T[K] : ComputedRef<T[K]>;
55
- };
56
50
  /**
57
51
  * 工具类型:将对象中所有属性值分流,分为事件和非事件
58
52
  *
@@ -0,0 +1 @@
1
+ export {};
package/dist/utils.d.ts CHANGED
@@ -4,6 +4,9 @@ import { FtFormColumnBase } from './form/columns';
4
4
  export declare const isBrowser: boolean;
5
5
  export declare const getField: <T extends Record<string, any>>(column: FtFormColumnBase<T>) => RecordPath<T>;
6
6
  export declare const isEmptyStrOrNull: (val: any) => boolean;
7
+ /**
8
+ * 深拷贝(简化版)
9
+ */
7
10
  export declare const cloneDeep: <T>(obj: T) => T;
8
11
  export declare const get: (obj: any, path: string) => any;
9
12
  export declare const set: (obj: any, path: string, value: any) => void;
@@ -36,5 +39,5 @@ export type RuntimeProps<T extends readonly any[] = []> = T[number] | [
36
39
  validator?(value: unknown, props: any): boolean;
37
40
  }
38
41
  ];
39
- export declare const transferVueArrayPropsToObject: (arr: RuntimeProps[]) => any;
42
+ export declare function transferVueArrayPropsToObject<T extends readonly any[] = []>(arr: RuntimeProps<T>[]): any;
40
43
  export declare const getPropsKeys: (arr: RuntimeProps<any>[]) => any[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ftjs/core",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "keywords": [],
5
5
  "author": "",
6
6
  "license": "MIT",
@@ -37,7 +37,7 @@
37
37
  "scripts": {
38
38
  "build": "vite build",
39
39
  "minify": "pnpm dlx esbuild ./dist/index.js --minify --outfile=./dist/index.min.js",
40
- "test": "vitest",
40
+ "test": "vitest --typecheck",
41
41
  "test:coverage": "vitest run --coverage",
42
42
  "pub": "tsx ../../scripts/publish.ts"
43
43
  }