add Slider

add Slider
This commit is contained in:
梁灏 2016-10-28 17:35:28 +08:00
parent 64bd05f7ff
commit 36febc3c56
4 changed files with 139 additions and 22 deletions

View file

@ -0,0 +1,3 @@
import Slider from './slider.vue';
export default Slider;

View file

@ -0,0 +1,116 @@
<template>
<div :class="classes">
<Input-number v-if="!range && showInput" :min="min" :max="max" :step="step" :value.sync="value" :disabled="disabled"></Input-number>
<div :class="[prefixCls + '-wrap']" @click="sliderClick">
<template v-if="showStops">
<div :class="[prefixCls + '-stop']" v-for="item in stops" :style="{ 'left': item + '%' }"></div>
</template>
<div :class="[prefixCls + '-bar']" :style="barStyle"></div>
<div :class="[prefixCls + '-button-wrap']" v-if="!range">
<Tooltip placement="top" :content="tipFormat(value)">
<div :class="[prefixCls + '-button']"></div>
</Tooltip>
</div>
</div>
</div>
</template>
<script>
import InputNumber from '../../components/input-number/input-number.vue';
import Tooltip from '../../components/tooltip/tooltip.vue';
const prefixCls = 'ivu-slider';
export default {
components: { InputNumber, Tooltip },
props: {
min: {
type: Number,
default: 0
},
max: {
type: Number,
default: 100
},
step: {
type: Number,
default: 1
},
range: {
type: Boolean,
default: false
},
value: {
type: [Number, Array],
default: 0
},
disabled: {
type: Boolean,
default: false
},
showInput: {
type: Boolean,
default: false
},
showStops: {
type: Boolean,
default: false
},
tipFormat: {
type: Function,
default (val) {
return val;
}
}
},
data () {
return {
prefixCls: prefixCls
}
},
computed: {
classes () {
return [
`${prefixCls}`,
{
[`${prefixCls}-input`]: this.showInput,
[`${prefixCls}-range`]: this.range,
[`${prefixCls}-disabled`]: this.disabled
}
]
},
barStyle () {
let style;
if (this.range) {
style = {
width: (this.value[1] - this.value[0]) / (this.max - this.min) * 100 + '%',
left: (this.value[0] - this.min) / (this.max - this.min) * 100 + '%'
}
} else {
style = {
width: (this.value - this.min) / (this.max - this.min) * 100 + '%'
}
}
return style;
},
stops() {
return this.max / this.step;
}
},
methods: {
sliderClick () {
}
},
ready () {
if (this.range) {
const isArray = Array.isArray(this.value);
if (!isArray || (isArray && this.value.length != 2) || (isArray && (!isNaN(this.value[0]) || !isNaN(this.value[1])))) {
this.value = [0, 0];
}
}
}
}
</script>

View file

@ -27,6 +27,7 @@ import Modal from './components/modal';
import { Select, Option, OptionGroup } from './components/select'; import { Select, Option, OptionGroup } from './components/select';
import Tooltip from './components/tooltip'; import Tooltip from './components/tooltip';
import Poptip from './components/poptip'; import Poptip from './components/poptip';
import Slider from './components/slider';
const iview = { const iview = {
Button, Button,
@ -67,7 +68,8 @@ const iview = {
iOption: Option, iOption: Option,
iOptionGroup: OptionGroup, iOptionGroup: OptionGroup,
Tooltip, Tooltip,
Poptip Poptip,
Slider
}; };
module.exports = iview; module.exports = iview;

View file

@ -1,29 +1,25 @@
<style>
body{
padding: 50px;
}
</style>
<template> <template>
<Collapse active-key="1"> <Slider :value="10" :tip-format="format">
<Panel key="1">
史蒂夫·乔布斯 </Slider>
<p slot="content">史蒂夫·乔布斯Steve Jobs1955年2月24日生于美国加利福尼亚州旧金山美国发明家企业家美国苹果公司联合创办人</p>
</Panel>
<Panel key="2">
斯蒂夫·盖瑞·沃兹尼亚克
<p slot="content">斯蒂夫·盖瑞·沃兹尼亚克Stephen Gary Wozniak美国电脑工程师曾与史蒂夫·乔布斯合伙创立苹果电脑今之苹果公司斯蒂夫·盖瑞·沃兹尼亚克曾就读于美国科罗拉多大学后转学入美国著名高等学府加州大学伯克利分校UC Berkeley并获得电机工程及计算机EECS本科学位1987</p>
</Panel>
<Panel key="3">
乔纳森·伊夫
<p slot="content">乔纳森·伊夫是一位工业设计师现任Apple公司设计师兼资深副总裁英国爵士他曾参与设计了iPodiMaciPhoneiPad等众多苹果产品除了乔布斯他是对苹果那些著名的产品最有影响力的人</p>
</Panel>
</Collapse>
<Input-number :max="10" :min="1" :value="1" @on-change="change"></Input-number>
<Input-number :max="10" :min="1" :step="1.2" :value="1"></Input-number>
</template> </template>
<script> <script>
import { Collapse, InputNumber } from 'iview'; import { Slider } from 'iview';
const Panel = Collapse.Panel;
export default { export default {
components: { Collapse, Panel, InputNumber }, components: { Slider },
data () {
return {
}
},
methods: { methods: {
change (data) { format (val) {
console.log(data); return `进度:${val}%`
} }
} }
} }