-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
222 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<template> | ||
<el-dropdown @command="handleCommand" trigger="click" class="number-range"> | ||
<el-button class="el-dropdown-link" :class="{empty: isEmpty}"> | ||
{{field.label}} {{selectValue}}<i class="el-icon-arrow-down el-icon--right"></i> | ||
</el-button> | ||
<el-dropdown-menu slot="dropdown"> | ||
<el-dropdown-item v-for="o in options" :command="o" v-key="o.text">{{o.text}}</el-dropdown-item> | ||
<el-dropdown-item :command="undefined">无</el-dropdown-item> | ||
<el-dropdown-item> | ||
<div @click.stop="noCommand"> | ||
<el-input-number v-model="range[0]" controls-position="right" clearable | ||
@change="onInputChange"></el-input-number> | ||
- | ||
<el-input-number v-model="range[1]" controls-position="right" clearable | ||
@change="onInputChange"></el-input-number> | ||
</div> | ||
</el-dropdown-item> | ||
</el-dropdown-menu> | ||
</el-dropdown> | ||
</template> | ||
<script> | ||
import {get} from 'lodash' | ||
// let DEFAULT_OPTIONS = [ | ||
// {text: '0-99', range: [0, 99]}, | ||
// {text: '100-199', range: [100, 199]}, | ||
// {text: '200-299', range: [200, 299]}, | ||
// {text: '300-', range: [300, 99999]} | ||
// | ||
// ] | ||
export default{ | ||
props: { | ||
value: String, | ||
field: Object, | ||
separator: {type: String, default: '至'} | ||
}, | ||
data () { | ||
return { | ||
selectValue: '', | ||
range: [undefined, undefined] | ||
} | ||
}, | ||
components: {}, | ||
methods: { | ||
handleCommand (c) { | ||
if (!c) { | ||
this.range = [undefined, undefined] | ||
this.selectValue = null | ||
} else { | ||
this.range = c.range | ||
this.selectValue = c.text || this.genRangeText(c.range) | ||
} | ||
}, | ||
noCommand() { | ||
}, | ||
genRangeText(range) { | ||
if (!range[0] && !range[1]) { | ||
return null | ||
} | ||
else if (!range[0] && range[1]) { | ||
return `${range[1]}及以下` | ||
} else if (!range[1] && range[0]) { | ||
return `${range[0]}及以上` | ||
} else { | ||
return `${range[0]}-${range[1]}` | ||
} | ||
}, | ||
onInputChange () { | ||
this.selectValue = this.genRangeText(this.range) | ||
} | ||
}, | ||
computed: { | ||
isEmpty () { | ||
return !this.range[0] && !this.range[1] | ||
}, | ||
options () { | ||
return get(this.field, 'search.options') || [] // || DEFAULT_OPTIONS | ||
} | ||
}, | ||
watch: { | ||
selectValue(v){ | ||
if (this.isEmpty) { | ||
this.$emit('input', undefined) | ||
} else { | ||
let min = this.range[0] || 0 | ||
let max = this.range[1] || 999999 | ||
this.$emit('input', `${min},${max}`) | ||
} | ||
} | ||
} | ||
} | ||
</script> | ||
<style> | ||
.number-range .empty { | ||
color: lightgray; | ||
} | ||
.el-input.range_begin, .el-input.range_end { | ||
width: 6rem; | ||
text-align: right; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<template> | ||
<el-select class="number-range model-select" :placeholder="field.placeholder || `请选择${field.label}`" v-model="selectValue"> | ||
<el-option v-for="a in options" :key="a.key" :label="a.label" :value="a.value"></el-option> | ||
<div> | ||
<el-input v-model="range[0]" :placeholder="`${field.label}最小`" class="range_begin" type="number" clearable @change="onChange"></el-input> | ||
- | ||
<el-input v-model="range[1]" :placeholder="`${field.label}最大`" class="range_end" type="number" clearable @change="onChange"></el-input> | ||
</div> | ||
<template #empty> | ||
<div> | ||
<el-input v-model="range[0]" :placeholder="`${field.label}最小`" class="range_begin" type="number" clearable @change="onChange"></el-input> | ||
- | ||
<el-input v-model="range[1]" :placeholder="`${field.label}最大`" class="range_end" type="number" clearable @change="onChange"></el-input> | ||
</div> | ||
</template> | ||
</el-select> | ||
</template> | ||
<script> | ||
export default{ | ||
props: { | ||
value: String, | ||
field: Object, | ||
separator: {type: String, default: '至'} | ||
}, | ||
data () { | ||
return { | ||
options: [], | ||
defaultSeparator: '-', | ||
selectValue: '', | ||
range: [undefined, undefined] | ||
} | ||
}, | ||
components: {}, | ||
mounted () { | ||
this.setRange() | ||
}, | ||
methods: { | ||
setRange () { | ||
if(!this.value) { | ||
this.range = [undefined, undefined] | ||
} else { | ||
let ps = this.value.split(this.separator).map(a => { | ||
return parseInt(a) || undefined | ||
}) | ||
if(ps.length<2) { | ||
ps.append(undefined) | ||
} | ||
this.range = ps | ||
} | ||
}, | ||
onChange () { | ||
let r = this.range | ||
let s = r.join(this.separator) || undefined | ||
this.selectValue = s | ||
let label= (r[0] || r[1]) ? s.replace(this.separator, this.defaultSeparator) : '' | ||
let opt = {key: 'self', label, value: s} | ||
this.options = this.options.filter(a => a.key!== opt.key).concat([opt]) | ||
this.$emit(s) | ||
} | ||
}, | ||
computed: {}, | ||
watch: { | ||
range () { | ||
this.onChange() | ||
} | ||
} | ||
} | ||
</script> | ||
<style> | ||
.el-input.range_begin, .el-input.range_end { | ||
width: 10rem; | ||
text-align: right; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters