@ftjs/core 0.1.3 → 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
@@ -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
  ];
@@ -462,10 +478,11 @@ const defineFtForm = (setup, renderMap, _runtimeProps) => {
462
478
  return null;
463
479
  }
464
480
  const component = renderMap.get(column.type);
481
+ const isView = toValue(column.isView) ?? props.isView;
465
482
  return h(component, {
466
483
  column,
467
484
  // 是否为查看模式
468
- isView: column.isView,
485
+ isView,
469
486
  key: getField(column)
470
487
  });
471
488
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ftjs/core",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "keywords": [],
5
5
  "author": "",
6
6
  "license": "MIT",