You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

205 lines
5.5 KiB
XML

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/**
* 监听页面内值的变化,主要用于动态开关swipe-action
* @param {Object} newValue
* @param {Object} oldValue
* @param {Object} ownerInstance
* @param {Object} instance
*/
function sizeReady(newValue, oldValue, ownerInstance, instance) {
var state = instance.getState()
state.position = JSON.parse(newValue)
if (!state.position || state.position.length === 0) return
var show = state.position[0].show
state.left = state.left || state.position[0].left;
// 通过用户变量,开启或关闭
if (show) {
openState(true, instance, ownerInstance)
} else {
openState(false, instance, ownerInstance)
}
}
/**
* 开始触摸操作
* @param {Object} e
* @param {Object} ins
*/
function touchstart(e, ins) {
var instance = e.instance;
var state = instance.getState();
var pageX = e.touches[0].pageX;
// 开始触摸时移除动画类
instance.removeClass('ani');
var owner = ins.selectAllComponents('.button-hock')
for (var i = 0; i < owner.length; i++) {
owner[i].removeClass('ani');
}
// state.position = JSON.parse(instance.getDataset().position);
state.left = state.left || state.position[0].left;
//
state.width = pageX - state.left;
ins.callMethod('closeSwipe')
}
/**
*
* @param {Object} e
* @param {Object} ownerInstance
*/
function touchmove(e, ownerInstance) {
var instance = e.instance;
var disabled = instance.getDataset().disabled
var state = instance.getState()
// fix by mehaotian, TODO app-vue dataset , h5 undefined ,
disabled = (typeof(disabled) === 'string' ? JSON.parse(disabled) : disabled) || false;
if (disabled) return
var pageX = e.touches[0].pageX;
move(pageX - state.width, instance, ownerInstance)
}
/**
*
* @param {Object} e
* @param {Object} ownerInstance
*/
function touchend(e, ownerInstance) {
var instance = e.instance;
var disabled = instance.getDataset().disabled
var state = instance.getState()
// fix by mehaotian, TODO app-vue dataset , h5 undefined ,
disabled = (typeof(disabled) === 'string' ? JSON.parse(disabled) : disabled) || false;
if (disabled) return
// ,
// fixed by mehaotian touchend click ios13
moveDirection(state.left, -40, instance, ownerInstance)
}
/**
*
* @param {Object} value
* @param {Object} instance
* @param {Object} ownerInstance
*/
function move(value, instance, ownerInstance) {
var state = instance.getState()
//
var x = Math.max(-state.position[1].width, Math.min((value), 0));
state.left = x;
instance.setStyle({
transform: 'translateX(' + x + 'px)',
'-webkit-transform': 'translateX(' + x + 'px)'
})
//
buttonFold(x, instance, ownerInstance)
}
/**
*
* @param {Object} left
* @param {Object} value
* @param {Object} ownerInstance
* @param {Object} ins
*/
function moveDirection(left, value, ins, ownerInstance) {
var state = ins.getState()
var position = state.position
var isopen = state.isopen
if (!position[1].width) {
openState(false, ins, ownerInstance)
return
}
// ,,
if (isopen) {
if (-left <= position[1].width) {
openState(false, ins, ownerInstance)
} else {
openState(true, ins, ownerInstance)
}
return
}
// ,,
if (left <= value) {
openState(true, ins, ownerInstance)
} else {
openState(false, ins, ownerInstance)
}
}
/**
*
* @param {Object} value
* @param {Object} instance
* @param {Object} ownerInstance
*/
function buttonFold(value, instance, ownerInstance) {
var ins = ownerInstance.selectAllComponents('.button-hock');
var state = instance.getState();
var position = state.position;
var arr = [];
var w = 0;
for (var i = 0; i < ins.length; i++) {
if (!ins[i].getDataset().button) return
var btnData = JSON.parse(ins[i].getDataset().button)
// fix by mehaotian TODO app-vue ,,,
if (typeof(btnData) === 'string') {
btnData = JSON.parse(btnData)
}
var button = btnData[i] && btnData[i].width || 0
w += button
arr.push(-w)
//
var distance = arr[i - 1] + value * (arr[i - 1] / position[1].width)
if (i != 0) {
ins[i].setStyle({
transform: 'translateX(' + distance + 'px)',
})
}
}
}
/**
*
* @param {Boolean} type
* @param {Object} ins
* @param {Object} ownerInstance
*/
function openState(type, ins, ownerInstance) {
var state = ins.getState()
var position = state.position
if (state.isopen === undefined) {
state.isopen = false
}
//
if (state.isopen !== type) {
// ,
ownerInstance.callMethod('change', {
open: type
})
}
//
state.isopen = type
//
ins.addClass('ani');
var owner = ownerInstance.selectAllComponents('.button-hock')
for (var i = 0; i < owner.length; i++) {
owner[i].addClass('ani');
}
//
move(type ? -position[1].width : 0, ins, ownerInstance)
}
module.exports = {
sizeReady: sizeReady,
touchstart: touchstart,
touchmove: touchmove,
touchend: touchend
}