mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
[build] 0.5.10
This commit is contained in:
parent
bbb070f084
commit
c9b52c0aab
52
dist/collapse-item/index.js
vendored
52
dist/collapse-item/index.js
vendored
@ -1,4 +1,5 @@
|
|||||||
import { VantComponent } from '../common/component';
|
import { VantComponent } from '../common/component';
|
||||||
|
const nextTick = () => new Promise(resolve => setTimeout(resolve, 20));
|
||||||
VantComponent({
|
VantComponent({
|
||||||
classes: ['title-class', 'content-class'],
|
classes: ['title-class', 'content-class'],
|
||||||
relation: {
|
relation: {
|
||||||
@ -26,48 +27,49 @@ VantComponent({
|
|||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
contentHeight: 0,
|
contentHeight: 0,
|
||||||
expanded: false
|
expanded: false,
|
||||||
|
transition: false
|
||||||
},
|
},
|
||||||
beforeCreate() {
|
mounted() {
|
||||||
this.animation = wx.createAnimation({
|
this.updateExpanded()
|
||||||
duration: 300,
|
.then(nextTick)
|
||||||
timingFunction: 'ease-in-out'
|
.then(() => {
|
||||||
|
this.set({ transition: true });
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
updateExpanded() {
|
updateExpanded() {
|
||||||
if (!this.parent) {
|
if (!this.parent) {
|
||||||
return null;
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
const { value, accordion, items } = this.parent.data;
|
const { value, accordion } = this.parent.data;
|
||||||
|
const { children = [] } = this.parent;
|
||||||
const { name } = this.data;
|
const { name } = this.data;
|
||||||
const index = items.indexOf(this);
|
const index = children.indexOf(this);
|
||||||
const currentName = name == null ? index : name;
|
const currentName = name == null ? index : name;
|
||||||
const expanded = accordion
|
const expanded = accordion
|
||||||
? value === currentName
|
? value === currentName
|
||||||
: value.some(name => name === currentName);
|
: (value || []).some((name) => name === currentName);
|
||||||
|
const stack = [];
|
||||||
if (expanded !== this.data.expanded) {
|
if (expanded !== this.data.expanded) {
|
||||||
this.updateStyle(expanded);
|
stack.push(this.updateStyle(expanded));
|
||||||
}
|
}
|
||||||
this.set({ index, expanded });
|
stack.push(this.set({ index, expanded }));
|
||||||
|
return Promise.all(stack);
|
||||||
},
|
},
|
||||||
updateStyle(expanded) {
|
updateStyle(expanded) {
|
||||||
this.getRect('.van-collapse-item__content').then(res => {
|
return this.getRect('.van-collapse-item__content')
|
||||||
const animationData = this.animation
|
.then((rect) => rect.height)
|
||||||
.height(expanded ? res.height : 0)
|
.then((height) => {
|
||||||
.step()
|
|
||||||
.export();
|
|
||||||
if (expanded) {
|
if (expanded) {
|
||||||
this.set({ animationData });
|
return this.set({
|
||||||
|
contentHeight: height ? `${height}px` : 'auto'
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.set({
|
return this.set({ contentHeight: `${height}px` })
|
||||||
contentHeight: res.height + 'px'
|
.then(nextTick)
|
||||||
}, () => {
|
.then(() => this.set({ contentHeight: 0 }));
|
||||||
setTimeout(() => {
|
|
||||||
this.set({ animationData });
|
|
||||||
}, 20);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -76,7 +78,7 @@ VantComponent({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const { name, expanded } = this.data;
|
const { name, expanded } = this.data;
|
||||||
const index = this.parent.data.items.indexOf(this);
|
const index = this.parent.children.indexOf(this);
|
||||||
const currentName = name == null ? index : name;
|
const currentName = name == null ? index : name;
|
||||||
this.parent.switch(currentName, !expanded);
|
this.parent.switch(currentName, !expanded);
|
||||||
},
|
},
|
||||||
|
3
dist/collapse-item/index.wxml
vendored
3
dist/collapse-item/index.wxml
vendored
@ -30,9 +30,8 @@
|
|||||||
/>
|
/>
|
||||||
</van-cell>
|
</van-cell>
|
||||||
<view
|
<view
|
||||||
class="van-collapse-item__wrapper"
|
class="{{ utils.bem('collapse-item__wrapper', { transition }) }}"
|
||||||
style="height: {{ contentHeight }};"
|
style="height: {{ contentHeight }};"
|
||||||
animation="{{ animationData }}"
|
|
||||||
bind:transitionend="onTransitionEnd"
|
bind:transitionend="onTransitionEnd"
|
||||||
>
|
>
|
||||||
<view
|
<view
|
||||||
|
2
dist/collapse-item/index.wxss
vendored
2
dist/collapse-item/index.wxss
vendored
@ -1 +1 @@
|
|||||||
@import '../common/index.wxss';.van-collapse-item__title .van-cell__right-icon{-webkit-transform:rotate(90deg);transform:rotate(90deg);transition:.3s}.van-collapse-item__title--expanded .van-cell__right-icon{-webkit-transform:rotate(-90deg);transform:rotate(-90deg)}.van-collapse-item__title--disabled .van-cell,.van-collapse-item__title--disabled .van-cell__right-icon{color:#c9c9c9!important}.van-collapse-item__title--disabled .van-cell--hover{background-color:#fff!important}.van-collapse-item__wrapper{overflow:hidden}.van-collapse-item__content{padding:15px;font-size:13px;line-height:1.5;color:#999;background-color:#fff}
|
@import '../common/index.wxss';.van-collapse-item__title .van-cell__right-icon{-webkit-transform:rotate(90deg);transform:rotate(90deg);transition:.3s}.van-collapse-item__title--expanded .van-cell__right-icon{-webkit-transform:rotate(-90deg);transform:rotate(-90deg)}.van-collapse-item__title--disabled .van-cell,.van-collapse-item__title--disabled .van-cell__right-icon{color:#c9c9c9!important}.van-collapse-item__title--disabled .van-cell--hover{background-color:#fff!important}.van-collapse-item__wrapper{overflow:hidden}.van-collapse-item__wrapper--transition{transition:height .3s ease-in-out}.van-collapse-item__content{padding:15px;font-size:13px;line-height:1.5;color:#999;background-color:#fff}
|
37
dist/collapse/index.js
vendored
37
dist/collapse/index.js
vendored
@ -4,43 +4,38 @@ VantComponent({
|
|||||||
name: 'collapse-item',
|
name: 'collapse-item',
|
||||||
type: 'descendant',
|
type: 'descendant',
|
||||||
linked(child) {
|
linked(child) {
|
||||||
this.set({
|
this.children.push(child);
|
||||||
items: [...this.data.items, child]
|
|
||||||
}, () => {
|
|
||||||
child.updateExpanded();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
value: null,
|
value: {
|
||||||
accordion: Boolean,
|
type: null,
|
||||||
|
observer: 'updateExpanded'
|
||||||
|
},
|
||||||
|
accordion: {
|
||||||
|
type: Boolean,
|
||||||
|
observer: 'updateExpanded'
|
||||||
|
},
|
||||||
border: {
|
border: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
value: true
|
value: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data: {
|
beforeCreate() {
|
||||||
items: []
|
this.children = [];
|
||||||
},
|
},
|
||||||
watch: {
|
methods: {
|
||||||
value() {
|
updateExpanded() {
|
||||||
this.data.items.forEach(child => {
|
this.children.forEach((child) => {
|
||||||
child.updateExpanded();
|
child.updateExpanded();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
accordion() {
|
|
||||||
this.data.items.forEach(child => {
|
|
||||||
child.updateExpanded();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
switch(name, expanded) {
|
switch(name, expanded) {
|
||||||
const { accordion, value } = this.data;
|
const { accordion, value } = this.data;
|
||||||
if (!accordion) {
|
if (!accordion) {
|
||||||
name = expanded
|
name = expanded
|
||||||
? value.concat(name)
|
? (value || []).concat(name)
|
||||||
: value.filter(activeName => activeName !== name);
|
: (value || []).filter((activeName) => activeName !== name);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
name = expanded ? name : '';
|
name = expanded ? name : '';
|
||||||
|
12
dist/mixins/touch.js
vendored
12
dist/mixins/touch.js
vendored
@ -1,13 +1,14 @@
|
|||||||
export const touch = Behavior({
|
export const touch = Behavior({
|
||||||
methods: {
|
methods: {
|
||||||
touchStart(event) {
|
touchStart(event) {
|
||||||
|
const touch = event.touches[0];
|
||||||
this.direction = '';
|
this.direction = '';
|
||||||
this.deltaX = 0;
|
this.deltaX = 0;
|
||||||
this.deltaY = 0;
|
this.deltaY = 0;
|
||||||
this.offsetX = 0;
|
this.offsetX = 0;
|
||||||
this.offsetY = 0;
|
this.offsetY = 0;
|
||||||
this.startX = event.touches[0].clientX;
|
this.startX = touch.clientX;
|
||||||
this.startY = event.touches[0].clientY;
|
this.startY = touch.clientY;
|
||||||
},
|
},
|
||||||
touchMove(event) {
|
touchMove(event) {
|
||||||
const touch = event.touches[0];
|
const touch = event.touches[0];
|
||||||
@ -15,7 +16,12 @@ export const touch = Behavior({
|
|||||||
this.deltaY = touch.clientY - this.startY;
|
this.deltaY = touch.clientY - this.startY;
|
||||||
this.offsetX = Math.abs(this.deltaX);
|
this.offsetX = Math.abs(this.deltaX);
|
||||||
this.offsetY = Math.abs(this.deltaY);
|
this.offsetY = Math.abs(this.deltaY);
|
||||||
this.direction = this.offsetX > this.offsetY ? 'horizontal' : this.offsetX < this.offsetY ? 'vertical' : '';
|
this.direction =
|
||||||
|
this.offsetX > this.offsetY
|
||||||
|
? 'horizontal'
|
||||||
|
: this.offsetX < this.offsetY
|
||||||
|
? 'vertical'
|
||||||
|
: '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
92
dist/swipe-cell/index.js
vendored
92
dist/swipe-cell/index.js
vendored
@ -1,6 +1,6 @@
|
|||||||
import { VantComponent } from '../common/component';
|
import { VantComponent } from '../common/component';
|
||||||
import { touch } from '../mixins/touch';
|
import { touch } from '../mixins/touch';
|
||||||
const THRESHOLD = 0.15;
|
const THRESHOLD = 0.3;
|
||||||
VantComponent({
|
VantComponent({
|
||||||
props: {
|
props: {
|
||||||
disabled: Boolean,
|
disabled: Boolean,
|
||||||
@ -16,97 +16,89 @@ VantComponent({
|
|||||||
},
|
},
|
||||||
mixins: [touch],
|
mixins: [touch],
|
||||||
data: {
|
data: {
|
||||||
offset: 0,
|
catchMove: true
|
||||||
draging: false
|
|
||||||
},
|
},
|
||||||
computed: {
|
created() {
|
||||||
wrapperStyle() {
|
this.offset = 0;
|
||||||
const { offset, draging } = this.data;
|
|
||||||
const transform = `translate3d(${offset}px, 0, 0)`;
|
|
||||||
const transition = draging ? 'none' : '.6s cubic-bezier(0.18, 0.89, 0.32, 1)';
|
|
||||||
return `
|
|
||||||
-webkit-transform: ${transform};
|
|
||||||
-webkit-transition: ${transition};
|
|
||||||
transform: ${transform};
|
|
||||||
transition: ${transition};
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onTransitionend() {
|
|
||||||
this.swipe = false;
|
|
||||||
},
|
|
||||||
open(position) {
|
open(position) {
|
||||||
const { leftWidth, rightWidth } = this.data;
|
const { leftWidth, rightWidth } = this.data;
|
||||||
const offset = position === 'left' ? leftWidth : -rightWidth;
|
const offset = position === 'left' ? leftWidth : -rightWidth;
|
||||||
this.swipeMove(offset);
|
this.swipeMove(offset);
|
||||||
this.resetSwipeStatus();
|
|
||||||
},
|
},
|
||||||
close() {
|
close() {
|
||||||
this.set({ offset: 0 });
|
this.swipeMove(0);
|
||||||
},
|
|
||||||
resetSwipeStatus() {
|
|
||||||
this.swiping = false;
|
|
||||||
this.opened = true;
|
|
||||||
},
|
},
|
||||||
swipeMove(offset = 0) {
|
swipeMove(offset = 0) {
|
||||||
this.set({ offset });
|
this.offset = offset;
|
||||||
offset && (this.swiping = true);
|
const transform = `translate3d(${offset}px, 0, 0)`;
|
||||||
!offset && (this.opened = false);
|
const transition = this.draging
|
||||||
|
? 'none'
|
||||||
|
: '.6s cubic-bezier(0.18, 0.89, 0.32, 1)';
|
||||||
|
this.set({
|
||||||
|
wrapperStyle: `
|
||||||
|
-webkit-transform: ${transform};
|
||||||
|
-webkit-transition: ${transition};
|
||||||
|
transform: ${transform};
|
||||||
|
transition: ${transition};
|
||||||
|
`
|
||||||
|
});
|
||||||
},
|
},
|
||||||
swipeLeaveTransition(direction) {
|
swipeLeaveTransition() {
|
||||||
const { offset, leftWidth, rightWidth } = this.data;
|
const { leftWidth, rightWidth } = this.data;
|
||||||
const threshold = this.opened ? 1 - THRESHOLD : THRESHOLD;
|
const { offset } = this;
|
||||||
// right
|
if (rightWidth > 0 && -offset > rightWidth * THRESHOLD) {
|
||||||
if (direction > 0 && -offset > rightWidth * threshold && rightWidth > 0) {
|
|
||||||
this.open('right');
|
this.open('right');
|
||||||
// left
|
|
||||||
}
|
}
|
||||||
else if (direction < 0 && offset > leftWidth * threshold && leftWidth > 0) {
|
else if (leftWidth > 0 && offset > leftWidth * THRESHOLD) {
|
||||||
this.open('left');
|
this.open('left');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.swipeMove();
|
this.swipeMove(0);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
startDrag(event) {
|
startDrag(event) {
|
||||||
if (this.data.disabled) {
|
if (this.data.disabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.set({ draging: true });
|
this.draging = true;
|
||||||
|
this.startOffset = this.offset;
|
||||||
|
this.firstDirection = '';
|
||||||
this.touchStart(event);
|
this.touchStart(event);
|
||||||
if (this.opened) {
|
|
||||||
this.startX -= this.data.offset;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
noop() { },
|
||||||
onDrag(event) {
|
onDrag(event) {
|
||||||
if (this.data.disabled) {
|
if (this.data.disabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.touchMove(event);
|
this.touchMove(event);
|
||||||
const { deltaX } = this;
|
if (!this.firstDirection) {
|
||||||
const { leftWidth, rightWidth } = this.data;
|
this.firstDirection = this.direction;
|
||||||
if ((deltaX < 0 && (-deltaX > rightWidth || !rightWidth)) ||
|
this.set({ catchMove: this.firstDirection === 'horizontal' });
|
||||||
(deltaX > 0 && (deltaX > leftWidth || (deltaX > 0 && !leftWidth)))) {
|
}
|
||||||
|
if (this.firstDirection === 'vertical') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.direction === 'horizontal') {
|
const { leftWidth, rightWidth } = this.data;
|
||||||
this.swipeMove(deltaX);
|
const offset = this.startOffset + this.deltaX;
|
||||||
|
if ((rightWidth > 0 && -offset > rightWidth) ||
|
||||||
|
(leftWidth > 0 && offset > leftWidth)) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
this.swipeMove(offset);
|
||||||
},
|
},
|
||||||
endDrag() {
|
endDrag() {
|
||||||
if (this.data.disabled) {
|
if (this.data.disabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.set({ draging: false });
|
this.draging = false;
|
||||||
if (this.swiping) {
|
this.swipeLeaveTransition();
|
||||||
this.swipeLeaveTransition(this.data.offset > 0 ? -1 : 1);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
onClick(event) {
|
onClick(event) {
|
||||||
const { key: position = 'outside' } = event.currentTarget.dataset;
|
const { key: position = 'outside' } = event.currentTarget.dataset;
|
||||||
this.$emit('click', position);
|
this.$emit('click', position);
|
||||||
if (!this.data.offset) {
|
if (!this.offset) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.data.asyncClose) {
|
if (this.data.asyncClose) {
|
||||||
|
8
dist/swipe-cell/index.wxml
vendored
8
dist/swipe-cell/index.wxml
vendored
@ -3,14 +3,12 @@
|
|||||||
data-key="cell"
|
data-key="cell"
|
||||||
catchtap="onClick"
|
catchtap="onClick"
|
||||||
bindtouchstart="startDrag"
|
bindtouchstart="startDrag"
|
||||||
catchtouchmove="onDrag"
|
catchtouchmove="{{ catchMove ? 'noop' : '' }}"
|
||||||
|
capture-bind:touchmove="onDrag"
|
||||||
catchtouchend="endDrag"
|
catchtouchend="endDrag"
|
||||||
catchtouchcancel="endDrag"
|
catchtouchcancel="endDrag"
|
||||||
>
|
>
|
||||||
<view
|
<view style="{{ wrapperStyle }}">
|
||||||
style="{{ wrapperStyle }}"
|
|
||||||
bindtransitionend="onTransitionend"
|
|
||||||
>
|
|
||||||
<view wx:if="{{ leftWidth }}" class="van-swipe-cell__left" data-key="left" catch:tap="onClick">
|
<view wx:if="{{ leftWidth }}" class="van-swipe-cell__left" data-key="left" catch:tap="onClick">
|
||||||
<slot name="left" />
|
<slot name="left" />
|
||||||
</view>
|
</view>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
var component_1 = require("../common/component");
|
var component_1 = require("../common/component");
|
||||||
|
var nextTick = function () { return new Promise(function (resolve) { return setTimeout(resolve, 20); }); };
|
||||||
component_1.VantComponent({
|
component_1.VantComponent({
|
||||||
classes: ['title-class', 'content-class'],
|
classes: ['title-class', 'content-class'],
|
||||||
relation: {
|
relation: {
|
||||||
@ -28,49 +29,51 @@ component_1.VantComponent({
|
|||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
contentHeight: 0,
|
contentHeight: 0,
|
||||||
expanded: false
|
expanded: false,
|
||||||
|
transition: false
|
||||||
},
|
},
|
||||||
beforeCreate: function () {
|
mounted: function () {
|
||||||
this.animation = wx.createAnimation({
|
var _this = this;
|
||||||
duration: 300,
|
this.updateExpanded()
|
||||||
timingFunction: 'ease-in-out'
|
.then(nextTick)
|
||||||
|
.then(function () {
|
||||||
|
_this.set({ transition: true });
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
updateExpanded: function () {
|
updateExpanded: function () {
|
||||||
if (!this.parent) {
|
if (!this.parent) {
|
||||||
return null;
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
var _a = this.parent.data, value = _a.value, accordion = _a.accordion, items = _a.items;
|
var _a = this.parent.data, value = _a.value, accordion = _a.accordion;
|
||||||
|
var _b = this.parent.children, children = _b === void 0 ? [] : _b;
|
||||||
var name = this.data.name;
|
var name = this.data.name;
|
||||||
var index = items.indexOf(this);
|
var index = children.indexOf(this);
|
||||||
var currentName = name == null ? index : name;
|
var currentName = name == null ? index : name;
|
||||||
var expanded = accordion
|
var expanded = accordion
|
||||||
? value === currentName
|
? value === currentName
|
||||||
: value.some(function (name) { return name === currentName; });
|
: (value || []).some(function (name) { return name === currentName; });
|
||||||
|
var stack = [];
|
||||||
if (expanded !== this.data.expanded) {
|
if (expanded !== this.data.expanded) {
|
||||||
this.updateStyle(expanded);
|
stack.push(this.updateStyle(expanded));
|
||||||
}
|
}
|
||||||
this.set({ index: index, expanded: expanded });
|
stack.push(this.set({ index: index, expanded: expanded }));
|
||||||
|
return Promise.all(stack);
|
||||||
},
|
},
|
||||||
updateStyle: function (expanded) {
|
updateStyle: function (expanded) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
this.getRect('.van-collapse-item__content').then(function (res) {
|
return this.getRect('.van-collapse-item__content')
|
||||||
var animationData = _this.animation
|
.then(function (rect) { return rect.height; })
|
||||||
.height(expanded ? res.height : 0)
|
.then(function (height) {
|
||||||
.step()
|
|
||||||
.export();
|
|
||||||
if (expanded) {
|
if (expanded) {
|
||||||
_this.set({ animationData: animationData });
|
return _this.set({
|
||||||
|
contentHeight: height ? height + "px" : 'auto'
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
_this.set({
|
return _this.set({ contentHeight: height + "px" })
|
||||||
contentHeight: res.height + 'px'
|
.then(nextTick)
|
||||||
}, function () {
|
.then(function () { return _this.set({ contentHeight: 0 }); });
|
||||||
setTimeout(function () {
|
|
||||||
_this.set({ animationData: animationData });
|
|
||||||
}, 20);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -79,7 +82,7 @@ component_1.VantComponent({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var _a = this.data, name = _a.name, expanded = _a.expanded;
|
var _a = this.data, name = _a.name, expanded = _a.expanded;
|
||||||
var index = this.parent.data.items.indexOf(this);
|
var index = this.parent.children.indexOf(this);
|
||||||
var currentName = name == null ? index : name;
|
var currentName = name == null ? index : name;
|
||||||
this.parent.switch(currentName, !expanded);
|
this.parent.switch(currentName, !expanded);
|
||||||
},
|
},
|
||||||
|
@ -30,9 +30,8 @@
|
|||||||
/>
|
/>
|
||||||
</van-cell>
|
</van-cell>
|
||||||
<view
|
<view
|
||||||
class="van-collapse-item__wrapper"
|
class="{{ utils.bem('collapse-item__wrapper', { transition }) }}"
|
||||||
style="height: {{ contentHeight }};"
|
style="height: {{ contentHeight }};"
|
||||||
animation="{{ animationData }}"
|
|
||||||
bind:transitionend="onTransitionEnd"
|
bind:transitionend="onTransitionEnd"
|
||||||
>
|
>
|
||||||
<view
|
<view
|
||||||
|
@ -1 +1 @@
|
|||||||
@import '../common/index.wxss';.van-collapse-item__title .van-cell__right-icon{-webkit-transform:rotate(90deg);transform:rotate(90deg);transition:.3s}.van-collapse-item__title--expanded .van-cell__right-icon{-webkit-transform:rotate(-90deg);transform:rotate(-90deg)}.van-collapse-item__title--disabled .van-cell,.van-collapse-item__title--disabled .van-cell__right-icon{color:#c9c9c9!important}.van-collapse-item__title--disabled .van-cell--hover{background-color:#fff!important}.van-collapse-item__wrapper{overflow:hidden}.van-collapse-item__content{padding:15px;font-size:13px;line-height:1.5;color:#999;background-color:#fff}
|
@import '../common/index.wxss';.van-collapse-item__title .van-cell__right-icon{-webkit-transform:rotate(90deg);transform:rotate(90deg);transition:.3s}.van-collapse-item__title--expanded .van-cell__right-icon{-webkit-transform:rotate(-90deg);transform:rotate(-90deg)}.van-collapse-item__title--disabled .van-cell,.van-collapse-item__title--disabled .van-cell__right-icon{color:#c9c9c9!important}.van-collapse-item__title--disabled .van-cell--hover{background-color:#fff!important}.van-collapse-item__wrapper{overflow:hidden}.van-collapse-item__wrapper--transition{transition:height .3s ease-in-out}.van-collapse-item__content{padding:15px;font-size:13px;line-height:1.5;color:#999;background-color:#fff}
|
@ -6,43 +6,38 @@ component_1.VantComponent({
|
|||||||
name: 'collapse-item',
|
name: 'collapse-item',
|
||||||
type: 'descendant',
|
type: 'descendant',
|
||||||
linked: function (child) {
|
linked: function (child) {
|
||||||
this.set({
|
this.children.push(child);
|
||||||
items: this.data.items.concat([child])
|
|
||||||
}, function () {
|
|
||||||
child.updateExpanded();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
value: null,
|
value: {
|
||||||
accordion: Boolean,
|
type: null,
|
||||||
|
observer: 'updateExpanded'
|
||||||
|
},
|
||||||
|
accordion: {
|
||||||
|
type: Boolean,
|
||||||
|
observer: 'updateExpanded'
|
||||||
|
},
|
||||||
border: {
|
border: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
value: true
|
value: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data: {
|
beforeCreate: function () {
|
||||||
items: []
|
this.children = [];
|
||||||
},
|
},
|
||||||
watch: {
|
methods: {
|
||||||
value: function () {
|
updateExpanded: function () {
|
||||||
this.data.items.forEach(function (child) {
|
this.children.forEach(function (child) {
|
||||||
child.updateExpanded();
|
child.updateExpanded();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
accordion: function () {
|
|
||||||
this.data.items.forEach(function (child) {
|
|
||||||
child.updateExpanded();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
switch: function (name, expanded) {
|
switch: function (name, expanded) {
|
||||||
var _a = this.data, accordion = _a.accordion, value = _a.value;
|
var _a = this.data, accordion = _a.accordion, value = _a.value;
|
||||||
if (!accordion) {
|
if (!accordion) {
|
||||||
name = expanded
|
name = expanded
|
||||||
? value.concat(name)
|
? (value || []).concat(name)
|
||||||
: value.filter(function (activeName) { return activeName !== name; });
|
: (value || []).filter(function (activeName) { return activeName !== name; });
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
name = expanded ? name : '';
|
name = expanded ? name : '';
|
||||||
|
@ -3,13 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||||||
exports.touch = Behavior({
|
exports.touch = Behavior({
|
||||||
methods: {
|
methods: {
|
||||||
touchStart: function (event) {
|
touchStart: function (event) {
|
||||||
|
var touch = event.touches[0];
|
||||||
this.direction = '';
|
this.direction = '';
|
||||||
this.deltaX = 0;
|
this.deltaX = 0;
|
||||||
this.deltaY = 0;
|
this.deltaY = 0;
|
||||||
this.offsetX = 0;
|
this.offsetX = 0;
|
||||||
this.offsetY = 0;
|
this.offsetY = 0;
|
||||||
this.startX = event.touches[0].clientX;
|
this.startX = touch.clientX;
|
||||||
this.startY = event.touches[0].clientY;
|
this.startY = touch.clientY;
|
||||||
},
|
},
|
||||||
touchMove: function (event) {
|
touchMove: function (event) {
|
||||||
var touch = event.touches[0];
|
var touch = event.touches[0];
|
||||||
@ -17,7 +18,12 @@ exports.touch = Behavior({
|
|||||||
this.deltaY = touch.clientY - this.startY;
|
this.deltaY = touch.clientY - this.startY;
|
||||||
this.offsetX = Math.abs(this.deltaX);
|
this.offsetX = Math.abs(this.deltaX);
|
||||||
this.offsetY = Math.abs(this.deltaY);
|
this.offsetY = Math.abs(this.deltaY);
|
||||||
this.direction = this.offsetX > this.offsetY ? 'horizontal' : this.offsetX < this.offsetY ? 'vertical' : '';
|
this.direction =
|
||||||
|
this.offsetX > this.offsetY
|
||||||
|
? 'horizontal'
|
||||||
|
: this.offsetX < this.offsetY
|
||||||
|
? 'vertical'
|
||||||
|
: '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
var component_1 = require("../common/component");
|
var component_1 = require("../common/component");
|
||||||
var touch_1 = require("../mixins/touch");
|
var touch_1 = require("../mixins/touch");
|
||||||
var THRESHOLD = 0.15;
|
var THRESHOLD = 0.3;
|
||||||
component_1.VantComponent({
|
component_1.VantComponent({
|
||||||
props: {
|
props: {
|
||||||
disabled: Boolean,
|
disabled: Boolean,
|
||||||
@ -18,93 +18,85 @@ component_1.VantComponent({
|
|||||||
},
|
},
|
||||||
mixins: [touch_1.touch],
|
mixins: [touch_1.touch],
|
||||||
data: {
|
data: {
|
||||||
offset: 0,
|
catchMove: true
|
||||||
draging: false
|
|
||||||
},
|
},
|
||||||
computed: {
|
created: function () {
|
||||||
wrapperStyle: function () {
|
this.offset = 0;
|
||||||
var _a = this.data, offset = _a.offset, draging = _a.draging;
|
|
||||||
var transform = "translate3d(" + offset + "px, 0, 0)";
|
|
||||||
var transition = draging ? 'none' : '.6s cubic-bezier(0.18, 0.89, 0.32, 1)';
|
|
||||||
return "\n -webkit-transform: " + transform + ";\n -webkit-transition: " + transition + ";\n transform: " + transform + ";\n transition: " + transition + ";\n ";
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onTransitionend: function () {
|
|
||||||
this.swipe = false;
|
|
||||||
},
|
|
||||||
open: function (position) {
|
open: function (position) {
|
||||||
var _a = this.data, leftWidth = _a.leftWidth, rightWidth = _a.rightWidth;
|
var _a = this.data, leftWidth = _a.leftWidth, rightWidth = _a.rightWidth;
|
||||||
var offset = position === 'left' ? leftWidth : -rightWidth;
|
var offset = position === 'left' ? leftWidth : -rightWidth;
|
||||||
this.swipeMove(offset);
|
this.swipeMove(offset);
|
||||||
this.resetSwipeStatus();
|
|
||||||
},
|
},
|
||||||
close: function () {
|
close: function () {
|
||||||
this.set({ offset: 0 });
|
this.swipeMove(0);
|
||||||
},
|
|
||||||
resetSwipeStatus: function () {
|
|
||||||
this.swiping = false;
|
|
||||||
this.opened = true;
|
|
||||||
},
|
},
|
||||||
swipeMove: function (offset) {
|
swipeMove: function (offset) {
|
||||||
if (offset === void 0) { offset = 0; }
|
if (offset === void 0) { offset = 0; }
|
||||||
this.set({ offset: offset });
|
this.offset = offset;
|
||||||
offset && (this.swiping = true);
|
var transform = "translate3d(" + offset + "px, 0, 0)";
|
||||||
!offset && (this.opened = false);
|
var transition = this.draging
|
||||||
|
? 'none'
|
||||||
|
: '.6s cubic-bezier(0.18, 0.89, 0.32, 1)';
|
||||||
|
this.set({
|
||||||
|
wrapperStyle: "\n -webkit-transform: " + transform + ";\n -webkit-transition: " + transition + ";\n transform: " + transform + ";\n transition: " + transition + ";\n "
|
||||||
|
});
|
||||||
},
|
},
|
||||||
swipeLeaveTransition: function (direction) {
|
swipeLeaveTransition: function () {
|
||||||
var _a = this.data, offset = _a.offset, leftWidth = _a.leftWidth, rightWidth = _a.rightWidth;
|
var _a = this.data, leftWidth = _a.leftWidth, rightWidth = _a.rightWidth;
|
||||||
var threshold = this.opened ? 1 - THRESHOLD : THRESHOLD;
|
var offset = this.offset;
|
||||||
// right
|
if (rightWidth > 0 && -offset > rightWidth * THRESHOLD) {
|
||||||
if (direction > 0 && -offset > rightWidth * threshold && rightWidth > 0) {
|
|
||||||
this.open('right');
|
this.open('right');
|
||||||
// left
|
|
||||||
}
|
}
|
||||||
else if (direction < 0 && offset > leftWidth * threshold && leftWidth > 0) {
|
else if (leftWidth > 0 && offset > leftWidth * THRESHOLD) {
|
||||||
this.open('left');
|
this.open('left');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.swipeMove();
|
this.swipeMove(0);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
startDrag: function (event) {
|
startDrag: function (event) {
|
||||||
if (this.data.disabled) {
|
if (this.data.disabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.set({ draging: true });
|
this.draging = true;
|
||||||
|
this.startOffset = this.offset;
|
||||||
|
this.firstDirection = '';
|
||||||
this.touchStart(event);
|
this.touchStart(event);
|
||||||
if (this.opened) {
|
|
||||||
this.startX -= this.data.offset;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
noop: function () { },
|
||||||
onDrag: function (event) {
|
onDrag: function (event) {
|
||||||
if (this.data.disabled) {
|
if (this.data.disabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.touchMove(event);
|
this.touchMove(event);
|
||||||
var deltaX = this.deltaX;
|
if (!this.firstDirection) {
|
||||||
var _a = this.data, leftWidth = _a.leftWidth, rightWidth = _a.rightWidth;
|
this.firstDirection = this.direction;
|
||||||
if ((deltaX < 0 && (-deltaX > rightWidth || !rightWidth)) ||
|
this.set({ catchMove: this.firstDirection === 'horizontal' });
|
||||||
(deltaX > 0 && (deltaX > leftWidth || (deltaX > 0 && !leftWidth)))) {
|
}
|
||||||
|
if (this.firstDirection === 'vertical') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.direction === 'horizontal') {
|
var _a = this.data, leftWidth = _a.leftWidth, rightWidth = _a.rightWidth;
|
||||||
this.swipeMove(deltaX);
|
var offset = this.startOffset + this.deltaX;
|
||||||
|
if ((rightWidth > 0 && -offset > rightWidth) ||
|
||||||
|
(leftWidth > 0 && offset > leftWidth)) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
this.swipeMove(offset);
|
||||||
},
|
},
|
||||||
endDrag: function () {
|
endDrag: function () {
|
||||||
if (this.data.disabled) {
|
if (this.data.disabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.set({ draging: false });
|
this.draging = false;
|
||||||
if (this.swiping) {
|
this.swipeLeaveTransition();
|
||||||
this.swipeLeaveTransition(this.data.offset > 0 ? -1 : 1);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
onClick: function (event) {
|
onClick: function (event) {
|
||||||
var _a = event.currentTarget.dataset.key, position = _a === void 0 ? 'outside' : _a;
|
var _a = event.currentTarget.dataset.key, position = _a === void 0 ? 'outside' : _a;
|
||||||
this.$emit('click', position);
|
this.$emit('click', position);
|
||||||
if (!this.data.offset) {
|
if (!this.offset) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.data.asyncClose) {
|
if (this.data.asyncClose) {
|
||||||
|
@ -3,14 +3,12 @@
|
|||||||
data-key="cell"
|
data-key="cell"
|
||||||
catchtap="onClick"
|
catchtap="onClick"
|
||||||
bindtouchstart="startDrag"
|
bindtouchstart="startDrag"
|
||||||
catchtouchmove="onDrag"
|
catchtouchmove="{{ catchMove ? 'noop' : '' }}"
|
||||||
|
capture-bind:touchmove="onDrag"
|
||||||
catchtouchend="endDrag"
|
catchtouchend="endDrag"
|
||||||
catchtouchcancel="endDrag"
|
catchtouchcancel="endDrag"
|
||||||
>
|
>
|
||||||
<view
|
<view style="{{ wrapperStyle }}">
|
||||||
style="{{ wrapperStyle }}"
|
|
||||||
bindtransitionend="onTransitionend"
|
|
||||||
>
|
|
||||||
<view wx:if="{{ leftWidth }}" class="van-swipe-cell__left" data-key="left" catch:tap="onClick">
|
<view wx:if="{{ leftWidth }}" class="van-swipe-cell__left" data-key="left" catch:tap="onClick">
|
||||||
<slot name="left" />
|
<slot name="left" />
|
||||||
</view>
|
</view>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user