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

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
  });
@@ -70,25 +71,24 @@ const script = defineComponent({
70
71
  async function fetchData(node, keyword) {
71
72
  try {
72
73
  if (node && !node.__keyword && node.isLeaf) {
73
- valueRef.value = createOptionValue(node);
74
- return;
74
+ return updateValue(node);
75
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;
84
- }
85
- if (node == null ? void 0 : node.__keyword) {
76
+ if (!(node == null ? void 0 : node.__keyword)) {
77
+ const result = await asyncQueue.addAsync(createParams(props.wordbook, props.autograph, field.value, node, fieldKey.value));
78
+ if (!node) {
79
+ optionsRef.value = result.map((option) => enrichKeywordOption(option, keyword));
80
+ } else {
81
+ if (!result.length)
82
+ return updateValue(node);
83
+ node.children = result.map((option) => enrichChildOption(option, node, depth.value));
84
+ }
85
+ } else {
86
86
  if (!isString(node.id_link))
87
- return;
87
+ return Promise.reject();
88
88
  const linkList = parseLinkFromString2List(node.id_link);
89
89
  const primaryKeyOptions = await fetchPrimaryKeyValue(linkList);
90
90
  if (!primaryKeyOptions)
91
- return;
91
+ return Promise.reject();
92
92
  const {
93
93
  lastOption,
94
94
  options
@@ -96,20 +96,33 @@ const script = defineComponent({
96
96
  await fetchData(lastOption);
97
97
  if (isEmpty(lastOption.children)) {
98
98
  valueRef.value = sortOptionWithIdList(primaryKeyOptions, linkList);
99
+ showRef.value = false;
100
+ return Promise.reject();
99
101
  } else {
100
102
  optionsRef.value = options;
103
+ return lastOption;
101
104
  }
102
- } else {
103
- node.children = result.map((option) => {
104
- return {
105
- ...option,
106
- parent: node
107
- };
108
- });
109
105
  }
110
106
  } catch (e) {
111
107
  isString(e) && formRenderLog(e);
112
108
  }
109
+ function enrichChildOption(option, parent, depth2) {
110
+ return {
111
+ ...option,
112
+ parent,
113
+ isLeaf: getNodeDepth(parent) + 1 >= depth2
114
+ };
115
+ }
116
+ function enrichKeywordOption(option, keyword2) {
117
+ option.__keyword = !!keyword2;
118
+ option.isLeaf = !!keyword2;
119
+ return option;
120
+ }
121
+ function updateValue(node2) {
122
+ valueRef.value = createOptionValue(node2);
123
+ showRef.value = false;
124
+ return Promise.reject();
125
+ }
113
126
  function sortOptionWithIdList(options, idList) {
114
127
  return idList.map((id) => {
115
128
  return options.find((option) => option[valueKey.value] === id);
@@ -119,10 +132,16 @@ const script = defineComponent({
119
132
  let lastOption = options[0];
120
133
  const resultOption = idList.reduce((res, id, index) => {
121
134
  const option = getTargetOption(options, id);
122
- if (index === 0)
135
+ if (index === 0) {
136
+ lastOption = option;
123
137
  return [option];
138
+ }
139
+ Object.assign(option, {
140
+ parent: lastOption,
141
+ isLeaf: index + 1 >= depth.value
142
+ });
143
+ lastOption.children = [option];
124
144
  lastOption = option;
125
- res[0].children = [option];
126
145
  return res;
127
146
  }, []);
128
147
  return {
@@ -133,28 +152,43 @@ const script = defineComponent({
133
152
  return options2.find((o) => o[valueKey.value] === value);
134
153
  }
135
154
  }
155
+ function getNodeDepth(node2) {
156
+ let result = 1;
157
+ let parent = node2.parent;
158
+ while (parent) {
159
+ result++;
160
+ parent = parent.parent;
161
+ }
162
+ return result;
163
+ }
136
164
  function parseLinkFromString2List(linkString) {
137
165
  return linkString.split("_").filter((s) => s);
138
166
  }
139
167
  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
168
+ const paramsAdaptorMap = {
169
+ autograph: () => autograph,
170
+ wordbookId: "id",
171
+ wordbookType: "type",
172
+ fieldKeys: () => wordbook.search_key ? JSON.stringify(wordbook.search_key) : void 0,
173
+ conObj: () => JSON.stringify(createConfigObject(wordbook, keyword, node2)),
174
+ primaryKey: "primary_key",
175
+ levelKey: "level_key",
176
+ keyword: () => keyword,
177
+ page: () => 1
150
178
  };
179
+ const params = Object.entries(paramsAdaptorMap).reduce((res, [k, v]) => {
180
+ res[k] = isString(v) ? wordbook[v] : isFunction(v) ? v() : void 0;
181
+ return res;
182
+ }, {});
151
183
  return {
152
184
  ...getSearchRequestInfo(),
153
185
  params,
154
186
  key: key2
155
187
  };
156
188
  }
157
- function createConfigObject(wordbook, node2) {
189
+ function createConfigObject(wordbook, keyword2, node2) {
190
+ if (keyword2)
191
+ return wordbook.conObj || [];
158
192
  if (!node2)
159
193
  return wordbook.conObjFirstLevel || [];
160
194
  return [{
@@ -169,21 +203,21 @@ const script = defineComponent({
169
203
  if (!getSearchRequestInfo().primaryKeyUrl)
170
204
  return [];
171
205
  try {
172
- const params = createParams(props.wordbook, props.autograph, primaryKeys, fieldKey.value);
173
- return await asyncQueue.addAsync(params);
206
+ return await asyncQueue.addAsync(createParams(props.wordbook, props.autograph, primaryKeys, fieldKey.value));
174
207
  } catch (e) {
175
208
  isString(e) && formRenderLog(e);
176
209
  }
177
210
  function createParams(wordbook, autograph, primaryKeys2, key2) {
178
211
  const requestInfo = getSearchRequestInfo();
212
+ const params = {
213
+ autograph,
214
+ tableId: wordbook.id,
215
+ primaryKeyValue: primaryKeys2.join(","),
216
+ page: 1
217
+ };
179
218
  return {
180
219
  key: key2,
181
- params: {
182
- autograph,
183
- tableId: wordbook.id,
184
- primaryKeyValue: primaryKeys2.join(","),
185
- page: 1
186
- },
220
+ params,
187
221
  ...requestInfo,
188
222
  url: requestInfo.primaryKeyUrl
189
223
  };
@@ -193,8 +227,8 @@ const script = defineComponent({
193
227
  const result = [];
194
228
  let current = node;
195
229
  while (current) {
196
- result.unshift(node);
197
- current = node.parent;
230
+ result.unshift(omit(current, ["parent", "isLeaf", "__keyword", "children"]));
231
+ current = current.parent;
198
232
  }
199
233
  return result;
200
234
  }
@@ -219,6 +253,8 @@ const script = defineComponent({
219
253
  return () => createVNode(SearchCascader, {
220
254
  "value": valueRef.value,
221
255
  "onUpdate:value": ($event) => valueRef.value = $event,
256
+ "show": showRef.value,
257
+ "onUpdate:show": ($event) => showRef.value = $event,
222
258
  "options": optionsRef.value,
223
259
  "key": key.value,
224
260
  "labelKey": labelKey.value,