Merge branch 'master' of gitlab.qima-inc.com:fe/zanui-vue

This commit is contained in:
pangxie1991 2017-03-27 18:40:19 +08:00
commit e4075e91df
8 changed files with 127 additions and 44 deletions

View File

@ -12,6 +12,16 @@
} }
</style> </style>
<script>
export default {
methods: {
handlePageEnd(page, index) {
console.log(page, index);
}
}
};
</script>
## Swipe 轮播 ## Swipe 轮播
### 基础用法 ### 基础用法
@ -33,7 +43,7 @@
:::demo 自动轮播 :::demo 自动轮播
```html ```html
<zan-swipe :auto-play="true"> <zan-swipe :auto-play="true" @pagechange:end="handlePageEnd">
<zan-swipe-item> <zan-swipe-item>
<img src="https://img.yzcdn.cn/upload_files/2017/03/14/FmTPs0SeyQaAOSK1rRe1sL8RcwSY.jpeg?imageView2/2/w/980/h/980/q/75/format/webp" alt=""> <img src="https://img.yzcdn.cn/upload_files/2017/03/14/FmTPs0SeyQaAOSK1rRe1sL8RcwSY.jpeg?imageView2/2/w/980/h/980/q/75/format/webp" alt="">
</zan-swipe-item> </zan-swipe-item>
@ -43,3 +53,16 @@
</zan-swipe> </zan-swipe>
``` ```
::: :::
### API
| 参数 | 说明 | 类型 | 默认值 | 可选值 |
|-----------|-----------|-----------|-------------|-------------|
| autoPlay | 是否自动轮播 | `boolean` | `false` | `true`, `false` |
| showIndicators | 是否显示指示器 | `boolean` | `true` | `true`, `false` |
### 事件
| 事件名 | 说明 | 参数 |
|-----------|-----------|-----------|
| `pagechange:end` | 每一页轮播结束后触发 | `(elem, currIndex)``elem`为触发页当前的DOM节点 |

View File

@ -1,6 +1,6 @@
{ {
"name": "@youzan/zanui-vue", "name": "@youzan/zanui-vue",
"version": "0.0.43", "version": "0.0.44",
"description": "有赞vue wap组件库", "description": "有赞vue wap组件库",
"main": "lib/zanui.js", "main": "lib/zanui.js",
"style": "lib/zanui-css/index.css", "style": "lib/zanui-css/index.css",

View File

@ -44,8 +44,14 @@ export default {
}, },
data() { data() {
let value = this.value ? +this.value : +this.defaultValue;
const correctedValue = this.correctValue(value);
if (value !== correctedValue) {
value = correctedValue;
this.$emit('input', value);
}
return { return {
currentValue: this.value ? +this.value : +this.defaultValue currentValue: value
}; };
}, },
@ -66,38 +72,37 @@ export default {
watch: { watch: {
currentValue(val) { currentValue(val) {
this.$emit('input', +val); this.$emit('input', val);
this.$emit('change', val);
}, },
value(val) { value(val) {
if (val) { if (val) {
this.currentValue = +val; this.currentValue = this.correctValue(+val);
} }
} }
}, },
methods: { methods: {
// value
correctValue(value) {
value = Math.max(this.min, value);
value = Math.min(this.max, value);
return value;
},
handleInputChange(event) { handleInputChange(event) {
let val = +event.target.value; const val = +event.target.value;
const max = +this.max;
const min = +this.min;
if (val > max) { this.currentValue = this.correctValue(val);
val = max;
} else if (val < min) {
val = min;
}
this.currentValue = val;
}, },
handleChange(type) { handleChange(type) {
if ((this.isMinusDisabled && type === 'minus') || (this.isPlusDisabled && type === 'plus')) { if ((this.isMinusDisabled && type === 'minus') || (this.isPlusDisabled && type === 'plus')) {
this.$emit('overlimit', type);
return; return;
} }
const step = +this.step; const step = +this.step;
const currentValue = +this.currentValue; const currentValue = +this.currentValue;
this.currentValue = type === 'minus' ? (currentValue - step) : (currentValue + step); this.currentValue = type === 'minus' ? (currentValue - step) : (currentValue + step);
this.$emit('change', this.currentValue);
} }
} }
}; };

View File

@ -6,6 +6,10 @@
<script> <script>
export default { export default {
name: 'zan-swipe-item' name: 'zan-swipe-item',
beforeCreate() {
this.$parent.swipes.push(this);
}
}; };
</script> </script>

View File

@ -1,7 +1,15 @@
<template> <template>
<div class="zan-swipe"> <div class="zan-swipe">
<div class="zan-swipe__items">
<slot></slot> <slot></slot>
</div> </div>
<div class="zan-swipe__indicators" v-if="showIndicators">
<span class="zan-swipe__indicator" v-for="i in swipes.length" :class="{
'zan-swipe__indicator--active': currIndex === i -1
}">
</span>
</div>
</div>
</template> </template>
<script> <script>
@ -13,16 +21,20 @@ export default {
name: 'zan-swipe', name: 'zan-swipe',
props: { props: {
autoPlay: { autoPlay: Boolean,
showIndicators: {
type: Boolean, type: Boolean,
default: false default: true
},
onPageChangeEnd: {
type: Function,
default: () => {}
} }
}, },
data() {
return {
currIndex: 0,
swipes: []
};
},
mounted() { mounted() {
this.input = new Input(this.$el, { this.input = new Input(this.$el, {
listenMoving: true listenMoving: true
@ -53,6 +65,13 @@ export default {
updated() { updated() {
this.scroll.update(); this.scroll.update();
},
methods: {
onPageChangeEnd(page, currIndex) {
this.currIndex = +currIndex;
this.$emit('pagechange:end', page, currIndex);
}
} }
}; };
</script> </script>

View File

@ -1,6 +1,6 @@
{ {
"name": "@youzan/zanui-css", "name": "@youzan/zanui-css",
"version": "0.0.43", "version": "0.0.44",
"description": "zanui css.", "description": "zanui css.",
"main": "lib/index.css", "main": "lib/index.css",
"style": "lib/index.css", "style": "lib/index.css",

View File

@ -1,15 +1,47 @@
@import './common/var.css';
@component-namespace zan { @component-namespace zan {
@b swipe { @b swipe {
position: relative; position: relative;
overflow: hidden; overflow: hidden;
width: 100%; width: 100%;
height: 100%;
@e indicators {
position: absolute;
bottom: 10px;
left: 50%;
transform: translateX(-50%);
}
@e indicator {
width: 5px;
height: 5px;
display: inline-block;
border-radius: 100%;
background: #999;
opacity: .8;
margin: 0 3px;
z-index: 1;
@m active {
background: $c-orange;
opacity: 1;
}
}
@e items {
position: relative;
overflow: hidden;
position: relative;
height: 100%;
}
} }
@b swipe-item { @b swipe-item {
display: none; display: none;
width: 100%;
height: 100%; height: 100%;
overflow: hidden; width: 100%;
text-align: center; text-align: center;
img { img {

View File

@ -80,7 +80,7 @@ if (typeof window !== 'undefined' && window.Vue) {
module.exports = { module.exports = {
install, install,
version: '0.0.43', version: '0.0.44',
Button, Button,
Switch, Switch,
Field, Field,