@fishawack/lab-velocity 2.0.0-beta.35 → 2.0.0-beta.37
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.
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
:remote-method="endpoint ? handleSearch : undefined"
|
|
21
21
|
:loading="initialLoading"
|
|
22
22
|
:empty-values="[null, undefined]"
|
|
23
|
+
:value-key="effectiveValueKey"
|
|
23
24
|
@change="handleInput"
|
|
24
25
|
@clear="$emit('clear')"
|
|
25
26
|
@blur="$emit('blur')"
|
|
@@ -27,25 +28,14 @@
|
|
|
27
28
|
>
|
|
28
29
|
<template #default>
|
|
29
30
|
<slot name="default">
|
|
30
|
-
<
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
</template>
|
|
39
|
-
<template v-else>
|
|
40
|
-
<el-option
|
|
41
|
-
v-for="option in currentOptions"
|
|
42
|
-
:key="option.value"
|
|
43
|
-
:label="option.label"
|
|
44
|
-
:disabled="option.disabled"
|
|
45
|
-
:value="option"
|
|
46
|
-
>
|
|
47
|
-
</el-option>
|
|
48
|
-
</template>
|
|
31
|
+
<el-option
|
|
32
|
+
v-for="option in currentOptions"
|
|
33
|
+
:key="option[effectiveValueKey]"
|
|
34
|
+
:label="option[labelKey]"
|
|
35
|
+
:disabled="option.disabled"
|
|
36
|
+
:value="option"
|
|
37
|
+
>
|
|
38
|
+
</el-option>
|
|
49
39
|
</slot>
|
|
50
40
|
</template>
|
|
51
41
|
<template v-if="endpoint" #loading>
|
|
@@ -117,7 +107,7 @@ export default {
|
|
|
117
107
|
},
|
|
118
108
|
valueKey: {
|
|
119
109
|
type: String,
|
|
120
|
-
default:
|
|
110
|
+
default: null,
|
|
121
111
|
},
|
|
122
112
|
searchParam: {
|
|
123
113
|
type: String,
|
|
@@ -155,6 +145,14 @@ export default {
|
|
|
155
145
|
}
|
|
156
146
|
return this.options;
|
|
157
147
|
},
|
|
148
|
+
effectiveValueKey() {
|
|
149
|
+
// If valueKey was explicitly provided, use it
|
|
150
|
+
if (this.valueKey !== null) {
|
|
151
|
+
return this.valueKey;
|
|
152
|
+
}
|
|
153
|
+
// Otherwise, use "id" for endpoints, "value" for static options
|
|
154
|
+
return this.endpoint ? "id" : "value";
|
|
155
|
+
},
|
|
158
156
|
},
|
|
159
157
|
|
|
160
158
|
mounted() {
|
|
@@ -215,35 +213,28 @@ export default {
|
|
|
215
213
|
},
|
|
216
214
|
|
|
217
215
|
methods: {
|
|
218
|
-
castValue(value) {
|
|
219
|
-
if (
|
|
220
|
-
!_.isNull(value) &&
|
|
221
|
-
typeof value === "string" &&
|
|
222
|
-
value !== "" &&
|
|
223
|
-
!isNaN(Number(value))
|
|
224
|
-
) {
|
|
225
|
-
return parseInt(value);
|
|
226
|
-
}
|
|
227
|
-
return value;
|
|
228
|
-
},
|
|
229
|
-
|
|
230
216
|
async handleVisibleChange(visible) {
|
|
231
217
|
// Load data when dropdown is opened for the first time
|
|
232
218
|
if (visible && this.endpoint && !this.initialLoadDone) {
|
|
233
|
-
await this.
|
|
234
|
-
this.initialLoadDone = true;
|
|
219
|
+
await this.handleSearch("");
|
|
235
220
|
}
|
|
236
221
|
},
|
|
237
222
|
|
|
238
223
|
async handleSearch(query) {
|
|
239
224
|
if (!this.endpoint) return;
|
|
240
|
-
if (query === this.lastSearchQuery) return;
|
|
241
225
|
|
|
242
|
-
|
|
243
|
-
this.
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
226
|
+
// For initial load, allow empty query even if it matches lastSearchQuery
|
|
227
|
+
if (!this.initialLoadDone || query !== this.lastSearchQuery) {
|
|
228
|
+
this.searchQuery = query;
|
|
229
|
+
this.lastSearchQuery = query;
|
|
230
|
+
this.currentPage = 1;
|
|
231
|
+
this.asyncOptions = [];
|
|
232
|
+
await this.fetchOptions(1, query);
|
|
233
|
+
|
|
234
|
+
if (!this.initialLoadDone) {
|
|
235
|
+
this.initialLoadDone = true;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
247
238
|
},
|
|
248
239
|
|
|
249
240
|
handleEndReached(direction) {
|
|
@@ -280,18 +271,11 @@ export default {
|
|
|
280
271
|
const data = response.data.data || [];
|
|
281
272
|
const meta = response.data.meta;
|
|
282
273
|
|
|
283
|
-
// Transform API data to option format
|
|
284
|
-
const newOptions = data.map((item) => ({
|
|
285
|
-
label: item[this.labelKey],
|
|
286
|
-
value: item[this.valueKey],
|
|
287
|
-
disabled: item.disabled || false,
|
|
288
|
-
}));
|
|
289
|
-
|
|
290
274
|
// If it's the first page, replace options, otherwise append
|
|
291
275
|
if (page === 1) {
|
|
292
|
-
this.asyncOptions =
|
|
276
|
+
this.asyncOptions = data;
|
|
293
277
|
} else {
|
|
294
|
-
this.asyncOptions = [...this.asyncOptions, ...
|
|
278
|
+
this.asyncOptions = [...this.asyncOptions, ...data];
|
|
295
279
|
}
|
|
296
280
|
|
|
297
281
|
this.currentPage = page;
|
|
@@ -51,7 +51,7 @@ export default {
|
|
|
51
51
|
if (this.resource.form.submit) {
|
|
52
52
|
await this.resource.form.submit(this);
|
|
53
53
|
} else {
|
|
54
|
-
const hold = this.form.data();
|
|
54
|
+
const hold = JSON.parse(JSON.stringify(this.form.data()));
|
|
55
55
|
|
|
56
56
|
try {
|
|
57
57
|
this.form.populate(this.resource.form.preparation(this));
|
|
@@ -76,7 +76,7 @@ export default {
|
|
|
76
76
|
if (this.resource.form.submit) {
|
|
77
77
|
await this.resource.form.submit(this);
|
|
78
78
|
} else {
|
|
79
|
-
const hold = this.form.data();
|
|
79
|
+
const hold = JSON.parse(JSON.stringify(this.form.data()));
|
|
80
80
|
|
|
81
81
|
try {
|
|
82
82
|
this.form.populate(this.resource.form.preparation(this));
|