cnhis-design-vue 3.1.23-beta.13 → 3.1.23-beta.14

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,5 @@
1
1
  import { defineComponent, computed, ref, inject, watch, createVNode } from 'vue';
2
- import { isEqual, isString, isEmpty } from 'lodash-es';
2
+ import { isEqual, isString, isEmpty, isFunction, omit } from 'lodash-es';
3
3
  import '../../../index2.js';
4
4
  import { InjectAsyncQueue } from '../../constants/index2.js';
5
5
  import { useCommonInjection } from '../../hooks/useCommonInjection2.js';
@@ -46,6 +46,7 @@ const script = defineComponent({
46
46
  get: () => props.value,
47
47
  set: (v) => emit("update:value", v)
48
48
  });
49
+ const showRef = ref(false);
49
50
  const optionsRef = ref([]);
50
51
  const {
51
52
  field,
@@ -59,7 +60,7 @@ const script = defineComponent({
59
60
  var _a, _b;
60
61
  return (_b = (_a = props.wordbook) == null ? void 0 : _a.value_key) != null ? _b : "value";
61
62
  });
62
- computed(() => {
63
+ const depth = computed(() => {
63
64
  var _a;
64
65
  return ((_a = props.wordbook) == null ? void 0 : _a.level_num) || Infinity;
65
66
  });
@@ -71,24 +72,16 @@ const script = defineComponent({
71
72
  try {
72
73
  if (node && !node.__keyword && node.isLeaf) {
73
74
  valueRef.value = createOptionValue(node);
74
- return;
75
- }
76
- const result = await asyncQueue.addAsync(createParams(props.wordbook, props.autograph, field.value, node, fieldKey.value));
77
- if (!node) {
78
- optionsRef.value = result.map((option) => {
79
- option.__keyword = !!keyword;
80
- option.isLeaf = !!keyword;
81
- return option;
82
- });
83
- return;
75
+ showRef.value = false;
76
+ return Promise.reject();
84
77
  }
85
78
  if (node == null ? void 0 : node.__keyword) {
86
79
  if (!isString(node.id_link))
87
- return;
80
+ return Promise.reject();
88
81
  const linkList = parseLinkFromString2List(node.id_link);
89
82
  const primaryKeyOptions = await fetchPrimaryKeyValue(linkList);
90
83
  if (!primaryKeyOptions)
91
- return;
84
+ return Promise.reject();
92
85
  const {
93
86
  lastOption,
94
87
  options
@@ -98,14 +91,25 @@ const script = defineComponent({
98
91
  valueRef.value = sortOptionWithIdList(primaryKeyOptions, linkList);
99
92
  } else {
100
93
  optionsRef.value = options;
94
+ return lastOption;
101
95
  }
102
96
  } else {
103
- node.children = result.map((option) => {
104
- return {
105
- ...option,
106
- parent: node
107
- };
108
- });
97
+ const result = await asyncQueue.addAsync(createParams(props.wordbook, props.autograph, field.value, node, fieldKey.value));
98
+ if (!node) {
99
+ optionsRef.value = result.map((option) => {
100
+ option.__keyword = !!keyword;
101
+ option.isLeaf = !!keyword;
102
+ return option;
103
+ });
104
+ } else {
105
+ node.children = result.map((option) => {
106
+ return {
107
+ ...option,
108
+ parent: node,
109
+ isLeaf: getNodeDepth(node) + 1 >= depth.value
110
+ };
111
+ });
112
+ }
109
113
  }
110
114
  } catch (e) {
111
115
  isString(e) && formRenderLog(e);
@@ -119,9 +123,15 @@ const script = defineComponent({
119
123
  let lastOption = options[0];
120
124
  const resultOption = idList.reduce((res, id, index) => {
121
125
  const option = getTargetOption(options, id);
122
- if (index === 0)
126
+ if (index === 0) {
127
+ lastOption = option;
123
128
  return [option];
129
+ }
124
130
  lastOption = option;
131
+ Object.assign(option, {
132
+ parent: res[0],
133
+ isLeaf: index + 1 >= depth.value
134
+ });
125
135
  res[0].children = [option];
126
136
  return res;
127
137
  }, []);
@@ -133,21 +143,34 @@ const script = defineComponent({
133
143
  return options2.find((o) => o[valueKey.value] === value);
134
144
  }
135
145
  }
146
+ function getNodeDepth(node2) {
147
+ let result = 1;
148
+ let parent = node2.parent;
149
+ while (parent) {
150
+ result++;
151
+ parent = parent.parent;
152
+ }
153
+ return result;
154
+ }
136
155
  function parseLinkFromString2List(linkString) {
137
156
  return linkString.split("_").filter((s) => s);
138
157
  }
139
158
  function createParams(wordbook, autograph, field2, node2, key2) {
140
- const params = {
141
- autograph,
142
- wordbookId: wordbook.id,
143
- wordbookType: wordbook.type,
144
- fieldKeys: wordbook.search_key ? JSON.stringify(wordbook.search_key) : void 0,
145
- conObj: JSON.stringify(createConfigObject(wordbook), node2),
146
- primaryKey: wordbook.primary_key,
147
- levelKey: wordbook.level_key,
148
- keyword,
149
- page: 1
159
+ const paramsAdaptorMap = {
160
+ autograph: () => autograph,
161
+ wordbookId: "id",
162
+ wordbookType: "type",
163
+ fieldKeys: () => wordbook.search_key ? JSON.stringify(wordbook.search_key) : void 0,
164
+ conObj: () => JSON.stringify(createConfigObject(wordbook, node2)),
165
+ primaryKey: "primary_key",
166
+ levelKey: "level_key",
167
+ keyword: () => keyword,
168
+ page: () => 1
150
169
  };
170
+ const params = Object.entries(paramsAdaptorMap).reduce((res, [k, v]) => {
171
+ res[k] = isString(v) ? wordbook[v] : isFunction(v) ? v() : void 0;
172
+ return res;
173
+ }, {});
151
174
  return {
152
175
  ...getSearchRequestInfo(),
153
176
  params,
@@ -169,21 +192,21 @@ const script = defineComponent({
169
192
  if (!getSearchRequestInfo().primaryKeyUrl)
170
193
  return [];
171
194
  try {
172
- const params = createParams(props.wordbook, props.autograph, primaryKeys, fieldKey.value);
173
- return await asyncQueue.addAsync(params);
195
+ return await asyncQueue.addAsync(createParams(props.wordbook, props.autograph, primaryKeys, fieldKey.value));
174
196
  } catch (e) {
175
197
  isString(e) && formRenderLog(e);
176
198
  }
177
199
  function createParams(wordbook, autograph, primaryKeys2, key2) {
178
200
  const requestInfo = getSearchRequestInfo();
201
+ const params = {
202
+ autograph,
203
+ tableId: wordbook.id,
204
+ primaryKeyValue: primaryKeys2.join(","),
205
+ page: 1
206
+ };
179
207
  return {
180
208
  key: key2,
181
- params: {
182
- autograph,
183
- tableId: wordbook.id,
184
- primaryKeyValue: primaryKeys2.join(","),
185
- page: 1
186
- },
209
+ params,
187
210
  ...requestInfo,
188
211
  url: requestInfo.primaryKeyUrl
189
212
  };
@@ -193,8 +216,8 @@ const script = defineComponent({
193
216
  const result = [];
194
217
  let current = node;
195
218
  while (current) {
196
- result.unshift(node);
197
- current = node.parent;
219
+ result.unshift(omit(current, ["parent", "isLeaf", "__keyword", "children"]));
220
+ current = current.parent;
198
221
  }
199
222
  return result;
200
223
  }
@@ -219,6 +242,8 @@ const script = defineComponent({
219
242
  return () => createVNode(SearchCascader, {
220
243
  "value": valueRef.value,
221
244
  "onUpdate:value": ($event) => valueRef.value = $event,
245
+ "show": showRef.value,
246
+ "onUpdate:show": ($event) => showRef.value = $event,
222
247
  "options": optionsRef.value,
223
248
  "key": key.value,
224
249
  "labelKey": labelKey.value,