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"
|
|
|
|
>
|
|
|
|
<optgroup v-if="groupSelector" v-for="group in this.options" :label="group.label">
|
2022-01-12 21:39:42 +08:00
|
|
|
<option v-for="option in group.options"
|
|
|
|
:key="option.label"
|
|
|
|
: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>
|
|
|
|
</optgroup>
|
|
|
|
<option v-if="!groupSelector"
|
2021-11-16 21:46:08 +08:00
|
|
|
v-for="option in this.options"
|
2021-12-10 21:12:06 +08:00
|
|
|
:key="option.label"
|
|
|
|
:value="option.value"
|
2022-01-12 21:39:42 +08:00
|
|
|
: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))"
|
2021-12-15 22:16:12 +08:00
|
|
|
:data-params="JSON.stringify(option.params)">
|
2021-11-16 21:46:08 +08:00
|
|
|
{{ option.label }}
|
|
|
|
</option>
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
name: 'DropdownSelector',
|
|
|
|
props: {
|
|
|
|
options: Array,
|
|
|
|
selectorId: String,
|
2021-12-07 22:28:20 +08:00
|
|
|
groupSelector: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
2021-11-16 21:46:08 +08:00
|
|
|
noEmptyOption: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true
|
|
|
|
},
|
2021-12-07 22:28:20 +08:00
|
|
|
placeholder: {
|
|
|
|
type: String,
|
|
|
|
default: ''
|
|
|
|
},
|
2021-12-10 21:12:06 +08:00
|
|
|
selectedValue: {
|
2022-01-12 21:39:42 +08:00
|
|
|
type: [String, Number, Boolean, Array],
|
2021-12-10 21:12:06 +08:00
|
|
|
default: null
|
|
|
|
},
|
2021-11-16 21:46:08 +08:00
|
|
|
singleSelect: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true
|
|
|
|
},
|
|
|
|
closeOnSelect: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true
|
|
|
|
},
|
|
|
|
selectAppearance: {
|
|
|
|
type: String,
|
|
|
|
default: 'simple'
|
|
|
|
},
|
2021-12-01 18:24:34 +08:00
|
|
|
disableSearch: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
2021-12-07 22:28:20 +08:00
|
|
|
optionClass: {
|
|
|
|
type: String,
|
|
|
|
default: ''
|
|
|
|
},
|
|
|
|
dataCombineTags: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
dataSelectMultipleAllSelected: {
|
|
|
|
type: String,
|
|
|
|
default: ''
|
|
|
|
},
|
|
|
|
dataSelectMultipleName: {
|
|
|
|
type: String,
|
|
|
|
default: ''
|
|
|
|
},
|
2021-12-15 22:16:12 +08:00
|
|
|
optionLabel: {
|
|
|
|
type: Function
|
|
|
|
},
|
2021-11-16 21:46:08 +08:00
|
|
|
onChange: Function
|
|
|
|
|
|
|
|
},
|
|
|
|
mounted: function() {
|
|
|
|
dropdownSelector.init(`#${this.selectorId}`, {
|
2021-12-07 22:28:20 +08:00
|
|
|
optionClass: this.optionClass,
|
2021-12-15 22:16:12 +08:00
|
|
|
optionLabel: this.optionLabel,
|
2021-11-16 21:46:08 +08:00
|
|
|
noEmptyOption: this.noEmptyOption,
|
|
|
|
singleSelect: this.singleSelect,
|
|
|
|
closeOnSelect: this.closeOnSelect,
|
|
|
|
selectAppearance: this.selectAppearance,
|
2021-12-01 18:24:34 +08:00
|
|
|
disableSearch: this.disableSearch,
|
2021-11-16 21:46:08 +08:00
|
|
|
onChange: () => {
|
|
|
|
if (this.onChange) this.onChange();
|
|
|
|
this.selectChanged(dropdownSelector.getValues(`#${this.selectorId}`))
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
selectChanged(value) {
|
|
|
|
this.$emit(
|
|
|
|
'dropdown:changed',
|
|
|
|
value
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-01 18:24:34 +08:00
|
|
|
</script>
|