452 lines
15 KiB
JavaScript
452 lines
15 KiB
JavaScript
var __wxsModules={};
|
|
|
|
__wxsModules["30f4e25a"] = (() => {
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
var __commonJS = (cb, mod) => function __require() {
|
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
};
|
|
|
|
// <stdin>
|
|
var require_stdin = __commonJS({
|
|
"<stdin>"(exports, module) {
|
|
var me = {};
|
|
me.onMoving = function(ins, rate, downHight) {
|
|
ins.requestAnimationFrame(function() {
|
|
ins.selectComponent(".mescroll-wxs-content").setStyle({
|
|
"will-change": "transform",
|
|
// 可解决下拉过程中, image和swiper脱离文档流的问题
|
|
"transform": "translateY(" + downHight + "px)",
|
|
"transition": ""
|
|
});
|
|
var progress = ins.selectComponent(".mescroll-wxs-progress");
|
|
progress && progress.setStyle({ transform: "rotate(" + 360 * rate + "deg)" });
|
|
});
|
|
};
|
|
me.showLoading = function(ins) {
|
|
me.downHight = me.optDown.offset;
|
|
ins.requestAnimationFrame(function() {
|
|
ins.selectComponent(".mescroll-wxs-content").setStyle({
|
|
"will-change": "auto",
|
|
"transform": "translateY(" + me.downHight + "px)",
|
|
"transition": "transform 300ms"
|
|
});
|
|
});
|
|
};
|
|
me.endDownScroll = function(ins) {
|
|
me.downHight = 0;
|
|
me.isDownScrolling = false;
|
|
ins.requestAnimationFrame(function() {
|
|
ins.selectComponent(".mescroll-wxs-content").setStyle({
|
|
"will-change": "auto",
|
|
"transform": "translateY(0)",
|
|
// 不可以写空串,否则scroll-view渲染不完整 (延时350ms会调clearTransform置空)
|
|
"transition": "transform 300ms"
|
|
});
|
|
});
|
|
};
|
|
me.clearTransform = function(ins) {
|
|
ins.requestAnimationFrame(function() {
|
|
ins.selectComponent(".mescroll-wxs-content").setStyle({
|
|
"will-change": "",
|
|
"transform": "",
|
|
"transition": ""
|
|
});
|
|
});
|
|
};
|
|
function propObserver(wxsProp) {
|
|
if (!wxsProp)
|
|
return;
|
|
me.optDown = wxsProp.optDown;
|
|
me.scrollTop = wxsProp.scrollTop;
|
|
me.bodyHeight = wxsProp.bodyHeight;
|
|
me.isDownScrolling = wxsProp.isDownScrolling;
|
|
me.isUpScrolling = wxsProp.isUpScrolling;
|
|
me.isUpBoth = wxsProp.isUpBoth;
|
|
me.isScrollBody = wxsProp.isScrollBody;
|
|
me.startTop = wxsProp.scrollTop;
|
|
}
|
|
function callObserver(callProp, oldValue, ins) {
|
|
if (me.disabled())
|
|
return;
|
|
if (callProp.callType) {
|
|
if (callProp.callType === "showLoading") {
|
|
me.showLoading(ins);
|
|
} else if (callProp.callType === "endDownScroll") {
|
|
me.endDownScroll(ins);
|
|
} else if (callProp.callType === "clearTransform") {
|
|
me.clearTransform(ins);
|
|
}
|
|
}
|
|
}
|
|
function touchstartEvent(e, ins) {
|
|
me.downHight = 0;
|
|
me.startPoint = me.getPoint(e);
|
|
me.startTop = me.getScrollTop();
|
|
me.startAngle = 0;
|
|
me.lastPoint = me.startPoint;
|
|
me.maxTouchmoveY = me.getBodyHeight() - me.optDown.bottomOffset;
|
|
me.inTouchend = false;
|
|
me.callMethod(ins, { type: "setWxsProp" });
|
|
}
|
|
function touchmoveEvent(e, ins) {
|
|
var isPrevent = true;
|
|
if (me.disabled())
|
|
return isPrevent;
|
|
var scrollTop = me.getScrollTop();
|
|
var curPoint = me.getPoint(e);
|
|
var moveY = curPoint.y - me.startPoint.y;
|
|
if (moveY > 0 && (me.isScrollBody && scrollTop <= 0 || !me.isScrollBody && (scrollTop <= 0 || scrollTop <= me.optDown.startTop && scrollTop === me.startTop))) {
|
|
if (!me.inTouchend && !me.isDownScrolling && !me.optDown.isLock && (!me.isUpScrolling || me.isUpScrolling && me.isUpBoth)) {
|
|
if (!me.startAngle)
|
|
me.startAngle = me.getAngle(me.lastPoint, curPoint);
|
|
if (me.startAngle < me.optDown.minAngle)
|
|
return isPrevent;
|
|
if (me.maxTouchmoveY > 0 && curPoint.y >= me.maxTouchmoveY) {
|
|
me.inTouchend = true;
|
|
touchendEvent(e, ins);
|
|
return isPrevent;
|
|
}
|
|
isPrevent = false;
|
|
var diff = curPoint.y - me.lastPoint.y;
|
|
if (me.downHight < me.optDown.offset) {
|
|
if (me.movetype !== 1) {
|
|
me.movetype = 1;
|
|
me.callMethod(ins, { type: "setLoadType", downLoadType: 1 });
|
|
me.isMoveDown = true;
|
|
}
|
|
me.downHight += diff * me.optDown.inOffsetRate;
|
|
} else {
|
|
if (me.movetype !== 2) {
|
|
me.movetype = 2;
|
|
me.callMethod(ins, { type: "setLoadType", downLoadType: 2 });
|
|
me.isMoveDown = true;
|
|
}
|
|
if (diff > 0) {
|
|
me.downHight += diff * me.optDown.outOffsetRate;
|
|
} else {
|
|
me.downHight += diff;
|
|
}
|
|
}
|
|
me.downHight = Math.round(me.downHight);
|
|
var rate = me.downHight / me.optDown.offset;
|
|
me.onMoving(ins, rate, me.downHight);
|
|
}
|
|
}
|
|
me.lastPoint = curPoint;
|
|
return isPrevent;
|
|
}
|
|
function touchendEvent(e, ins) {
|
|
if (me.isMoveDown) {
|
|
if (me.downHight >= me.optDown.offset) {
|
|
me.downHight = me.optDown.offset;
|
|
me.callMethod(ins, { type: "triggerDownScroll" });
|
|
} else {
|
|
me.downHight = 0;
|
|
me.callMethod(ins, { type: "endDownScroll" });
|
|
}
|
|
me.movetype = 0;
|
|
me.isMoveDown = false;
|
|
} else if (!me.isScrollBody && me.getScrollTop() === me.startTop) {
|
|
var isScrollUp = me.getPoint(e).y - me.startPoint.y < 0;
|
|
if (isScrollUp) {
|
|
var angle = me.getAngle(me.getPoint(e), me.startPoint);
|
|
if (angle > 80) {
|
|
me.callMethod(ins, { type: "triggerUpScroll" });
|
|
}
|
|
}
|
|
}
|
|
me.callMethod(ins, { type: "setWxsProp" });
|
|
}
|
|
me.disabled = function() {
|
|
return !me.optDown || !me.optDown.use || me.optDown.native;
|
|
};
|
|
me.getPoint = function(e) {
|
|
if (!e) {
|
|
return { x: 0, y: 0 };
|
|
}
|
|
if (e.touches && e.touches[0]) {
|
|
return { x: e.touches[0].pageX, y: e.touches[0].pageY };
|
|
} else if (e.changedTouches && e.changedTouches[0]) {
|
|
return { x: e.changedTouches[0].pageX, y: e.changedTouches[0].pageY };
|
|
} else {
|
|
return { x: e.clientX, y: e.clientY };
|
|
}
|
|
};
|
|
me.getAngle = function(p1, p2) {
|
|
var x = Math.abs(p1.x - p2.x);
|
|
var y = Math.abs(p1.y - p2.y);
|
|
var z = Math.sqrt(x * x + y * y);
|
|
var angle = 0;
|
|
if (z !== 0) {
|
|
angle = Math.asin(y / z) / Math.PI * 180;
|
|
}
|
|
return angle;
|
|
};
|
|
me.getScrollTop = function() {
|
|
return me.scrollTop || 0;
|
|
};
|
|
me.getBodyHeight = function() {
|
|
return me.bodyHeight || 0;
|
|
};
|
|
me.callMethod = function(ins, param) {
|
|
if (ins)
|
|
ins.callMethod("wxsCall", param);
|
|
};
|
|
module.exports = {
|
|
propObserver,
|
|
callObserver,
|
|
touchstartEvent,
|
|
touchmoveEvent,
|
|
touchendEvent
|
|
};
|
|
}
|
|
});
|
|
return require_stdin();
|
|
})();
|
|
|
|
|
|
__wxsModules.afd46426 = (() => {
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
var __commonJS = (cb, mod) => function __require() {
|
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
};
|
|
|
|
// <stdin>
|
|
var require_stdin = __commonJS({
|
|
"<stdin>"(exports, module) {
|
|
var MIN_DISTANCE = 10;
|
|
var IS_HTML5 = false;
|
|
if (typeof window === "object")
|
|
IS_HTML5 = true;
|
|
function showWatch(newVal, oldVal, ownerInstance, instance) {
|
|
var state = instance.getState();
|
|
getDom(instance, ownerInstance);
|
|
if (newVal && newVal !== "none") {
|
|
openState(newVal, instance, ownerInstance);
|
|
return;
|
|
}
|
|
if (state.left) {
|
|
openState("none", instance, ownerInstance);
|
|
}
|
|
resetTouchStatus(instance);
|
|
}
|
|
function touchstart(e, ownerInstance) {
|
|
var instance = e.instance;
|
|
var disabled = instance.getDataset().disabled;
|
|
var state = instance.getState();
|
|
getDom(instance, ownerInstance);
|
|
disabled = (typeof disabled === "string" ? JSON.parse(disabled) : disabled) || false;
|
|
if (disabled)
|
|
return;
|
|
instance.requestAnimationFrame(function() {
|
|
instance.removeClass("ani");
|
|
ownerInstance.callMethod("closeSwipe");
|
|
});
|
|
state.x = state.left || 0;
|
|
stopTouchStart(e, ownerInstance);
|
|
}
|
|
function touchmove(e, ownerInstance) {
|
|
var instance = e.instance;
|
|
var disabled = instance.getDataset().disabled;
|
|
var state = instance.getState();
|
|
disabled = (typeof disabled === "string" ? JSON.parse(disabled) : disabled) || false;
|
|
if (disabled)
|
|
return;
|
|
stopTouchMove(e);
|
|
if (state.direction !== "horizontal") {
|
|
return;
|
|
}
|
|
if (e.preventDefault) {
|
|
e.preventDefault();
|
|
}
|
|
move(state.x + state.deltaX, instance, ownerInstance);
|
|
}
|
|
function touchend(e, ownerInstance) {
|
|
var instance = e.instance;
|
|
var disabled = instance.getDataset().disabled;
|
|
var state = instance.getState();
|
|
disabled = (typeof disabled === "string" ? JSON.parse(disabled) : disabled) || false;
|
|
if (disabled)
|
|
return;
|
|
moveDirection(state.left, instance, ownerInstance);
|
|
}
|
|
function move(value, instance, ownerInstance) {
|
|
value = value || 0;
|
|
var state = instance.getState();
|
|
var leftWidth = state.leftWidth;
|
|
var rightWidth = state.rightWidth;
|
|
state.left = range(value, -rightWidth, leftWidth);
|
|
instance.requestAnimationFrame(function() {
|
|
instance.setStyle({
|
|
transform: "translateX(" + state.left + "px)",
|
|
"-webkit-transform": "translateX(" + state.left + "px)"
|
|
});
|
|
});
|
|
}
|
|
function getDom(instance, ownerInstance) {
|
|
var state = instance.getState();
|
|
var leftDom = ownerInstance.selectComponent(".button-group--left");
|
|
var rightDom = ownerInstance.selectComponent(".button-group--right");
|
|
var leftStyles = {
|
|
width: 0
|
|
};
|
|
var rightStyles = {
|
|
width: 0
|
|
};
|
|
leftStyles = leftDom.getBoundingClientRect();
|
|
rightStyles = rightDom.getBoundingClientRect();
|
|
state.leftWidth = leftStyles.width || 0;
|
|
state.rightWidth = rightStyles.width || 0;
|
|
state.threshold = instance.getDataset().threshold;
|
|
}
|
|
function range(num, min, max) {
|
|
return Math.min(Math.max(num, min), max);
|
|
}
|
|
function moveDirection(left, ins, ownerInstance) {
|
|
var state = ins.getState();
|
|
var threshold = state.threshold;
|
|
var position = state.position;
|
|
var isopen = state.isopen || "none";
|
|
var leftWidth = state.leftWidth;
|
|
var rightWidth = state.rightWidth;
|
|
if (state.deltaX === 0) {
|
|
openState("none", ins, ownerInstance);
|
|
return;
|
|
}
|
|
if (isopen === "none" && rightWidth > 0 && -left > threshold || isopen !== "none" && rightWidth > 0 && rightWidth + left < threshold) {
|
|
openState("right", ins, ownerInstance);
|
|
} else if (isopen === "none" && leftWidth > 0 && left > threshold || isopen !== "none" && leftWidth > 0 && leftWidth - left < threshold) {
|
|
openState("left", ins, ownerInstance);
|
|
} else {
|
|
openState("none", ins, ownerInstance);
|
|
}
|
|
}
|
|
function openState(type, ins, ownerInstance) {
|
|
var state = ins.getState();
|
|
var leftWidth = state.leftWidth;
|
|
var rightWidth = state.rightWidth;
|
|
var left = "";
|
|
state.isopen = state.isopen ? state.isopen : "none";
|
|
switch (type) {
|
|
case "left":
|
|
left = leftWidth;
|
|
break;
|
|
case "right":
|
|
left = -rightWidth;
|
|
break;
|
|
default:
|
|
left = 0;
|
|
}
|
|
if (state.isopen !== type) {
|
|
state.throttle = true;
|
|
ownerInstance.callMethod("change", {
|
|
open: type
|
|
});
|
|
}
|
|
state.isopen = type;
|
|
ins.requestAnimationFrame(function() {
|
|
ins.addClass("ani");
|
|
move(left, ins, ownerInstance);
|
|
});
|
|
}
|
|
function getDirection(x, y) {
|
|
if (x > y && x > MIN_DISTANCE) {
|
|
return "horizontal";
|
|
}
|
|
if (y > x && y > MIN_DISTANCE) {
|
|
return "vertical";
|
|
}
|
|
return "";
|
|
}
|
|
function resetTouchStatus(instance) {
|
|
var state = instance.getState();
|
|
state.direction = "";
|
|
state.deltaX = 0;
|
|
state.deltaY = 0;
|
|
state.offsetX = 0;
|
|
state.offsetY = 0;
|
|
}
|
|
function stopTouchStart(event) {
|
|
var instance = event.instance;
|
|
var state = instance.getState();
|
|
resetTouchStatus(instance);
|
|
var touch = event.touches[0];
|
|
if (IS_HTML5 && isPC()) {
|
|
touch = event;
|
|
}
|
|
state.startX = touch.clientX;
|
|
state.startY = touch.clientY;
|
|
}
|
|
function stopTouchMove(event) {
|
|
var instance = event.instance;
|
|
var state = instance.getState();
|
|
var touch = event.touches[0];
|
|
if (IS_HTML5 && isPC()) {
|
|
touch = event;
|
|
}
|
|
state.deltaX = touch.clientX - state.startX;
|
|
state.deltaY = touch.clientY - state.startY;
|
|
state.offsetY = Math.abs(state.deltaY);
|
|
state.offsetX = Math.abs(state.deltaX);
|
|
state.direction = state.direction || getDirection(state.offsetX, state.offsetY);
|
|
}
|
|
function isPC() {
|
|
var userAgentInfo = navigator.userAgent;
|
|
var Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];
|
|
var flag = true;
|
|
for (var v = 0; v < Agents.length - 1; v++) {
|
|
if (userAgentInfo.indexOf(Agents[v]) > 0) {
|
|
flag = false;
|
|
break;
|
|
}
|
|
}
|
|
return flag;
|
|
}
|
|
var movable = false;
|
|
function mousedown(e, ins) {
|
|
if (!IS_HTML5)
|
|
return;
|
|
if (!isPC())
|
|
return;
|
|
touchstart(e, ins);
|
|
movable = true;
|
|
}
|
|
function mousemove(e, ins) {
|
|
if (!IS_HTML5)
|
|
return;
|
|
if (!isPC())
|
|
return;
|
|
if (!movable)
|
|
return;
|
|
touchmove(e, ins);
|
|
}
|
|
function mouseup(e, ins) {
|
|
if (!IS_HTML5)
|
|
return;
|
|
if (!isPC())
|
|
return;
|
|
touchend(e, ins);
|
|
movable = false;
|
|
}
|
|
function mouseleave(e, ins) {
|
|
if (!IS_HTML5)
|
|
return;
|
|
if (!isPC())
|
|
return;
|
|
movable = false;
|
|
}
|
|
module.exports = {
|
|
showWatch,
|
|
touchstart,
|
|
touchmove,
|
|
touchend,
|
|
mousedown,
|
|
mousemove,
|
|
mouseup,
|
|
mouseleave
|
|
};
|
|
}
|
|
});
|
|
return require_stdin();
|
|
})();
|