Commit 36febc3c56fc83f6b5ed19ec461059c7a6521739
1 parent
64bd05f7
add Slider
add Slider
Showing
4 changed files
with
139 additions
and
22 deletions
Show diff stats
| 1 | +<template> | ||
| 2 | + <div :class="classes"> | ||
| 3 | + <Input-number v-if="!range && showInput" :min="min" :max="max" :step="step" :value.sync="value" :disabled="disabled"></Input-number> | ||
| 4 | + <div :class="[prefixCls + '-wrap']" @click="sliderClick"> | ||
| 5 | + <template v-if="showStops"> | ||
| 6 | + <div :class="[prefixCls + '-stop']" v-for="item in stops" :style="{ 'left': item + '%' }"></div> | ||
| 7 | + </template> | ||
| 8 | + <div :class="[prefixCls + '-bar']" :style="barStyle"></div> | ||
| 9 | + <div :class="[prefixCls + '-button-wrap']" v-if="!range"> | ||
| 10 | + <Tooltip placement="top" :content="tipFormat(value)"> | ||
| 11 | + <div :class="[prefixCls + '-button']"></div> | ||
| 12 | + </Tooltip> | ||
| 13 | + </div> | ||
| 14 | + | ||
| 15 | + </div> | ||
| 16 | + </div> | ||
| 17 | +</template> | ||
| 18 | +<script> | ||
| 19 | + import InputNumber from '../../components/input-number/input-number.vue'; | ||
| 20 | + import Tooltip from '../../components/tooltip/tooltip.vue'; | ||
| 21 | + | ||
| 22 | + const prefixCls = 'ivu-slider'; | ||
| 23 | + | ||
| 24 | + export default { | ||
| 25 | + components: { InputNumber, Tooltip }, | ||
| 26 | + props: { | ||
| 27 | + min: { | ||
| 28 | + type: Number, | ||
| 29 | + default: 0 | ||
| 30 | + }, | ||
| 31 | + max: { | ||
| 32 | + type: Number, | ||
| 33 | + default: 100 | ||
| 34 | + }, | ||
| 35 | + step: { | ||
| 36 | + type: Number, | ||
| 37 | + default: 1 | ||
| 38 | + }, | ||
| 39 | + range: { | ||
| 40 | + type: Boolean, | ||
| 41 | + default: false | ||
| 42 | + }, | ||
| 43 | + value: { | ||
| 44 | + type: [Number, Array], | ||
| 45 | + default: 0 | ||
| 46 | + }, | ||
| 47 | + disabled: { | ||
| 48 | + type: Boolean, | ||
| 49 | + default: false | ||
| 50 | + }, | ||
| 51 | + showInput: { | ||
| 52 | + type: Boolean, | ||
| 53 | + default: false | ||
| 54 | + }, | ||
| 55 | + showStops: { | ||
| 56 | + type: Boolean, | ||
| 57 | + default: false | ||
| 58 | + }, | ||
| 59 | + tipFormat: { | ||
| 60 | + type: Function, | ||
| 61 | + default (val) { | ||
| 62 | + return val; | ||
| 63 | + } | ||
| 64 | + } | ||
| 65 | + }, | ||
| 66 | + data () { | ||
| 67 | + return { | ||
| 68 | + prefixCls: prefixCls | ||
| 69 | + } | ||
| 70 | + }, | ||
| 71 | + computed: { | ||
| 72 | + classes () { | ||
| 73 | + return [ | ||
| 74 | + `${prefixCls}`, | ||
| 75 | + { | ||
| 76 | + [`${prefixCls}-input`]: this.showInput, | ||
| 77 | + [`${prefixCls}-range`]: this.range, | ||
| 78 | + [`${prefixCls}-disabled`]: this.disabled | ||
| 79 | + } | ||
| 80 | + ] | ||
| 81 | + }, | ||
| 82 | + barStyle () { | ||
| 83 | + let style; | ||
| 84 | + | ||
| 85 | + if (this.range) { | ||
| 86 | + style = { | ||
| 87 | + width: (this.value[1] - this.value[0]) / (this.max - this.min) * 100 + '%', | ||
| 88 | + left: (this.value[0] - this.min) / (this.max - this.min) * 100 + '%' | ||
| 89 | + } | ||
| 90 | + } else { | ||
| 91 | + style = { | ||
| 92 | + width: (this.value - this.min) / (this.max - this.min) * 100 + '%' | ||
| 93 | + } | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + return style; | ||
| 97 | + }, | ||
| 98 | + stops() { | ||
| 99 | + return this.max / this.step; | ||
| 100 | + } | ||
| 101 | + }, | ||
| 102 | + methods: { | ||
| 103 | + sliderClick () { | ||
| 104 | + | ||
| 105 | + } | ||
| 106 | + }, | ||
| 107 | + ready () { | ||
| 108 | + if (this.range) { | ||
| 109 | + const isArray = Array.isArray(this.value); | ||
| 110 | + if (!isArray || (isArray && this.value.length != 2) || (isArray && (!isNaN(this.value[0]) || !isNaN(this.value[1])))) { | ||
| 111 | + this.value = [0, 0]; | ||
| 112 | + } | ||
| 113 | + } | ||
| 114 | + } | ||
| 115 | + } | ||
| 116 | +</script> | ||
| 0 | \ No newline at end of file | 117 | \ No newline at end of file |
src/index.js
| @@ -27,6 +27,7 @@ import Modal from './components/modal'; | @@ -27,6 +27,7 @@ import Modal from './components/modal'; | ||
| 27 | import { Select, Option, OptionGroup } from './components/select'; | 27 | import { Select, Option, OptionGroup } from './components/select'; |
| 28 | import Tooltip from './components/tooltip'; | 28 | import Tooltip from './components/tooltip'; |
| 29 | import Poptip from './components/poptip'; | 29 | import Poptip from './components/poptip'; |
| 30 | +import Slider from './components/slider'; | ||
| 30 | 31 | ||
| 31 | const iview = { | 32 | const iview = { |
| 32 | Button, | 33 | Button, |
| @@ -67,7 +68,8 @@ const iview = { | @@ -67,7 +68,8 @@ const iview = { | ||
| 67 | iOption: Option, | 68 | iOption: Option, |
| 68 | iOptionGroup: OptionGroup, | 69 | iOptionGroup: OptionGroup, |
| 69 | Tooltip, | 70 | Tooltip, |
| 70 | - Poptip | 71 | + Poptip, |
| 72 | + Slider | ||
| 71 | }; | 73 | }; |
| 72 | 74 | ||
| 73 | module.exports = iview; | 75 | module.exports = iview; |
| 74 | \ No newline at end of file | 76 | \ No newline at end of file |
test/routers/tag.vue
| 1 | +<style> | ||
| 2 | + body{ | ||
| 3 | + padding: 50px; | ||
| 4 | + } | ||
| 5 | +</style> | ||
| 1 | <template> | 6 | <template> |
| 2 | - <Collapse active-key="1"> | ||
| 3 | - <Panel key="1"> | ||
| 4 | - 史蒂夫·乔布斯 | ||
| 5 | - <p slot="content">史蒂夫·乔布斯(Steve Jobs),1955年2月24日生于美国加利福尼亚州旧金山,美国发明家、企业家、美国苹果公司联合创办人。</p> | ||
| 6 | - </Panel> | ||
| 7 | - <Panel key="2"> | ||
| 8 | - 斯蒂夫·盖瑞·沃兹尼亚克 | ||
| 9 | - <p slot="content">斯蒂夫·盖瑞·沃兹尼亚克(Stephen Gary Wozniak),美国电脑工程师,曾与史蒂夫·乔布斯合伙创立苹果电脑(今之苹果公司)。斯蒂夫·盖瑞·沃兹尼亚克曾就读于美国科罗拉多大学,后转学入美国著名高等学府加州大学伯克利分校(UC Berkeley)并获得电机工程及计算机(EECS)本科学位(1987年)。</p> | ||
| 10 | - </Panel> | ||
| 11 | - <Panel key="3"> | ||
| 12 | - 乔纳森·伊夫 | ||
| 13 | - <p slot="content">乔纳森·伊夫是一位工业设计师,现任Apple公司设计师兼资深副总裁,英国爵士。他曾参与设计了iPod,iMac,iPhone,iPad等众多苹果产品。除了乔布斯,他是对苹果那些著名的产品最有影响力的人。</p> | ||
| 14 | - </Panel> | ||
| 15 | - </Collapse> | ||
| 16 | - <Input-number :max="10" :min="1" :value="1" @on-change="change"></Input-number> | ||
| 17 | - <Input-number :max="10" :min="1" :step="1.2" :value="1"></Input-number> | 7 | + <Slider :value="10" :tip-format="format"> |
| 8 | + | ||
| 9 | + </Slider> | ||
| 18 | </template> | 10 | </template> |
| 19 | <script> | 11 | <script> |
| 20 | - import { Collapse, InputNumber } from 'iview'; | ||
| 21 | - const Panel = Collapse.Panel; | 12 | + import { Slider } from 'iview'; |
| 22 | export default { | 13 | export default { |
| 23 | - components: { Collapse, Panel, InputNumber }, | 14 | + components: { Slider }, |
| 15 | + data () { | ||
| 16 | + return { | ||
| 17 | + | ||
| 18 | + } | ||
| 19 | + }, | ||
| 24 | methods: { | 20 | methods: { |
| 25 | - change (data) { | ||
| 26 | - console.log(data); | 21 | + format (val) { |
| 22 | + return `进度:${val}%` | ||
| 27 | } | 23 | } |
| 28 | } | 24 | } |
| 29 | } | 25 | } |