zs-mini-ali-ui
Version:
中视编译后版本 ali-ui
381 lines (337 loc) • 10.6 kB
JavaScript
;/******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ({
/***/ 4:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (/* binding */ fmtUnit)
/* harmony export */ });
var jsUnitRpx = 'false';
/* eslint-disable no-continue, prefer-spread */
function fmtUnit(oldUnit) {
var getUnit = oldUnit;
if (jsUnitRpx === 'true') {
if (typeof getUnit === 'string' && getUnit === 'px') {
getUnit = 'rpx';
} else if (typeof getUnit === 'number') {
getUnit *= 2;
} else if (typeof getUnit === 'string') {
getUnit = oldUnit.match(/(\d+|\d+\.\d+)(px)/)[1] * 2 + 'rpx';
}
}
return getUnit;
}
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/ /* webpack/runtime/define property getters */
/******/ (() => {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = (exports, definition) => {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ })();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ (() => {
/******/ // define __esModule on exports
/******/ __webpack_require__.r = (exports) => {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ })();
/******/
/************************************************************************/
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
(() => {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _util_fmtUnit__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(4);
var isV2 = my.canIUse('movable-view.onTouchStart');
var _windowWidth;
Component({
data: {
leftPos: 0,
swiping: false,
holdSwipe: true,
viewWidth: 0,
x: 0,
actionWidth: 0,
transitionVal: 'none',
radiusItemSpace: (0,_util_fmtUnit__WEBPACK_IMPORTED_MODULE_0__["default"])('12px')
},
props: {
className: '',
right: [],
restore: false,
borderRadius: false,
index: null,
swipeitem: null,
height: 0,
enableNew: true,
swipeWidth: ''
},
didMount: function didMount() {
var _this$props = this.props,
enableNew = _this$props.enableNew,
swipeWidth = _this$props.swipeWidth;
var useV2 = isV2 && enableNew;
this.setData({
useV2: useV2
});
if (swipeWidth.match(/%/)) {
this.setData({
swipeWidth: ''
});
}
this.setWindowWidth();
},
didUpdate: function didUpdate(_prevProps, prevData) {
var restore = this.props.restore;
var _this$data = this.data,
holdSwipe = _this$data.holdSwipe,
useV2 = _this$data.useV2;
if (restore === true && _prevProps.restore !== restore || prevData.holdSwipe === true && holdSwipe === false) {
this.setData({
leftPos: 0,
swiping: false,
cellWidth: this.btnWidth,
x: this.btnWidth // V2
});
}
this.getSwipeHeight();
if (!useV2) {
this.setBtnWidth();
this.getSwipeHeight();
}
},
methods: {
setWindowWidth: function setWindowWidth() {
if (!_windowWidth) {
var sysInfo = my.getSystemInfoSync();
if (sysInfo) {
_windowWidth = sysInfo.windowWidth;
this.realSetWindowWidth(sysInfo.windowWidth);
}
} else {
this.realSetWindowWidth(_windowWidth);
}
},
realSetWindowWidth: function realSetWindowWidth(windowWidth) {
this.setData({
viewWidth: windowWidth
});
this.setBtnWidth();
this.getSwipeHeight();
},
setBtnWidth: function setBtnWidth() {
var _this = this;
my.createSelectorQuery().select(".am-swipe-right-" + this.$id).boundingClientRect().exec(function (ret) {
_this.btnWidth = ret && ret[0] && ret[0].width || 0;
if (isV2 && _this.props.enableNew) {
_this.setData({
actionWidth: _this.btnWidth,
x: _this.btnWidth,
cellWidth: _this.btnWidth,
lastWidth: _this.btnWidth
});
}
});
},
getSwipeHeight: function getSwipeHeight() {
var _this2 = this;
var enableNew = this.props.enableNew;
var useV2 = isV2 && enableNew;
if (useV2) {
my.createSelectorQuery().select(".am-swipe-movable-area-" + this.$id).boundingClientRect().exec(function (ret) {
if (!ret) return;
_this2.setData({
height: parseInt(ret[0].height, 0)
});
});
}
},
onSwipeTap: function onSwipeTap() {
this.setData({
cellWidth: this.data.lastWidth
});
if (!this.data.swiping && this.data.x < 0 || this.data.leftPos !== 0) {
this.setData({
leftPos: 0,
swiping: false,
x: 0
});
}
},
onSwipeStart: function onSwipeStart(e) {
this.touchObject = {
startX: e.touches[0].pageX,
startY: e.touches[0].pageY
};
var _this$props2 = this.props,
index = _this$props2.index,
onSwipeStart = _this$props2.onSwipeStart;
if (onSwipeStart) {
onSwipeStart({
index: index
});
}
},
onSwipeMove: function onSwipeMove(e) {
var touchObject = this.touchObject;
var touchePoint = e.touches[0];
var leftPos = this.data.leftPos;
touchObject.endX = touchePoint.pageX; // 首次触发时,计算滑动角度
if (touchObject.direction === undefined) {
var direction = 0;
var xDist = touchObject.startX - touchePoint.pageX || 0;
var yDist = touchObject.startY - touchePoint.pageY || 0;
var r = Math.atan2(yDist, xDist);
var swipeAngle = Math.round(r * 180 / Math.PI);
if (swipeAngle < 0) {
swipeAngle = 360 - Math.abs(swipeAngle);
}
if (swipeAngle <= 45 && swipeAngle >= 0) {
direction = 1;
}
if (swipeAngle <= 360 && swipeAngle >= 315) {
direction = 1;
}
if (swipeAngle >= 135 && swipeAngle <= 225) {
direction = -1;
}
touchObject.direction = direction;
} // 通过角度判断是左右方向
if (touchObject.direction !== 0) {
var newLeftPos = leftPos; // 滑动距离
var distance = touchObject.endX - touchObject.startX; // 左划
if (distance < 0) {
newLeftPos = Math.max(distance, -this.btnWidth); // 右划
} else {
newLeftPos = 0;
}
if (Math.abs(distance) > 10) {
this.setData({
leftPos: newLeftPos,
swiping: distance < 0
});
}
}
},
onSwipeEnd: function onSwipeEnd(e) {
var touchObject = this.touchObject;
if (touchObject.direction !== 0) {
var touchePoint = e.changedTouches[0];
touchObject.endX = touchePoint.pageX;
var leftPos = this.data.leftPos;
var distance = touchObject.endX - touchObject.startX;
var newLeftPos = leftPos;
if (distance < 0) {
if (Math.abs(distance + leftPos) > this.btnWidth * 0.7) {
newLeftPos = -this.btnWidth;
} else {
newLeftPos = 0;
}
}
this.setData({
leftPos: newLeftPos,
swiping: false
});
}
},
onChange: function onChange() {
if (!this.data.swiping) {
this.setData({
swiping: true,
transitionVal: 'transform 100ms linear'
});
}
},
onChangeEnd: function onChangeEnd(e) {
var _this3 = this;
var actionWidth = this.data.actionWidth;
var x = e.detail.x;
this.setData({
x: x < actionWidth / 2 ? -1 : actionWidth - 1,
swiping: false
}, function () {
_this3.setData({
x: _this3.data.x === -1 ? 0 : actionWidth
});
});
},
done: function done() {
var _this4 = this;
this.setData({
holdSwipe: true
}, function () {
_this4.setData({
holdSwipe: false
});
});
},
onItemClick: function onItemClick(e) {
var _this5 = this;
var onRightItemClick = this.props.onRightItemClick;
var holdSwipe = this.data.holdSwipe;
if (onRightItemClick) {
var index = e.target.dataset.index;
onRightItemClick({
index: index,
extra: this.props.extra,
detail: this.props.right[index],
done: this.done.bind(this)
});
}
if (!this.data.swiping && holdSwipe === false) {
setTimeout(function () {
_this5.setData({
leftPos: 0,
swiping: false,
x: 0
});
}, 300);
}
}
}
});
})();
/******/ })()
;