This commit is contained in:
Ling53666
2025-08-18 09:11:51 +08:00
commit 02554225da
2516 changed files with 133155 additions and 0 deletions

View File

@ -0,0 +1 @@
@keyframes text-animate-right{33%{margin-left:-5px}66%{margin-left:5px}100%{margin-left:0}}@keyframes text-animate-midd{0%{margin-left:22px}100%{margin-left:0}}@keyframes text-animate-left{33%{margin-left:5px}66%{margin-left:-5px}100%{margin-left:0}}.text-move-right{animation-name:text-animate-right;animation-duration:.5s}.text-move-left{animation-name:text-animate-left;animation-duration:.5s}.text-move-midd{animation-name:text-animate-midd;animation-duration:.5s}.ant-swipe{width:100%;height:100%;overflow:hidden}.ant-swipe-action{height:100%;position:relative}.ant-swipe-action-movable{width:100%;height:100%}.ant-swipe-action-movable-content{height:100%;position:relative}.ant-swipe-action-movable-content-view{height:100%}.ant-swipe-action-movable-content-view-modal{width:100%;height:100%;background:0 0;position:absolute;left:0;top:0;z-index:9}.ant-swipe-action-movable-content-right{height:100%;color:#fff}.ant-swipe-action-movable-content-right-text{height:100%;display:flex;align-items:center;justify-content:center;transition:all 120ms cubic-bezier(.2,.2,.8,1)}.ant-swipe-action-movable-content-right-text .right-text{text-align:center;white-space:nowrap}.ant-swipe-action-movable-content-left{position:absolute;right:0;top:0;color:#fff;display:flex;flex-direction:row;justify-content:flex-end}.ant-swipe-action-movable-content-left-text1{height:100%;display:flex;align-items:center;justify-content:flex-end;transition:all 120ms cubic-bezier(.2,.2,.8,1)}.ant-swipe-action-movable-content-left-text1 .right-text{text-align:center;white-space:nowrap}.ant-swipe-action-is-right-swipe{display:flex;flex-direction:row;justify-content:flex-end}

View File

@ -0,0 +1,116 @@
<import-sjs
from="./index.sjs"
name="util"
></import-sjs>
<view class="ant-swipe">
<view
class="ant-swipe-action"
style="width: {{util.getWidth(rightWidth, leftWidth, inertiaWidth)}};"
>
<movable-area
a:if="{{ready}}"
class="ant-swipe-action-movable"
style="margin-left: {{util.getMarginLeft(rightWidth, leftWidth, inertiaWidth)}}"
>
<movable-view
class="ant-swipe-action-movable-content"
style="width:{{util.getWidth2(rightWidth, leftWidth, inertiaWidth)}}; margin-left: {{util.getMarginLeft2(rightWidth, leftWidth, inertiaWidth)}};"
x="{{swipeX}}"
data-type="content"
animation="{{animation}}"
damping="{{damping}}"
direction="horizontal"
outOfBounds="{{false}}"
disabled="{{disabled}}"
onTap="onSwipeTap"
onChange="onChange"
onChangeEnd="onChangeEnd"
catchTouchEnd="onTouchEnd"
onTouchCancel="onTouchCancel"
catchTouchStart="onTouchStart"
>
<view
class="ant-swipe-action-movable-content-view"
style="{{util.getSlotWidthStyle(rightWidth, leftWidth, _leftButtons, _rightButtons, inertiaWidth)}}"
onTap="onClick"
>
<view
a:if="{{swipedR || swipedL}}"
class="ant-swipe-action-movable-content-view-modal"
></view>
<slot></slot>
</view>
</movable-view>
<movable-view
class="ant-swipe-action-movable-content ant-swipe-action-movable-right{{$id ? '-' + $id : ''}}"
damping="{{damping}}"
style="{{util.getRightMovableContentStyle(tapTypeR, idx, rightWidth, leftWidth, inertiaWidth)}}"
data-type="content"
animation="{{false}}"
disabled="{{true}}"
direction="horizontal"
x="{{moveX * (util.getMoveX(_rightButtons, idx) / rightWidth)}}"
a:for="{{_rightButtons}}"
a:for-index="idx"
a:for-item="item"
key="{{idx}}"
>
<view
class="ant-swipe-action-movable-content-right"
style="background: {{item.bgColor}};width: {{(item.width + inertiaWidth + 1) / 2}}px;"
>
<view
class="ant-swipe-action-movable-content-right-text"
onTap="onItemTap"
data-item="{{util.axmlObj({ item, idx })}}"
aria-hidden="{{!swipedR}}"
style="{{util.getMovableContentRightStyle(item, tapTypeR, idx, rightWidth, inTouch, inertiaWidth, myStyle)}}"
>
<slot name="{{util.getRightSlotName(tapTypeR, idx, item)}}">
<!--display: inline-->
<text class="right-text {{util.getLeft(tapTypeR, idx, _rightButtons, true)}}">{{util.getRightText(tapTypeR, idx, item)}}</text>
</slot>
</view>
</view>
</movable-view>
<movable-view
class="ant-swipe-action-movable-content ant-swipe-action-is-right-swipe ant-swipe-action-movable-left{{$id ? '-' + $id : ''}}"
damping="{{damping}}"
style="{{util.getLeftMovableContentStyle(tapTypeL, idx, leftWidth, inertiaWidth)}}"
data-type="content"
animation="{{false}}"
disabled="{{true}}"
direction="horizontal"
x="{{moveX * (util.getMoveX(_leftButtons, idx) / leftWidth)}}"
a:for="{{_leftButtons}}"
a:for-index="idx"
a:for-item="itemL"
key="{{'left-' + idx}}"
>
<view
class="ant-swipe-action-movable-content-left"
style="background: {{tapTypeL && tapTypeL === 'L-' + idx && _leftButtons.length === 3 && idx === 1 ? 'none' : itemL.bgColor}};width: {{(leftWidth + inertiaWidth) / 2}}px"
>
<view
class="ant-swipe-action-movable-content-left-text1 ant-swipe-action-left"
onTap="onItemTap"
data-item="{{util.axmlObj({ itemL, idx })}}"
aria-hidden="{{!swipedL}}"
style="{{util.getMovableContentLeftStyle(itemL, tapTypeL, idx, leftWidth, inTouch, inertiaWidth, myStyle)}}"
>
<slot name="{{util.getLeftSlotName(tapTypeL, idx, itemL)}}">
<!--display: inline-->
<text
class="right-text"
style="width: 100%"
>
<!--display: inline-->
<text class="right-text {{util.getLeft(tapTypeL, idx, _leftButtons, false)}}">{{util.getLeftText(tapTypeL, idx, itemL)}}</text>
</text>
</slot>
</view>
</view>
</movable-view>
</movable-area>
</view>
</view>

View File

@ -0,0 +1 @@
import '../_util/assert-component2';

View File

@ -0,0 +1,429 @@
import { __assign } from "tslib";
import { SwipeActionDefaultProps } from './props';
import fmtEvent from '../_util/fmtEvent';
import { compareVersion } from '../_util/compareVersion';
import '../_util/assert-component2';
import { platform } from '../_util/platform';
import { getInstanceBoundingClientRect } from '../_util/jsapi/get-instance-bounding-client-rect';
import { transformOptions } from './wechat';
var setStyleObj1 = function (buttons, inertiaWidth) {
var _a, _b, _c;
var widthPos = buttons.length === 2 ? 0.5 : 0.3333;
return [
{ marginLeft: 0 },
{
marginLeft: "".concat(-(((_a = buttons[0]) === null || _a === void 0 ? void 0 : _a.width) + 1 + (inertiaWidth || 0) * widthPos) / 2, "px"),
},
{
marginLeft: "".concat(-(((_b = buttons[0]) === null || _b === void 0 ? void 0 : _b.width) +
((_c = buttons[1]) === null || _c === void 0 ? void 0 : _c.width) +
1 +
(inertiaWidth || 0) * 0.6666) / 2, "px"),
},
];
};
var setStyleObj2 = function (buttons, inertiaWidth) {
var _a, _b, _c, _d;
var length = buttons.length;
if (length === 2) {
return [
{ marginRight: 0 },
{
marginRight: "-".concat((((_a = buttons[0]) === null || _a === void 0 ? void 0 : _a.width) + (inertiaWidth || 0) * 0.5) / 2, "px"),
},
];
}
if (length === 3) {
return [
{ marginRight: 0 },
{
marginRight: "-".concat((((_b = buttons[0]) === null || _b === void 0 ? void 0 : _b.width) + (inertiaWidth || 0) * 0.3333) / 2, "px"),
},
{
marginRight: "-".concat((((_c = buttons[0]) === null || _c === void 0 ? void 0 : _c.width) +
((_d = buttons[1]) === null || _d === void 0 ? void 0 : _d.width) +
(inertiaWidth || 0) * 0.6666) /
2, "px"),
},
];
}
return [{ marginRight: 0 }];
};
var myTimeOut = null;
var getDirectionLeft = function (arr) {
if (arr.length < 2) {
arr = [0, arr[0]];
}
return arr[0] + arr[1] <= 0;
};
var isOldVersion = getIsOldVersion();
function getIsOldVersion() {
if (typeof my === 'undefined') {
return false;
}
var SDKVersion = my.SDKVersion;
return compareVersion(SDKVersion, '2.0.0') < 0;
}
function getInitReady() {
if (platform() === 'wechat') {
return false;
}
if (isOldVersion) {
return false;
}
return true;
}
Component(transformOptions({
props: SwipeActionDefaultProps,
didMount: function () {
var _this = this;
var _a = this.getProps(), defaultSwiped = _a.defaultSwiped, elasticity = _a.elasticity;
this.setButtonItemWidth();
this.setData({ inertiaWidth: !isOldVersion && elasticity ? 20 : 0 });
if (defaultSwiped) {
this.initWidth(function (maxSwipe) {
maxSwipe &&
_this.setData({
swipeX: (maxSwipe + 0.01) * (defaultSwiped === 'right' ? -1 : 1),
swipedR: defaultSwiped === 'right',
swipedL: defaultSwiped === 'left',
});
});
}
},
didUpdate: function (prevProp) {
var _a = this.getProps(), swiped = _a.swiped, damping = _a.damping, elasticity = _a.elasticity;
// 设置不同的滑动位置时需要重置
var rs = prevProp.swiped !== swiped && !swiped;
var is = prevProp.elasticity !== elasticity;
var ds = prevProp.damping !== damping;
if (rs || is || ds) {
this.setData({
swipeX: 0,
swipedR: false,
swipedL: false,
tapTypeL: '',
tapTypeR: '',
});
}
if (is) {
this.setData({ inertiaWidth: elasticity ? 20 : 0 });
}
},
data: {
// 在微信小程序与支付宝小程序基础库 1.0
// 组件初始化时的 margin-left 决定了后续可移动的距离,所以需要等组件初始化以后再加载
ready: getInitReady(),
swipeLeft: true,
swipeX: 0,
moveX: 0,
tapTypeL: '',
tapTypeR: '',
leftWidth: 20,
rightWidth: 20,
maxSwipeL: 0,
maxSwipeR: 0,
inTouch: false,
swipedR: false,
swipedL: false,
changeArr: [0, 0],
myStyle: {},
inertiaWidth: 20,
animation: !isOldVersion,
_leftButtons: [],
_rightButtons: [],
},
methods: {
setWidth: function () {
var _a = this.data, _leftButtons = _a._leftButtons, _rightButtons = _a._rightButtons;
var _rightArr = _rightButtons || [];
var _leftArr = _leftButtons || [];
this.setData({
ready: true,
rightWidth: _rightArr.reduce(function (tolal, cur) {
return tolal + cur.width;
}, 0),
leftWidth: _leftArr.length
? _leftArr.reduce(function (tolal, cur) {
return tolal + cur.width;
}, 0)
: 0,
});
},
setButtonItemWidth: function () {
var _this = this;
var _a = this.getProps(), leftButtons = _a.leftButtons, rightButtons = _a.rightButtons;
leftButtons.forEach(function (i) {
i.width = i.width || 150;
});
rightButtons.forEach(function (i) {
i.width = i.width || 150;
});
this.setData({ _leftButtons: leftButtons, _rightButtons: rightButtons }, function () {
_this.setWidth();
});
},
getProps: function () {
var _this = this;
if (platform() === 'wechat') {
return __assign(__assign({}, this.data), { onSwipeStart: function (v) {
_this.triggerEvent('swipestart', v);
}, onSwipeEnd: function (v) {
_this.triggerEvent('swipeend', v);
}, onButtonTap: function (v) {
_this.triggerEvent('buttontap', v);
} });
}
return this.props;
},
initWidth: function (func) {
var _this = this;
var _a = this.getProps(), leftButtons = _a.leftButtons, rightButtons = _a.rightButtons;
// 获取宽度信息,设置滑轨的宽度、初始化滑动位置
// 如果没有获取到该信息则把左滑禁用掉
rightButtons.length > 0 &&
this.boundingClientRect(".ant-swipe-action-movable-right".concat(this.$id ? '-' + this.$id : '')).then(function (ret) {
if (ret && ret.width) {
_this.setData({ maxSwipeR: ret.width });
func && func(ret.width);
}
});
leftButtons.length > 0 &&
this.boundingClientRect(".ant-swipe-action-movable-left".concat(this.$id ? '-' + this.$id : '')).then(function (ret) {
if (ret && ret.width) {
_this.setData({ maxSwipeL: ret.width });
func && func(ret.width);
}
});
},
boundingClientRect: function (id) {
if (typeof my === 'undefined') {
return getInstanceBoundingClientRect(this, id);
}
return getInstanceBoundingClientRect(my, id);
},
// 向外透出事件
onTouchStart: function () {
var onSwipeStart = this.getProps().onSwipeStart;
var _a = this.data, swipedR = _a.swipedR, swipedL = _a.swipedL;
this.initWidth();
this.setData({ tapTypeL: '', tapTypeR: '', inTouch: true }); // 清空confirmType = auto 的表现
onSwipeStart({
swiped: !!(swipedR || swipedL),
direction: swipedL ? 'left' : swipedR ? 'right' : '',
}, fmtEvent(this.getProps()));
},
onTouchEnd: function (e) {
// 因为微信小程序没有 onChangeEnd 事件
// 所以用 onTouchEnd 模拟 onChangeEnd
if (platform() === 'wechat') {
this.onChangeEnd(e);
}
this.setData({ inTouch: false });
},
// 滑动过程中的事件,是内部事件不向外透出,用于控制右侧按钮的位置信息
onChange: function (e) {
var _this = this;
var _a = this.data, changeArr = _a.changeArr, maxSwipeR = _a.maxSwipeR, maxSwipeL = _a.maxSwipeL, inTouch = _a.inTouch, swipedR = _a.swipedR, swipedL = _a.swipedL, inertiaWidth = _a.inertiaWidth;
var x = e.detail.x;
var L = x;
// changeArr用于精准的控制滑动的方向
var newArr = changeArr[1] === L ? [changeArr] : [changeArr[1], L];
this.setData({ moveX: L, changeArr: newArr });
var ridx = this.getProps().rightButtons.findIndex(function (u) { return u.confirmType === 'move'; });
var lidx = this.getProps().leftButtons.findIndex(function (u) { return u.confirmType === 'move'; });
if (ridx === -1 && lidx === -1)
return;
var isRight = getDirectionLeft(changeArr);
// 左滑时的滑动确认、收起处理
if (isRight) {
if (L < 0 && Math.abs(L) >= maxSwipeR && inTouch && !swipedR) {
clearTimeout(myTimeOut);
myTimeOut = setTimeout(function () {
var _a = _this.data, changeArr = _a.changeArr, maxSwipeR = _a.maxSwipeR, inTouch = _a.inTouch, swipedR = _a.swipedR, moveX = _a.moveX;
var _left = getDirectionLeft(changeArr) && changeArr[0] >= changeArr[1];
if (inTouch &&
maxSwipeR + inertiaWidth + 2 >= Math.abs(moveX) &&
_left &&
!swipedR) {
_this.onSetCheck(true);
}
}, 100);
}
if (changeArr[0] < changeArr[1] && maxSwipeR > L + 4 && inTouch) {
this.setData({ tapTypeR: '', myStyle: {} });
}
}
else {
if (L > 0 && L + 1 >= maxSwipeL && inTouch && !swipedL) {
clearTimeout(myTimeOut);
myTimeOut = setTimeout(function () {
var _a = _this.data, changeArr = _a.changeArr, maxSwipeL = _a.maxSwipeL, inTouch = _a.inTouch, swipedL = _a.swipedL, moveX = _a.moveX;
var _right = !getDirectionLeft(changeArr) && changeArr[1] >= changeArr[0];
if (inTouch && maxSwipeL <= moveX + 1 && _right && !swipedL) {
_this.onSetCheck(false);
}
}, 100);
}
if (changeArr[0] > changeArr[1] && maxSwipeL > L + 2 && inTouch) {
this.setData({ tapTypeL: '', myStyle: {} });
}
}
},
onSetCheck: function (isRight) {
var _a = this.getProps(), rightButtons = _a.rightButtons, leftButtons = _a.leftButtons;
var _b = this.data, inertiaWidth = _b.inertiaWidth, _leftButtons = _b._leftButtons, _rightButtons = _b._rightButtons;
var arr = isRight ? rightButtons : leftButtons;
var idx = arr.findIndex(function (u) { return u.confirmType === 'move'; });
if (idx === -1)
return;
typeof my !== 'undefined' && my.vibrateShort({ success: function () { } });
var styArr = isRight
? setStyleObj1(_rightButtons, inertiaWidth)
: setStyleObj2(_leftButtons, inertiaWidth);
var sty = styArr[idx];
this.setData({ myStyle: sty });
isRight
? this.setData({ tapTypeR: 'R-' + idx })
: this.setData({ tapTypeL: 'L-' + idx });
},
// 意外中断了滑动,则立即开始结算滑动动作
onTouchCancel: function (e) {
this.onChangeEnd(e);
},
onChangeEnd: function (e) {
var x = e.detail.x;
var changeArr = this.data.changeArr;
// 如果是停留在初始态返回
if (x === 0)
return;
// 判断是否是左滑
var isRight = getDirectionLeft(changeArr);
this.setData({ swipeLeft: isRight });
isRight ? this.onSetSwipeRight(x) : this.onSetSwipeLeft(x);
},
onSetSwipeRight: function (x, needBack) {
var _a = this.data, swipedR = _a.swipedR, inTouch = _a.inTouch, tapTypeR = _a.tapTypeR, changeArr = _a.changeArr;
var onButtonTap = this.getProps().onButtonTap;
var isRight = Math.abs(changeArr[1]) > Math.abs(changeArr[0]);
if (!swipedR && Math.abs(x) < 10) {
isRight = false;
}
needBack && (isRight = false);
!isRight && this.setData({ tapTypeR: '', myStyle: {} });
if (inTouch && !!tapTypeR) {
this.setData({ tapTypeR: '', myStyle: {} });
onButtonTap({
direction: 'right',
btnIdx: parseInt(tapTypeR.replace('R-', '')),
}, fmtEvent(this.getProps()));
this.onSwipeRight(false);
return;
}
this.setData({ changeArr: [0, 0] });
this.onSwipeRight(isRight);
},
onSetSwipeLeft: function (x, needBack) {
var _a = this.data, swipedL = _a.swipedL, inTouch = _a.inTouch, tapTypeL = _a.tapTypeL, changeArr = _a.changeArr;
var onButtonTap = this.getProps().onButtonTap;
// true初始是往右滑false: 右滑收起
var isRight = changeArr[1] >= changeArr[0];
if (!swipedL && Math.abs(x) < 10) {
isRight = false;
}
needBack && (isRight = false);
// 清空二次确认的状态
!isRight && this.setData({ tapTypeL: '', myStyle: {} });
// 处理滑动-触发事件
if (inTouch && !!tapTypeL) {
this.setData({ tapTypeL: '', myStyle: {} });
onButtonTap({ direction: 'left', btnIdx: parseInt(tapTypeL.replace('L-', '')) }, fmtEvent(this.getProps()));
this.onSwipeLeft(false);
return;
}
// 清空滑动方向
this.setData({ changeArr: [0, 0] });
this.onSwipeLeft(isRight);
},
// 结算
onSwipeLeft: function (isRight) {
var _this = this;
var onSwipeEnd = this.getProps().onSwipeEnd;
var _a = this.data, maxSwipeL = _a.maxSwipeL, inertiaWidth = _a.inertiaWidth;
// 为了处理到重置状态的效果
var maxX = maxSwipeL + 0.01 + inertiaWidth;
this.setData({
swipeX: isRight ? maxX : -0.01,
}, function () {
var flag = _this.data.swipeX === -0.01;
setTimeout(function () {
_this.setData({
swipeX: flag ? 0 : maxSwipeL + 0.01,
swipedL: !flag,
}, function () {
onSwipeEnd({ direction: 'left', swiped: !!isRight }, fmtEvent(_this.getProps()));
});
}, inertiaWidth > 0 ? 180 : 0);
});
},
onSwipeRight: function (isRight) {
var _this = this;
var _a = this.data, maxSwipeR = _a.maxSwipeR, inertiaWidth = _a.inertiaWidth;
var onSwipeEnd = this.getProps().onSwipeEnd;
// 处理x的位置两次setData X是因为x如果相同位置不会变刚好也把弹性在这里处理了
// 为了处理到重置状态的效果
var maxX = -(maxSwipeR + 0.01 + inertiaWidth);
this.setData({
swipeX: isRight ? maxX : -0.01,
}, function () {
var flag = _this.data.swipeX === -0.01;
setTimeout(function () {
_this.setData({
swipeX: flag ? 0 : -(maxSwipeR + 0.01),
swipedR: !flag,
}, function () {
onSwipeEnd({ direction: 'right', swiped: !!isRight }, fmtEvent(_this.getProps()));
});
}, inertiaWidth > 0 ? 180 : 0);
});
},
// 处理右侧点击事件
onItemTap: function (e) {
var _a = this.data, swipeLeft = _a.swipeLeft, tapTypeL = _a.tapTypeL, tapTypeR = _a.tapTypeR, _leftButtons = _a._leftButtons, _rightButtons = _a._rightButtons;
var onButtonTap = this.getProps().onButtonTap;
if (!onButtonTap)
return;
var _b = e.currentTarget.dataset.item, itemL = _b.itemL, idx = _b.idx, item = _b.item;
var confirmType = (swipeLeft ? item : itemL).confirmType;
if (tapTypeL === 'L-' + idx) {
this.onSetSwipeLeft(0, true);
this.setData({ tapTypeL: '', myStyle: {} });
onButtonTap({ direction: 'left', btnIdx: idx }, fmtEvent(this.getProps()));
return;
}
if (tapTypeR === 'R-' + idx) {
this.onSetSwipeRight(0, true);
this.setData({ tapTypeR: '', myStyle: {} });
onButtonTap({ direction: 'right', btnIdx: idx }, fmtEvent(this.getProps()));
return;
}
// auto 是展开按钮二次确认的效果
if (confirmType === 'tap' || confirmType === 'move') {
var styArr = swipeLeft
? setStyleObj1(_rightButtons)
: setStyleObj2(_leftButtons);
var sty = styArr[idx];
this.setData({ myStyle: sty });
!swipeLeft
? this.setData({ tapTypeL: 'L-' + idx })
: this.setData({ tapTypeR: 'R-' + idx });
}
else {
!swipeLeft
? this.onSetSwipeLeft(0, true)
: this.onSetSwipeRight(0, true);
onButtonTap({ direction: !swipeLeft ? 'left' : 'right', btnIdx: idx }, fmtEvent(this.getProps()));
}
},
},
}));

View File

@ -0,0 +1,3 @@
{
"component": true
}

View File

@ -0,0 +1,144 @@
var getWidth = function getWidth(rightWidth, leftWidth, inertiaWidth) {
var num = (rightWidth || leftWidth) * 2 + inertiaWidth;
var width = rightWidth > leftWidth ? rightWidth : leftWidth;
return rightWidth && leftWidth ? "calc(100% + ".concat(width + inertiaWidth, "px)") : "calc(100% + ".concat(num / 2, "px)");
};
var getMarginLeft = function getMarginLeft(rightWidth, leftWidth, inertiaWidth) {
var width = rightWidth > leftWidth ? rightWidth : leftWidth;
return "calc(-".concat((width + inertiaWidth) / 2, "px)");
};
var getSlotWidthStyle = function getSlotWidthStyle(rightWidth, leftWidth) {
var left = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
var right = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
var inertiaWidth = arguments.length > 4 ? arguments[4] : undefined;
// 右
if (right.length > 0 && left.length === 0) {
return "calc(100% - ".concat((1 + inertiaWidth) / 2, "px)");
}
// 左
if (left.length > 0 && right.length === 0) {
return "width: calc(100% - ".concat(leftWidth / 2, "px); margin-left: ").concat((leftWidth + inertiaWidth) / 2, "px;");
}
if (left.length > 0 && right.length > 0) {
return "width: 100%;margin-left: 0;";
}
};
var getLeft = function getLeft(tapType, idx, right, isLeft) {
var tip = !isLeft ? 'L-' : 'R-';
if (right.length === 1) {
return tapType && tapType === "".concat(tip).concat(idx) ? 'text-move-midd' : '';
}
if (right.length === 3 && idx === 1) {
return tapType && tapType === "".concat(tip).concat(idx) ? 'text-move-midd' : '';
}
var cls = '';
if (idx === 0) {
cls = isLeft ? 'text-move-left' : 'text-move-right';
} else {
cls = isLeft ? 'text-move-right' : 'text-move-left';
}
return tapType && tapType === "".concat(tip).concat(idx) ? cls : '';
};
var getWidth2 = function getWidth2(rightWidth, leftWidth, inertiaWidth) {
var width = rightWidth > leftWidth ? rightWidth : leftWidth;
return rightWidth && leftWidth ? "calc(100% - ".concat(width + inertiaWidth, "px)") : "calc(100% - ".concat((width + inertiaWidth) / 2, "px)");
};
var getMarginLeft2 = function getMarginLeft2(rightWidth, leftWidth, inertiaWidth) {
var num = rightWidth > 0 ? inertiaWidth : 0;
var width = rightWidth > leftWidth ? rightWidth : leftWidth;
return leftWidth && rightWidth ? "".concat((width + num) / 2, "px") : leftWidth > 0 ? 0 : "".concat((width + inertiaWidth) / 2, "px");
};
var getMarginLeft3 = function getMarginLeft3(rightWidth, leftWidth, inertiaWidth) {
var width = rightWidth > leftWidth ? rightWidth : leftWidth;
return leftWidth && rightWidth ? "calc(100% - ".concat((width + inertiaWidth) / 2, "px)") : "calc(100% - ".concat(rightWidth / 2 - 1, "px)");
};
var getMoveX = function getMoveX(rightButtons, idx) {
var arr = rightButtons.slice(idx, rightButtons.length);
return arr.reduce(function (tolal, cur) {
return parseFloat(tolal) + cur.width;
}, 0);
};
var getMovableContentRightStyle = function getMovableContentRightStyle(item, tapTypeR, idx, rightWidth, inTouch, inertiaWidth, myStyle) {
var isTapTypeR = tapTypeR && tapTypeR === "R-".concat(idx);
var myStyleString = isTapTypeR ? styleObjectToString(myStyle) : '';
return "\n font-size: ".concat((item.fontSize || 28) / 2, "px;\n color: ").concat(item.color, ";\n background: ").concat(item.bgColor, ";\n height: calc(100% + 2px);\n ").concat(isTapTypeR ? "width: ".concat((rightWidth + 1 + (item.confirmType === 'move' && inTouch ? inertiaWidth : 0)) / 2, "px;") : "width: ".concat(item.width / 2, "px;"), "\n ").concat(myStyleString);
};
var styleKeyMap = {
'marginRight': 'margin-right',
'marginLeft': 'margin-left',
'fontSize': 'font-size',
zIndex: 'z-index'
};
function styleObjectToString(myStyle) {
var styleKeys = keys(myStyle);
var res = '';
for (var i = 0; i < styleKeys.length; i++) {
var key = styleKeys[i];
res = res + "".concat(styleKeyMap[key] || key, ": ").concat(myStyle[key], "; ");
}
return res;
}
var getMovableContentLeftStyle = function getMovableContentLeftStyle(itemL, tapTypeL, idx, leftWidth, inTouch, inertiaWidth, myStyle) {
var isTapTypeL = tapTypeL && tapTypeL === "L-".concat(idx);
var myStyleString = isTapTypeL ? styleObjectToString(myStyle) : '';
return "\n background: ".concat(itemL.bgColor, ";\n height: calc(100% + 2px);\n font-size: ").concat((itemL.fontSize || 28) / 2, "px;\n color: ").concat(itemL.color, ";\n ").concat(isTapTypeL ? "width: ".concat((leftWidth + 1 + (itemL.confirmType === 'move' && inTouch ? inertiaWidth : 0)) / 2, "px;") : "width: ".concat(itemL.width / 2, "px;"), "\n ").concat(myStyleString);
};
var getLeftSlotName = function getLeftSlotName(tapTypeL, idx, itemL) {
if (!itemL.slotName) {
return '';
}
return tapTypeL && tapTypeL === "L-".concat(idx) ? "".concat(itemL.slotName, "-confirm") : itemL.slotName;
};
var getRightSlotName = function getRightSlotName(tapTypeR, idx, item) {
if (!item.slotName) {
return '';
}
return tapTypeR && tapTypeR === "R-".concat(idx) ? "".concat(item.slotName, "-confirm") : item.slotName;
};
var getLeftText = function getLeftText(tapTypeL, idx, itemL) {
return tapTypeL && tapTypeL === "L-".concat(idx) ? itemL.confirmText || itemL.text : itemL.text;
};
var getRightText = function getRightText(tapTypeR, idx, item) {
return tapTypeR && tapTypeR === "R-".concat(idx) ? item.confirmText || item.text : item.text;
};
var getRightMovableContentStyle = function getRightMovableContentStyle(tapTypeR, idx, rightWidth, leftWidth, inertiaWidth) {
return styleObjectToString({
zIndex: tapTypeR === "R-".concat(idx) ? 1 : 0,
marginLeft: getMarginLeft3(rightWidth, leftWidth, inertiaWidth),
width: (rightWidth - 0.1) / 2 + 'px'
});
};
var getLeftMovableContentStyle = function getLeftMovableContentStyle(tapTypeL, idx, leftWidth, inertiaWidth) {
return styleObjectToString({
zIndex: tapTypeL === "L-".concat(idx) ? 1 : 0,
marginLeft: "".concat(inertiaWidth / 2, "px"),
width: (leftWidth - 1) / 2 + 'px'
});
};
var axmlObj = function axmlObj(obj) {
return obj;
};
export default {
axmlObj: axmlObj,
getWidth2: getWidth2,
getMarginLeft2: getMarginLeft2,
getMarginLeft3: getMarginLeft3,
getRightMovableContentStyle: getRightMovableContentStyle,
getLeftMovableContentStyle: getLeftMovableContentStyle,
getLeft: getLeft,
getWidth: getWidth,
getSlotWidthStyle: getSlotWidthStyle,
getMarginLeft: getMarginLeft,
getMoveX: getMoveX,
getMovableContentRightStyle: getMovableContentRightStyle,
getMovableContentLeftStyle: getMovableContentLeftStyle,
getRightText: getRightText,
getLeftText: getLeftText,
getLeftSlotName: getLeftSlotName,
getRightSlotName: getRightSlotName
};
function keys(obj) {
if (typeof Object.keys === 'function') {
return Object.keys(obj);
}
}

View File

@ -0,0 +1,66 @@
import { IBaseProps } from '../_util/base';
interface SwipeButton {
text: string;
width?: number;
bgColor?: string;
color?: string;
slotName?: string;
confirmType?: '' | 'move' | 'tap';
confirmText?: string;
}
interface SwipeData {
direction: 'right' | 'left' | '';
btnIdx?: number;
swiped?: boolean;
}
export interface ISwipeActionProps extends IBaseProps {
/**
* @description 左侧滑出事件
* @default []
*/
leftButtons: SwipeButton[];
/**
* @description 右侧滑出事件
* @default []
*/
rightButtons: SwipeButton[];
/**
* @description 滑动速度
* @default 70
*/
damping: number | string;
/**
* @description 禁止滑动
* @default false
*/
disabled: boolean;
/**
* @description 禁止滑动
* @default ''
*/
swiped: '' | 'left' | 'right' | boolean;
/**
* @description 禁止滑动
* @default ''
*/
defaultSwiped: '' | 'left' | 'right';
/**
* @description 弹性超出最大滑动距离自动弹回
* @default true
*/
elasticity: boolean;
/**
* @description 滑动结束
*/
onSwipeEnd: (data: SwipeData, e: Record<string, any>) => void;
/**
* @description 滑动、触摸开始
*/
onSwipeStart: (data: SwipeData, e: Record<string, any>) => void;
/**
* @description 右侧滑动按钮的点击事件回调
*/
onButtonTap: (data: SwipeData, e: Record<string, any>) => void;
}
export declare const SwipeActionDefaultProps: Partial<ISwipeActionProps>;
export {};

View File

@ -0,0 +1,12 @@
export var SwipeActionDefaultProps = {
leftButtons: [],
rightButtons: [],
elasticity: true,
swiped: '',
defaultSwiped: '',
damping: 70,
disabled: false,
onSwipeEnd: function () { },
onSwipeStart: function () { },
onButtonTap: function () { },
};

View File

@ -0,0 +1,2 @@
export declare function transformOptions(original: any): any;
export declare function transformProperties(props: any): any;

View File

@ -0,0 +1,46 @@
import { __assign, __rest } from "tslib";
import { platform } from '../_util/platform';
export function transformOptions(original) {
if (platform() === 'wechat') {
var props = original.props, didMount_1 = original.didMount, didUpdate = original.didUpdate, rest = __rest(original, ["props", "didMount", "didUpdate"]);
return __assign(__assign({}, rest), { properties: transformProperties(props), lifetimes: {
attached: function () {
return didMount_1.call(this);
},
}, options: {
multipleSlots: true,
styleIsolation: 'shared',
}, observers: {
'damping, swiped': function () {
this.setData({
swipeX: 0,
swipedR: false,
swipedL: false,
tapTypeL: '',
tapTypeR: '',
});
},
'elasticity': function (elasticity) {
this.setData({
swipeX: 0,
swipedR: false,
swipedL: false,
tapTypeL: '',
tapTypeR: '',
});
this.setData({ inertiaWidth: elasticity ? 20 : 0 });
},
} });
}
return __assign({}, original);
}
export function transformProperties(props) {
var properties = {};
Object.keys(props).forEach(function (key) {
properties[key] = {
type: null,
value: props[key],
};
});
return properties;
}