2021-11-16 21:46:08 +08:00
|
|
|
<template>
|
|
|
|
<div class="dropdown-selector">
|
2021-12-07 22:28:20 +08:00
|
|
|
<select :id="this.selectorId"
|
|
|
|
:data-select-by-group="groupSelector"
|
|
|
|
:data-combine-tags="dataCombineTags"
|
|
|
|
:data-select-multiple-all-selected="dataSelectMultipleAllSelected"
|
|
|
|
:data-select-multiple-name="dataSelectMultipleName"
|
|
|
|
:data-placeholder="placeholder"
|
2022-06-06 19:56:22 +08:00
|
|
|
:data-view-mode="viewMode"
|
2021-12-07 22:28:20 +08:00
|
|
|
>
|
2022-02-28 20:21:17 +08:00
|
|
|
<template v-if="groupSelector">
|
|
|
|
<optgroup v-for="group in this.options" :label="group.label" :key="group.label">
|
|
|
|
<option v-for="option in group.options"
|
2022-09-30 03:11:00 +08:00
|
|
|
:key="option.value"
|
2022-02-28 20:21:17 +08:00
|
|
|
:value="option.value"
|
|
|
|
:selected="option.value == selectedValue || (Array.isArray(selectedValue) && selectedValue.some(e => e == option.value))"
|
|
|
|
:data-selected="option.value == selectedValue || (Array.isArray(selectedValue) && selectedValue.some(e => e == option.value))"
|
|
|
|
:data-params="JSON.stringify(option.params)"
|
|
|
|
:data-group="group.label">
|
|
|
|
{{ option.label }}
|
|
|
|
</option>
|
|
|
|
</optgroup>
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
<option
|
|
|
|
v-for="option in this.options"
|
2022-09-30 03:11:00 +08:00
|
|
|
:key="option.value"
|
2022-01-12 21:39:42 +08:00
|
|
|
:value="option.value"
|
|
|
|
:selected="option.value == selectedValue || (Array.isArray(selectedValue) && selectedValue.some(e => e == option.value))"
|
|
|
|
:data-selected="option.value == selectedValue || (Array.isArray(selectedValue) && selectedValue.some(e => e == option.value))"
|
|
|
|
:data-params="JSON.stringify(option.params)">
|
2021-12-07 22:28:20 +08:00
|
|
|
{{ option.label }}
|
|
|
|
</option>
|
2022-02-28 20:21:17 +08:00
|
|
|
</template>
|
2021-11-16 21:46:08 +08:00
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2024-01-04 23:34:36 +08:00
|
|
|
export default {
|
|
|
|
name: 'DropdownSelector',
|
|
|
|
props: {
|
|
|
|
options: Array,
|
|
|
|
selectorId: String,
|
|
|
|
groupSelector: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
noEmptyOption: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true
|
|
|
|
},
|
|
|
|
placeholder: {
|
|
|
|
type: String,
|
|
|
|
default: ''
|
|
|
|
},
|
|
|
|
selectedValue: {
|
|
|
|
type: [String, Number, Boolean, Array],
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
singleSelect: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true
|
|
|
|
},
|
|
|
|
closeOnSelect: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true
|
|
|
|
},
|
|
|
|
selectAppearance: {
|
|
|
|
type: String,
|
|
|
|
default: 'simple'
|
|
|
|
},
|
|
|
|
disableSearch: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
labelHTML: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
tagLabel: {
|
|
|
|
type: Function
|
2021-11-16 21:46:08 +08:00
|
|
|
},
|
2024-01-04 23:34:36 +08:00
|
|
|
optionClass: {
|
|
|
|
type: String,
|
|
|
|
default: ''
|
|
|
|
},
|
|
|
|
dataCombineTags: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
dataSelectMultipleAllSelected: {
|
|
|
|
type: String,
|
|
|
|
default: ''
|
|
|
|
},
|
|
|
|
dataSelectMultipleName: {
|
|
|
|
type: String,
|
|
|
|
default: ''
|
|
|
|
},
|
|
|
|
optionLabel: {
|
|
|
|
type: Function
|
|
|
|
},
|
|
|
|
onOpen: {
|
|
|
|
type: Function
|
|
|
|
},
|
|
|
|
inputTagMode: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
viewMode: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
onChange: Function
|
|
|
|
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
dropdownSelector.init(`#${this.selectorId}`, {
|
|
|
|
inputTagMode: this.inputTagMode,
|
|
|
|
optionClass: this.optionClass,
|
|
|
|
optionLabel: this.optionLabel,
|
|
|
|
noEmptyOption: this.noEmptyOption,
|
|
|
|
singleSelect: this.singleSelect,
|
|
|
|
closeOnSelect: this.closeOnSelect,
|
|
|
|
selectAppearance: this.selectAppearance,
|
|
|
|
disableSearch: this.disableSearch,
|
|
|
|
tagLabel: this.tagLabel,
|
|
|
|
labelHTML: this.labelHTML,
|
|
|
|
onOpen: this.onOpen,
|
|
|
|
onChange: () => {
|
|
|
|
if (this.onChange) this.onChange();
|
|
|
|
this.selectChanged(dropdownSelector.getValues(`#${this.selectorId}`));
|
2021-11-16 21:46:08 +08:00
|
|
|
}
|
2024-01-04 23:34:36 +08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
selectChanged(value) {
|
|
|
|
this.$emit(
|
|
|
|
'dropdown:changed',
|
|
|
|
value
|
|
|
|
);
|
|
|
|
},
|
|
|
|
selectValues(value) {
|
|
|
|
dropdownSelector.selectValues(`#${this.selectorId}`, value);
|
2021-11-16 21:46:08 +08:00
|
|
|
}
|
|
|
|
}
|
2024-01-04 23:34:36 +08:00
|
|
|
};
|
2021-12-01 18:24:34 +08:00
|
|
|
</script>
|