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>
|
|
|
|
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
|
|
|
|
},
|
2022-09-28 19:25:55 +08:00
|
|
|
labelHTML: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
tagLabel: {
|
|
|
|
type: Function
|
|
|
|
},
|
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
|
|
|
|
},
|
2022-09-28 17:32:14 +08:00
|
|
|
onOpen: {
|
|
|
|
type: Function
|
|
|
|
},
|
2022-06-06 19:56:22 +08:00
|
|
|
inputTagMode: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
viewMode: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
2021-11-16 21:46:08 +08:00
|
|
|
onChange: Function
|
|
|
|
|
|
|
|
},
|
|
|
|
mounted: function() {
|
|
|
|
dropdownSelector.init(`#${this.selectorId}`, {
|
2022-06-06 19:56:22 +08:00
|
|
|
inputTagMode: this.inputTagMode,
|
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,
|
2022-09-28 19:25:55 +08:00
|
|
|
tagLabel: this.tagLabel,
|
|
|
|
labelHTML: this.labelHTML,
|
2022-09-28 17:32:14 +08:00
|
|
|
onOpen: this.onOpen,
|
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
|
|
|
|
);
|
2022-09-29 20:47:59 +08:00
|
|
|
},
|
|
|
|
selectValues(value) {
|
|
|
|
dropdownSelector.selectValues(`#${this.selectorId}`, value);
|
2021-11-16 21:46:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-01 18:24:34 +08:00
|
|
|
</script>
|