@hostlink/nuxt-light 1.27.3 → 1.27.4
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.
package/dist/module.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
declare namespace _default {
|
|
2
2
|
let name: string;
|
|
3
3
|
let props: any;
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
function setup(props: any): {
|
|
5
|
+
filteredOptions: import("vue").Ref<any, any>;
|
|
6
|
+
normalizedOptions: import("vue").ComputedRef<any[]>;
|
|
7
7
|
};
|
|
8
8
|
namespace methods {
|
|
9
9
|
function filterOptions(inputValue: any, update: any, abort: any): void;
|
|
@@ -1,36 +1,31 @@
|
|
|
1
|
-
import { h } from 'vue';
|
|
1
|
+
import { computed, h, ref } from 'vue';
|
|
2
2
|
import { QSelect } from 'quasar';
|
|
3
3
|
|
|
4
|
+
// 將 normalizeOptions 拆分為更小的函數
|
|
5
|
+
const normalizeOption = (option, i) => {
|
|
6
|
+
if (typeof option === 'string' || typeof option === 'number') {
|
|
7
|
+
return { label: String(option), value: String(option) };
|
|
8
|
+
}
|
|
9
|
+
if (typeof option === 'object') {
|
|
10
|
+
if ('group' in option) {
|
|
11
|
+
option.options = normalizeOptions(option.options || [], i);
|
|
12
|
+
return option;
|
|
13
|
+
} else if ('value' in option && typeof option.value !== 'string') {
|
|
14
|
+
Object.assign(option, { value: option.value });
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return option;
|
|
18
|
+
};
|
|
19
|
+
|
|
4
20
|
const normalizeOptions = (options, i = { count: 1 }) => {
|
|
5
21
|
if (Array.isArray(options)) {
|
|
6
|
-
return options.map(
|
|
7
|
-
if (typeof option === 'string' || typeof option === 'number') {
|
|
8
|
-
return {
|
|
9
|
-
label: String(option),
|
|
10
|
-
value: String(option),
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
if (typeof option == 'object') {
|
|
14
|
-
if ('group' in option) {
|
|
15
|
-
option.options = normalizeOptions(option.options || [], i)
|
|
16
|
-
return option
|
|
17
|
-
} else if ('value' in option && typeof option.value !== 'string') {
|
|
18
|
-
Object.assign(option, {
|
|
19
|
-
value: option.value,
|
|
20
|
-
})
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return option
|
|
24
|
-
}
|
|
25
|
-
)
|
|
22
|
+
return options.map(option => normalizeOption(option, i));
|
|
26
23
|
}
|
|
27
|
-
return Object.keys(options).map(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
})
|
|
33
|
-
}
|
|
24
|
+
return Object.keys(options).map(value => ({
|
|
25
|
+
label: options[value],
|
|
26
|
+
value,
|
|
27
|
+
}));
|
|
28
|
+
};
|
|
34
29
|
|
|
35
30
|
export default {
|
|
36
31
|
name: 'LSelect',
|
|
@@ -39,7 +34,7 @@ export default {
|
|
|
39
34
|
emitValue: { type: Boolean, default: true },
|
|
40
35
|
mapOptions: { type: Boolean, default: true },
|
|
41
36
|
hideBottomSpace: { type: Boolean, default: true },
|
|
42
|
-
required:
|
|
37
|
+
required: Boolean,
|
|
43
38
|
filled: { type: Boolean, default: undefined },
|
|
44
39
|
outlined: { type: Boolean, default: undefined },
|
|
45
40
|
standout: { type: Boolean, default: undefined },
|
|
@@ -50,13 +45,15 @@ export default {
|
|
|
50
45
|
optionLabel: { type: [String, Function], default: 'label' },
|
|
51
46
|
optionValue: { type: String, default: 'value' },
|
|
52
47
|
inputDebounce: { type: [Number, String], default: 0 },
|
|
53
|
-
|
|
54
48
|
},
|
|
55
|
-
|
|
56
|
-
|
|
49
|
+
setup(props) {
|
|
50
|
+
// 使用 computed 來緩存 normalizedOptions
|
|
51
|
+
const normalizedOptions = computed(() => normalizeOptions(props.options));
|
|
52
|
+
const filteredOptions = ref(props.options);
|
|
53
|
+
|
|
57
54
|
return {
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
filteredOptions,
|
|
56
|
+
normalizedOptions,
|
|
60
57
|
};
|
|
61
58
|
},
|
|
62
59
|
methods: {
|
|
@@ -67,22 +64,27 @@ export default {
|
|
|
67
64
|
}
|
|
68
65
|
|
|
69
66
|
update(() => {
|
|
70
|
-
this.filteredOptions = this.normalizedOptions.filter(option => {
|
|
71
|
-
|
|
72
|
-
|
|
67
|
+
this.filteredOptions.value = this.normalizedOptions.filter(option => {
|
|
68
|
+
const label =
|
|
69
|
+
typeof this.optionLabel === 'function'
|
|
70
|
+
? this.optionLabel(option)
|
|
71
|
+
: option[this.optionLabel];
|
|
73
72
|
return label && label.toLowerCase().includes(inputValue.toLowerCase());
|
|
74
73
|
});
|
|
75
74
|
});
|
|
76
75
|
},
|
|
77
76
|
},
|
|
78
77
|
render() {
|
|
79
|
-
return h(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
78
|
+
return h(
|
|
79
|
+
QSelect,
|
|
80
|
+
{
|
|
81
|
+
...this.$props,
|
|
82
|
+
...this.$light.getInputProps(this.$props), // 使用主題樣式的輸入屬性
|
|
83
|
+
'onUpdate:modelValue': this.$emit.bind(this, 'update:modelValue'),
|
|
84
|
+
onFilter: this.$props.useInput ? this.filterOptions : undefined, // 僅在 filterable 為 true 時使用 filterOptions
|
|
85
|
+
options: this.$props.useInput ? this.filteredOptions.value : this.$props.options,
|
|
86
|
+
},
|
|
87
|
+
this.$slots
|
|
88
|
+
);
|
|
87
89
|
},
|
|
88
90
|
};
|