上传代码
This commit is contained in:
@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
let bindIngXMixins = {};
|
||||
exports.bindIngXMixins = bindIngXMixins;
|
@ -0,0 +1,237 @@
|
||||
"use strict";
|
||||
const common_vendor = require("../../../../common/vendor.js");
|
||||
let otherMixins = {};
|
||||
const MIN_DISTANCE = 10;
|
||||
otherMixins = {
|
||||
data() {
|
||||
const elClass = `Uni_${Math.ceil(Math.random() * 1e6).toString(36)}`;
|
||||
return {
|
||||
uniShow: false,
|
||||
left: 0,
|
||||
buttonShow: "none",
|
||||
ani: false,
|
||||
moveLeft: "",
|
||||
elClass
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
show(newVal) {
|
||||
if (this.autoClose)
|
||||
return;
|
||||
this.openState(newVal);
|
||||
},
|
||||
left() {
|
||||
this.moveLeft = `translateX(${this.left}px)`;
|
||||
},
|
||||
buttonShow(newVal) {
|
||||
if (this.autoClose)
|
||||
return;
|
||||
this.openState(newVal);
|
||||
},
|
||||
leftOptions() {
|
||||
this.init();
|
||||
},
|
||||
rightOptions() {
|
||||
this.init();
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.swipeaction = this.getSwipeAction();
|
||||
if (this.swipeaction && Array.isArray(this.swipeaction.children)) {
|
||||
this.swipeaction.children.push(this);
|
||||
}
|
||||
this.init();
|
||||
},
|
||||
methods: {
|
||||
init() {
|
||||
clearTimeout(this.timer);
|
||||
this.timer = setTimeout(() => {
|
||||
this.getSelectorQuery();
|
||||
}, 100);
|
||||
this.left = 0;
|
||||
this.x = 0;
|
||||
},
|
||||
closeSwipe(e) {
|
||||
if (this.autoClose && this.swipeaction) {
|
||||
this.swipeaction.closeOther(this);
|
||||
}
|
||||
},
|
||||
appTouchStart(e) {
|
||||
const {
|
||||
clientX
|
||||
} = e.changedTouches[0];
|
||||
this.clientX = clientX;
|
||||
this.timestamp = (/* @__PURE__ */ new Date()).getTime();
|
||||
},
|
||||
appTouchEnd(e, index, item, position) {
|
||||
const {
|
||||
clientX
|
||||
} = e.changedTouches[0];
|
||||
let diff = Math.abs(this.clientX - clientX);
|
||||
let time = (/* @__PURE__ */ new Date()).getTime() - this.timestamp;
|
||||
if (diff < 40 && time < 300) {
|
||||
this.$emit("click", {
|
||||
content: item,
|
||||
index,
|
||||
position
|
||||
});
|
||||
}
|
||||
},
|
||||
touchstart(e) {
|
||||
if (this.disabled)
|
||||
return;
|
||||
this.ani = false;
|
||||
this.x = this.left || 0;
|
||||
this.stopTouchStart(e);
|
||||
this.autoClose && this.closeSwipe();
|
||||
},
|
||||
touchmove(e) {
|
||||
if (this.disabled)
|
||||
return;
|
||||
this.stopTouchMove(e);
|
||||
if (this.direction !== "horizontal") {
|
||||
return;
|
||||
}
|
||||
this.move(this.x + this.deltaX);
|
||||
return false;
|
||||
},
|
||||
touchend() {
|
||||
if (this.disabled)
|
||||
return;
|
||||
this.moveDirection(this.left);
|
||||
},
|
||||
/**
|
||||
* 设置移动距离
|
||||
* @param {Object} value
|
||||
*/
|
||||
move(value) {
|
||||
value = value || 0;
|
||||
const leftWidth = this.leftWidth;
|
||||
const rightWidth = this.rightWidth;
|
||||
this.left = this.range(value, -rightWidth, leftWidth);
|
||||
},
|
||||
/**
|
||||
* 获取范围
|
||||
* @param {Object} num
|
||||
* @param {Object} min
|
||||
* @param {Object} max
|
||||
*/
|
||||
range(num, min, max) {
|
||||
return Math.min(Math.max(num, min), max);
|
||||
},
|
||||
/**
|
||||
* 移动方向判断
|
||||
* @param {Object} left
|
||||
* @param {Object} value
|
||||
*/
|
||||
moveDirection(left) {
|
||||
const threshold = this.threshold;
|
||||
const isopen = this.isopen || "none";
|
||||
const leftWidth = this.leftWidth;
|
||||
const rightWidth = this.rightWidth;
|
||||
if (this.deltaX === 0) {
|
||||
this.openState("none");
|
||||
return;
|
||||
}
|
||||
if (isopen === "none" && rightWidth > 0 && -left > threshold || isopen !== "none" && rightWidth > 0 && rightWidth + left < threshold) {
|
||||
this.openState("right");
|
||||
} else if (isopen === "none" && leftWidth > 0 && left > threshold || isopen !== "none" && leftWidth > 0 && leftWidth - left < threshold) {
|
||||
this.openState("left");
|
||||
} else {
|
||||
this.openState("none");
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 开启状态
|
||||
* @param {Boolean} type
|
||||
*/
|
||||
openState(type) {
|
||||
const leftWidth = this.leftWidth;
|
||||
const rightWidth = this.rightWidth;
|
||||
let left = "";
|
||||
this.isopen = this.isopen ? this.isopen : "none";
|
||||
switch (type) {
|
||||
case "left":
|
||||
left = leftWidth;
|
||||
break;
|
||||
case "right":
|
||||
left = -rightWidth;
|
||||
break;
|
||||
default:
|
||||
left = 0;
|
||||
}
|
||||
if (this.isopen !== type) {
|
||||
this.throttle = true;
|
||||
this.$emit("change", type);
|
||||
}
|
||||
this.isopen = type;
|
||||
this.ani = true;
|
||||
this.$nextTick(() => {
|
||||
this.move(left);
|
||||
});
|
||||
},
|
||||
close() {
|
||||
this.openState("none");
|
||||
},
|
||||
getDirection(x, y) {
|
||||
if (x > y && x > MIN_DISTANCE) {
|
||||
return "horizontal";
|
||||
}
|
||||
if (y > x && y > MIN_DISTANCE) {
|
||||
return "vertical";
|
||||
}
|
||||
return "";
|
||||
},
|
||||
/**
|
||||
* 重置滑动状态
|
||||
* @param {Object} event
|
||||
*/
|
||||
resetTouchStatus() {
|
||||
this.direction = "";
|
||||
this.deltaX = 0;
|
||||
this.deltaY = 0;
|
||||
this.offsetX = 0;
|
||||
this.offsetY = 0;
|
||||
},
|
||||
/**
|
||||
* 设置滑动开始位置
|
||||
* @param {Object} event
|
||||
*/
|
||||
stopTouchStart(event) {
|
||||
this.resetTouchStatus();
|
||||
const touch = event.touches[0];
|
||||
this.startX = touch.clientX;
|
||||
this.startY = touch.clientY;
|
||||
},
|
||||
/**
|
||||
* 滑动中,是否禁止打开
|
||||
* @param {Object} event
|
||||
*/
|
||||
stopTouchMove(event) {
|
||||
const touch = event.touches[0];
|
||||
this.deltaX = touch.clientX - this.startX;
|
||||
this.deltaY = touch.clientY - this.startY;
|
||||
this.offsetX = Math.abs(this.deltaX);
|
||||
this.offsetY = Math.abs(this.deltaY);
|
||||
this.direction = this.direction || this.getDirection(this.offsetX, this.offsetY);
|
||||
},
|
||||
getSelectorQuery() {
|
||||
const views = common_vendor.index.createSelectorQuery().in(this);
|
||||
views.selectAll("." + this.elClass).boundingClientRect((data) => {
|
||||
if (data.length === 0)
|
||||
return;
|
||||
let show = "none";
|
||||
if (this.autoClose) {
|
||||
show = "none";
|
||||
} else {
|
||||
show = this.show;
|
||||
}
|
||||
this.leftWidth = data[0].width || 0;
|
||||
this.rightWidth = data[1].width || 0;
|
||||
this.buttonShow = show;
|
||||
}).exec();
|
||||
}
|
||||
}
|
||||
};
|
||||
const mpother = otherMixins;
|
||||
exports.mpother = mpother;
|
@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
let mpMixins = {};
|
||||
exports.mpMixins = mpMixins;
|
@ -0,0 +1,98 @@
|
||||
/**
|
||||
* 这里是uni-app内置的常用样式变量
|
||||
*
|
||||
* uni-app 官方扩展插件及插件市场(https://ext.dcloud.net.cn)上很多三方插件均使用了这些样式变量
|
||||
* 如果你是插件开发者,建议你使用scss预处理,并在插件代码中直接使用这些变量(无需 import 这个文件),方便用户通过搭积木的方式开发整体风格一致的App
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* 如果你是App开发者(插件使用者),你可以通过修改这些变量来定制自己的插件主题,实现自定义主题功能
|
||||
*
|
||||
* 如果你的项目同样使用了scss预处理,你也可以直接在你的 scss 代码中使用如下变量,同时无需 import 这个文件
|
||||
*/
|
||||
/* 颜色变量 */
|
||||
/* 行为相关颜色 */
|
||||
/* 文字基本颜色 */
|
||||
/* 背景颜色 */
|
||||
/* 边框颜色 */
|
||||
/* 尺寸变量 */
|
||||
/* 文字尺寸 */
|
||||
/* 图片尺寸 */
|
||||
/* Border Radius */
|
||||
/* 水平间距 */
|
||||
/* 垂直间距 */
|
||||
/* 透明度 */
|
||||
/* 文章场景相关 */
|
||||
.uni-swipe {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
.uni-swipe_box {
|
||||
display: flex;
|
||||
flex-shrink: 0;
|
||||
position: relative;
|
||||
}
|
||||
.uni-swipe_text--center {
|
||||
width: 100%;
|
||||
cursor: grab;
|
||||
}
|
||||
.uni-swipe_button-group {
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
}
|
||||
.button-group--left {
|
||||
left: 0;
|
||||
transform: translateX(-100%);
|
||||
}
|
||||
.button-group--right {
|
||||
right: 0;
|
||||
transform: translateX(100%);
|
||||
}
|
||||
.uni-swipe_button {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 0 20px;
|
||||
}
|
||||
.uni-swipe_button-text {
|
||||
flex-shrink: 0;
|
||||
font-size: 14px;
|
||||
}
|
||||
.ani {
|
||||
transition-property: transform;
|
||||
transition-duration: 0.3s;
|
||||
transition-timing-function: cubic-bezier(0.165, 0.84, 0.44, 1);
|
||||
}
|
||||
.movable-area {
|
||||
/* width: 100%; */
|
||||
height: 45px;
|
||||
}
|
||||
.movable-view {
|
||||
display: flex;
|
||||
/* justify-content: center; */
|
||||
position: relative;
|
||||
flex: 1;
|
||||
height: 45px;
|
||||
z-index: 2;
|
||||
}
|
||||
.movable-view-button {
|
||||
display: flex;
|
||||
flex-shrink: 0;
|
||||
flex-direction: row;
|
||||
height: 100%;
|
||||
background: #C0C0C0;
|
||||
}
|
||||
|
||||
/* .transition {
|
||||
transition: all 0.3s;
|
||||
} */
|
||||
.movable-view-box {
|
||||
flex-shrink: 0;
|
||||
height: 100%;
|
||||
background-color: #fff;
|
||||
}
|
@ -0,0 +1 @@
|
||||
<view class="uni-swipe"><view onTouchStart="{{g}}" onTouchMove="{{h}}" onTouchEnd="{{i}}" style="{{'transform:' + j}}" class="{{('uni-swipe_box') + ' ' + (k && 'ani')}}"><view class="{{('uni-swipe_button-group') + ' ' + 'button-group--left' + ' ' + c}}"><slot name="left"><view a:for="{{a}}" a:for-item="item" a:key="c" style="{{'background-color:' + item.d + ';' + ('font-size:' + item.e)}}" class="uni-swipe_button button-hock" catchTouchStart="{{b}}" catchTouchEnd="{{item.f}}"><text class="uni-swipe_button-text" style="{{'color:' + item.b}}">{{item.a}}</text></view></slot></view><slot></slot><view class="{{('uni-swipe_button-group') + ' ' + 'button-group--right' + ' ' + f}}"><slot name="right"><view a:for="{{d}}" a:for-item="item" a:key="c" style="{{'background-color:' + item.d + ';' + ('font-size:' + item.e)}}" catchTouchStart="{{e}}" catchTouchEnd="{{item.f}}" class="uni-swipe_button button-hock"><text class="uni-swipe_button-text" style="{{'color:' + item.b}}">{{item.a}}</text></view></slot></view></view></view>
|
@ -0,0 +1,116 @@
|
||||
"use strict";
|
||||
const uni_modules_uniSwipeAction_components_uniSwipeActionItem_mpwxs = require("./mpwxs.js");
|
||||
const uni_modules_uniSwipeAction_components_uniSwipeActionItem_bindingx = require("./bindingx.js");
|
||||
const uni_modules_uniSwipeAction_components_uniSwipeActionItem_mpother = require("./mpother.js");
|
||||
const common_vendor = require("../../../../common/vendor.js");
|
||||
const block0 = {};
|
||||
const block1 = {};
|
||||
const _sfc_main = {
|
||||
mixins: [uni_modules_uniSwipeAction_components_uniSwipeActionItem_mpwxs.mpMixins, uni_modules_uniSwipeAction_components_uniSwipeActionItem_bindingx.bindIngXMixins, uni_modules_uniSwipeAction_components_uniSwipeActionItem_mpother.mpother],
|
||||
emits: ["click", "change"],
|
||||
props: {
|
||||
// 控制开关
|
||||
show: {
|
||||
type: String,
|
||||
default: "none"
|
||||
},
|
||||
// 禁用
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
// 是否自动关闭
|
||||
autoClose: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
// 滑动缺省距离
|
||||
threshold: {
|
||||
type: Number,
|
||||
default: 20
|
||||
},
|
||||
// 左侧按钮内容
|
||||
leftOptions: {
|
||||
type: Array,
|
||||
default() {
|
||||
return [];
|
||||
}
|
||||
},
|
||||
// 右侧按钮内容
|
||||
rightOptions: {
|
||||
type: Array,
|
||||
default() {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
},
|
||||
// TODO vue3
|
||||
unmounted() {
|
||||
this.__isUnmounted = true;
|
||||
this.uninstall();
|
||||
},
|
||||
methods: {
|
||||
uninstall() {
|
||||
if (this.swipeaction) {
|
||||
this.swipeaction.children.forEach((item, index) => {
|
||||
if (item === this) {
|
||||
this.swipeaction.children.splice(index, 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 获取父元素实例
|
||||
*/
|
||||
getSwipeAction(name = "uniSwipeAction") {
|
||||
let parent = this.$parent;
|
||||
let parentName = parent.$options.name;
|
||||
while (parentName !== name) {
|
||||
parent = parent.$parent;
|
||||
if (!parent)
|
||||
return false;
|
||||
parentName = parent.$options.name;
|
||||
}
|
||||
return parent;
|
||||
}
|
||||
}
|
||||
};
|
||||
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
||||
return {
|
||||
a: common_vendor.f($props.leftOptions, (item, index, i0) => {
|
||||
return {
|
||||
a: common_vendor.t(item.text),
|
||||
b: item.style && item.style.color ? item.style.color : "#FFFFFF",
|
||||
c: index,
|
||||
d: item.style && item.style.backgroundColor ? item.style.backgroundColor : "#C7C6CD",
|
||||
e: item.style && item.style.fontSize ? item.style.fontSize : "16px",
|
||||
f: common_vendor.o(($event) => _ctx.appTouchEnd($event, index, item, "left"))
|
||||
};
|
||||
}),
|
||||
b: common_vendor.o((...args) => _ctx.appTouchStart && _ctx.appTouchStart(...args)),
|
||||
c: common_vendor.n(_ctx.elClass),
|
||||
d: common_vendor.f($props.rightOptions, (item, index, i0) => {
|
||||
return {
|
||||
a: common_vendor.t(item.text),
|
||||
b: item.style && item.style.color ? item.style.color : "#FFFFFF",
|
||||
c: index,
|
||||
d: item.style && item.style.backgroundColor ? item.style.backgroundColor : "#C7C6CD",
|
||||
e: item.style && item.style.fontSize ? item.style.fontSize : "16px",
|
||||
f: common_vendor.o(($event) => _ctx.appTouchEnd($event, index, item, "right"))
|
||||
};
|
||||
}),
|
||||
e: common_vendor.o((...args) => _ctx.appTouchStart && _ctx.appTouchStart(...args)),
|
||||
f: common_vendor.n(_ctx.elClass),
|
||||
g: common_vendor.o((...args) => _ctx.touchstart && _ctx.touchstart(...args)),
|
||||
h: common_vendor.o((...args) => _ctx.touchmove && _ctx.touchmove(...args)),
|
||||
i: common_vendor.o((...args) => _ctx.touchend && _ctx.touchend(...args)),
|
||||
j: _ctx.moveLeft,
|
||||
k: _ctx.ani ? 1 : ""
|
||||
};
|
||||
}
|
||||
if (typeof block0 === "function")
|
||||
block0(_sfc_main);
|
||||
if (typeof block1 === "function")
|
||||
block1(_sfc_main);
|
||||
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
|
||||
my.createComponent(Component);
|
@ -0,0 +1,5 @@
|
||||
{
|
||||
"component": true,
|
||||
"styleIsolation": "apply-shared",
|
||||
"usingComponents": {}
|
||||
}
|
@ -0,0 +1 @@
|
||||
<view><slot></slot></view>
|
@ -0,0 +1,36 @@
|
||||
"use strict";
|
||||
const common_vendor = require("../../../../common/vendor.js");
|
||||
const _sfc_main = {
|
||||
name: "uniSwipeAction",
|
||||
data() {
|
||||
return {};
|
||||
},
|
||||
created() {
|
||||
this.children = [];
|
||||
},
|
||||
methods: {
|
||||
// 公开给用户使用,重制组件样式
|
||||
resize() {
|
||||
this.children.forEach((vm) => {
|
||||
vm.init();
|
||||
});
|
||||
},
|
||||
// 公开给用户使用,关闭全部 已经打开的组件
|
||||
closeAll() {
|
||||
this.children.forEach((vm) => {
|
||||
vm.close();
|
||||
});
|
||||
},
|
||||
closeOther(vm) {
|
||||
if (this.openItem && this.openItem !== vm) {
|
||||
this.openItem.close();
|
||||
}
|
||||
this.openItem = vm;
|
||||
}
|
||||
}
|
||||
};
|
||||
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
||||
return {};
|
||||
}
|
||||
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
|
||||
my.createComponent(Component);
|
@ -0,0 +1,5 @@
|
||||
{
|
||||
"component": true,
|
||||
"styleIsolation": "apply-shared",
|
||||
"usingComponents": {}
|
||||
}
|
Reference in New Issue
Block a user