Browse Source

Merge pull request 'zq-slider-menu' (#47) from zq-slider-menu into master

Reviewed-on: #47
pull/51/head
zhangqi 2 weeks ago
parent
commit
66c1d6e9e2
  1. 96
      src/components/GuipSelect.vue

96
src/components/GuipSelect.vue

@ -1,12 +1,12 @@
<template> <template>
<el-form-item :style="{ ...style, height: height, ...styleObject }" <el-form-item :style="{ ...style, height: height, ...styleObject }"
:class="[{ 'column': column }, { 'w510': addClass == 'w510' }, { 'w388': addClass == 'w388' }, 'form-item']" :label="label" :class="[{ 'column': column }, { 'w510': addClass == 'w510' }, { 'w388': addClass == 'w388' }, 'form-item']"
:prop="prop" :rules="rules"> :label="label" :prop="prop" :rules="rules">
<p v-if="desc" class="desc_right">{{ desc }}</p> <p v-if="desc" class="desc_right">{{ desc }}</p>
<el-select :style="{ width: width }" :placeholder="placeholder1" @change="handleChange" v-model="selectedValue" v-bind="$attrs"> <el-select :style="{ width: width }" :placeholder="placeholder1" @change="handleChange" v-model="selectedValue"
<el-option v-for="item in options" :key="item.value" :label="item.label" :disabled="item.disabled" v-bind="$attrs">
:value="item.value"> <el-option v-for="item in processedOptions" :key="getItemValue(item)" :label="getItemLabel(item)"
:disabled="item.disabled" :value="getItemValue(item)">
</el-option> </el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
@ -14,9 +14,36 @@
<script> <script>
export default { export default {
name: 'GuipTextarea', name: 'GuipSelect',
props: ['value','options', 'styleObject', 'disabled', 'defaultValue', 'placeholder', props: {
'width', 'height', 'label', 'type', 'prop', 'rules', 'column', 'addClass', 'desc'], value: [String, Number, Array],
options: {
type: Array,
default: () => []
},
//
valueKey: {
type: String,
default: 'value'
},
labelKey: {
type: String,
default: 'label'
},
styleObject: Object,
disabled: Boolean,
defaultValue: [String, Number, Array],
placeholder: String,
width: String,
height: String,
label: String,
type: String,
prop: String,
rules: [Object, Array],
column: Boolean,
addClass: String,
desc: String
},
data() { data() {
return { return {
selectedValue: '', selectedValue: '',
@ -24,43 +51,48 @@ export default {
placeholder1: '请选择', placeholder1: '请选择',
} }
}, },
computed: {
// options
processedOptions() {
return this.options || []
}
},
watch: { watch: {
value(newVal) { value(newVal) {
this.selectedValue = newVal; this.selectedValue = newVal
}, },
// defaultValue(newVal) { defaultValue(newVal) {
// this.selectedValue = newVal; if (newVal !== undefined && newVal !== null) {
// } this.selectedValue = newVal
}
}
}, },
mounted() { mounted() {
// //
if (this.defaultValue != null) { if (this.defaultValue !== undefined && this.defaultValue !== null) {
this.selectedValue = this.defaultValue; this.selectedValue = this.defaultValue
} }
if (this.value != null) { if (this.value !== undefined && this.value !== null) {
this.selectedValue = this.value; this.selectedValue = this.value
} }
// //
if (this.placeholder) { if (this.placeholder) {
this.placeholder1 = this.placeholder; this.placeholder1 = this.placeholder
} }
this.$nextTick(() => {
// let els = document.querySelectorAll('.el-select .el-input');
// els.forEach(item => {
// item.onmouseover = function () {
// item.classList.add("hoverclass")
// }
// item.onmouseout = function () {
// item.classList.remove("hoverclass")
// }
// })
})
}, },
methods: { methods: {
handleChange(value) { // value
this.$emit('input', value); getItemValue(item) {
this.$emit('change', value); return item[this.valueKey]
}, },
// label
getItemLabel(item) {
return item[this.labelKey]
},
handleChange(value) {
this.$emit('input', value)
this.$emit('change', value)
}
} }
} }
</script> </script>
Loading…
Cancel
Save