@ticatec/uniface-flexi-module 0.2.4 → 0.2.6

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.
@@ -1,5 +1,6 @@
1
1
  <script lang="ts">import CascadeOptionSelect from "@ticatec/uniface-element/CascadeOptionsSelect";
2
2
  import FlexiField from "../flexi_field/FlexiField";
3
+ import utils from "../../utils";
3
4
  export let field;
4
5
  export let readonly;
5
6
  export let disabled;
@@ -7,7 +8,8 @@ export let variant;
7
8
  $: props = field.props;
8
9
  $: data = field.data;
9
10
  $: events = field.events;
11
+ $: text = field.dataFields['textField'] ? utils.extractFieldValue(field.rawData, field.dataFields['textField']) ?? '' : '';
10
12
  </script>
11
13
 
12
- <CascadeOptionSelect bind:value={data[field.keyField]} variant={variant??field.variant} readonly={readonly || field.isReadonly}
14
+ <CascadeOptionSelect bind:value={data[field.keyField]} variant={variant??field.variant} readonly={readonly || field.isReadonly} {text}
13
15
  disabled={disabled || field.disabled} {...props} {...events}/>
@@ -106,7 +106,7 @@ const buildUnitNumberField = (schema, dictLoader) => {
106
106
  const buildCascadeOptionSelect = (schema, dictLoader) => {
107
107
  const props = schema.props;
108
108
  if (schema.dictName) {
109
- props.options = dictLoader(schema.dictName);
109
+ props.nodes = [dictLoader(schema.dictName)];
110
110
  }
111
111
  return {
112
112
  component: CascadeOptionSelectField,
@@ -22,6 +22,8 @@ export interface FlexiFieldSchema {
22
22
  type: string;
23
23
  /** 字段的名称 */
24
24
  keyField: string;
25
+ /** 其他的数据字段 */
26
+ dataFields: Record<string, string>;
25
27
  /** 字段的名称 */
26
28
  name: string;
27
29
  /** 关联的数据字典项目 */
@@ -38,6 +40,8 @@ export interface FlexiFieldSchema {
38
40
  required?: boolean;
39
41
  /** 事件 */
40
42
  events?: Record<string, string>;
43
+ /** 函数,部分属性可以是一个动态函数 */
44
+ methods?: Record<string, string>;
41
45
  /** 在卡片/Block中所在单元格的属性,flex布局和grid布局对应的属性也不一样*/
42
46
  cell?: any;
43
47
  /** 字段的属性 */
@@ -47,8 +51,10 @@ export interface FlexiFieldSchema {
47
51
  }
48
52
  export default class FlexiField {
49
53
  #private;
54
+ readonly rawData: any;
50
55
  readonly data: any;
51
56
  readonly keyField: string;
57
+ readonly dataFields: Record<string, string>;
52
58
  readonly component: typeof SvelteComponent;
53
59
  readonly variant?: "" | "outlined" | "filled";
54
60
  visibility: Visibility;
@@ -6,8 +6,10 @@ import i18nRes from "../../i18n-res";
6
6
  import { i18nUtils } from "@ticatec/i18n";
7
7
  export default class FlexiField {
8
8
  #parent;
9
+ rawData;
9
10
  data;
10
11
  keyField;
12
+ dataFields;
11
13
  component;
12
14
  variant;
13
15
  visibility = Visibility.View;
@@ -29,6 +31,7 @@ export default class FlexiField {
29
31
  this.isReadonly = schema.readonly == true;
30
32
  this.disabled = schema.disabled == true;
31
33
  this.required = schema.required == true;
34
+ this.dataFields = schema.dataFields;
32
35
  this.#cell = schema.cell;
33
36
  const card = parent instanceof FlexiCard ? parent : parent.card;
34
37
  if (schema.events) {
@@ -46,6 +49,13 @@ export default class FlexiField {
46
49
  this.#props[key] = utils.getScopeVariable(cellField.props[key]);
47
50
  }
48
51
  }
52
+ if (schema.methods) {
53
+ for (let key in schema.methods) {
54
+ let classMethod = schema.methods[key];
55
+ this.#props[key] = (...args) => card[classMethod]?.(...args);
56
+ }
57
+ }
58
+ this.rawData = data;
49
59
  const result = utils.getParentAndKey(data, schema.keyField);
50
60
  this.keyField = result?.key;
51
61
  this.data = result?.parent;
package/dist/utils.d.ts CHANGED
@@ -8,5 +8,6 @@ declare const _default: {
8
8
  formatText: (s: string, obj: any) => string;
9
9
  propsFilter: (attrs: any, excludes?: Array<string>) => any;
10
10
  getScopeVariable: (key: string) => any;
11
+ extractFieldValue: (data: any, keyPath: string) => any;
11
12
  };
12
13
  export default _default;
package/dist/utils.js CHANGED
@@ -62,10 +62,19 @@ const getParentAndKey = (data, keyPath) => {
62
62
  return { parent: data, key: keyPath };
63
63
  }
64
64
  };
65
+ /**
66
+ * 萃取字段值
67
+ * @param data
68
+ * @param keyPath
69
+ */
70
+ const extractFieldValue = (data, keyPath) => {
71
+ let nestObj = getParentAndKey(data, keyPath);
72
+ return nestObj.parent[nestObj.key];
73
+ };
65
74
  const formatText = (s, obj) => {
66
75
  return s.replace(/\{\{(.*?)\}\}/g, (_, key) => {
67
76
  key = key.trim();
68
77
  return obj.hasOwnProperty(key) ? String(obj[key]) : `{{${key}}}`;
69
78
  });
70
79
  };
71
- export default { copyAttrs, extractExpression, getParentAndKey, formatText, propsFilter, getScopeVariable };
80
+ export default { copyAttrs, extractExpression, getParentAndKey, formatText, propsFilter, getScopeVariable, extractFieldValue };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ticatec/uniface-flexi-module",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "A flexible form framework for Svelte applications with dynamic field types, criteria panels, and modular components",
5
5
  "keywords": [
6
6
  "svelte",