首页 > 其他分享 >uniapp实现左滑显示编辑删除按钮

uniapp实现左滑显示编辑删除按钮

时间:2024-05-23 15:22:31浏览次数:19  
标签:uniapp right console log 左滑 index csListArrl currentTarget 按钮

 【使用时可删除不必要的内容,我就是记录一下】

方法一:详细借鉴(app):http://www.aliyue.net/10130.html

方法二:详细借鉴(微信小程序):https://blog.csdn.net/weixin_41579185/article/details/117747252?spm=1001.2101.3001.6650.2&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2-117747252-blog-123702049.pc_relevant_aa&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2-117747252-blog-123702049.pc_relevant_aa&utm_relevant_index=3

 

<template>
    <view class="padding-sm">
        <view class=" flex justify-between margin-bottom-sm">
            <uni-easyinput style="flex:0.55" class="uni-mt-5" trim="all" placeholder="请输入内容"></uni-easyinput>
            <uni-data-select style="flex:0.4" v-model="value" :localdata="range" placeholder="请选择类型"></uni-data-select>
        </view>
        <view class="main">
            <view v-for="(item, index) in csListArrl" :key="index" :data-index="index" class="order-item"
                @touchstart="drawStart" @touchmove="drawMove" @touchend="drawEnd" :style="'right:'+item.right+'px'">
                <view class="content">
                    <view class="alarm_box1 flex flex-direction">
                        <view class="flex">
                            <image src="../../static/logo.png" mode="" class="alarm_iamge"></image>
                            <view class="flex flex-direction justify-between" style="flex: 1;">
                                <view class="flex justify-between align-end">
                                    <span class="alarm_name">体检</span>
                                    <span class="alarm_time">2024-05-07 16:00</span>
                                </view>
                                <view class="flex  align-end">
                                    <span class="alarm_phone margin-right-sm">类型:医疗</span>
                                    <span class="alarm_phone">状态:即将来到</span>
                                </view>
                                <view class="flex  align-end" style="width: 68vw;">
                                    <view class="alarm_phone Personnel_description">描述:Lorem, ipsum dolor sit amet
                                        consectetur adipisicing elit. Molestias, beatae quasi quidem doloribus ducimus
                                        possimus. Saepe consequatur, neque a molestias commodi deserunt sequi labore
                                        tenetur omnis ipsam ipsum molestiae voluptates.</view>
                                </view>
                            </view>
                        </view>
                    </view>
                </view>
                <view class="remove" @click="delData(item)">删除</view>
                <view class="edit" @click="editData(item)">编辑</view>
            </view>
        </view>

    </view>
</template>

<script>
    export default {
        data() {
            return { //列表数据,可根据自己的业务获取
                //列表数据,可根据自己的业务获取
                csListArrl: [{
                    name: '小A',
                    age: '18',
                    right: 0
                }],
                //左滑默认宽度
                delBtnWidth: 80,

                value: 0,
                range: [{
                        value: 0,
                        text: "篮球"
                    },
                    {
                        value: 1,
                        text: "足球"
                    },
                    {
                        value: 2,
                        text: "游泳"
                    },
                ],

            }
        },
        methods: {
            /* input(e) {
                console.log('输入内容:', e);
            },
            change(e) {
                console.log("e:", e);
            }, */ //开始触摸滑动
            //开始触摸滑动
            drawStart(e) {
                console.log("开始触发");
                var touch = e.touches[0];
                this.startX = touch.clientX;
            },
            //触摸滑动
            drawMove(e) {
                console.log("滑动");
                for (var index in this.csListArrl) {
                    this.$set(this.csListArrl[index], 'right', 0);
                }
                var touch = e.touches[0];
                var item = this.csListArrl[e.currentTarget.dataset.index];
                var disX = this.startX - touch.clientX;
                if (disX >= 20) {
                    if (disX > this.delBtnWidth) {
                        disX = this.delBtnWidth;
                    }
                    this.$set(this.csListArrl[e.currentTarget.dataset.index], 'right', disX);
                } else {
                    this.$set(this.csListArrl[e.currentTarget.dataset.index], 'right', 0);
                }
            },
            //触摸滑动结束
            drawEnd(e) {
                console.log("滑动结束");
                var item = this.csListArrl[e.currentTarget.dataset.index];
                if (item.right >= this.delBtnWidth / 2) {
                    this.$set(this.csListArrl[e.currentTarget.dataset.index], 'right', this.delBtnWidth*2);
                } else {
                    this.$set(this.csListArrl[e.currentTarget.dataset.index], 'right', 0);
                }
            },
            //删除方法
            delData(item) {
                console.log("删除")
                uni.showModal({
                    title: '提示',
                    content: "确认删除该日程?",
                    success: function(res) {
                        if (res.confirm) {
                            console.log('用户点击确定');
                        } else if (res.cancel) {
                            console.log('用户点击取消');
                        }
                    }
                });
            },
            editData(item) {
                uni.showModal({
                    title: '提示',
                    content: "确认编辑该日程?",
                    success: function(res) {
                        if (res.confirm) {
                            console.log('用户点击确定');
                        } else if (res.cancel) {
                            console.log('用户点击取消');
                        }
                    }
                });
            }
        }
    }
</script>

<style lang="scss" scoped>
    .main {
        width: 100%;
        height: auto;
        margin: 10px auto;
        overflow: hidden
    }

    .order-item {
        width: 100%;
        display: flex;
        position: relative;
        margin: 10px auto;
        align-items: right;
        flex-direction: row;
    }

    .content {
        width: 100%;
        // height: 100px;
        margin: 0 auto;
        border: 1px solid #C0C0C0;
    }

    .remove {
        width: 60px;
        right: -150px;
        margin-left: -5%;    
        height: 100%;
        background-color: red;
        color: #FFFFFF;
        position: absolute;
        top: 0;
        
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 16px;
        border-radius: 12rpx;
    }

    .edit {
        height: 100%;
        background-color: green;
        color: white;
        position: absolute;
        top: 0;
        width:60px;
        right: -80px;

        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 16px;
        border-radius: 12rpx;
    }
</style>

 

标签:uniapp,right,console,log,左滑,index,csListArrl,currentTarget,按钮
From: https://www.cnblogs.com/le-cheng/p/18208527

相关文章

  • uniapp中使用mqtt.js的踩坑记录
    最近在uniapp的vue3.0版本中使用mqtt.js库时遇到了一些坑,经过亲身踩坑,现在把实际能够实现在uniapp的app端能够使用mqtt.js的方法步骤记录如下:一、安装首先安装mqtt.js,建议使用较为稳定的3.0.0版本:[email protected]二、引入mqtt.jsimportmqttfrom'mqtt/dist/mqtt.......
  • uniapp 闪屏页被拉伸解决方案 9图制作
    问题当闪屏页是一张图的时候,针对不同分辨率,容易被拉伸解决9图制作(必须是纯色背景)首先拿一张png图用安卓studio打开,就生产了一张9图然后进行9图制作右侧画边,底部画边,然后左边和顶部,利用画边,把可以拉伸的描出来在uniapp里面设置附送大佬的视频https://www.bilibil......
  • uniapp_07_文本截取和canvas
    uniapp_07_文本截取和canvasuniapp的canvas文本截取获取图片颜色renderjs参考uniapp的canvasuniappcancas组件和api请看uniapp的官方文档,咕就不在这里写了,哎早知道当年就好好读书了,现在写个随笔都写不好,标点符号都不会用,果然没救了canvas组件和canvasApi与html......
  • 【unity】在EditorWindow添加自定义的Toolbar按钮
    好久没写了,最近做工具,写了个EditorWindow,为了让使用者方便查看这个工具的文档,想着在导航栏加个问号按钮,点一下打开说明文档就完事~查了下unity手册,发现Unity提供了一个ShowButton 方法,用于在自定义Editor窗口的工具栏中添加自定义内容,下面是实现的例子:privateGUIStyle......
  • uniapp 页面无法后退
    页面C后退的时候报错,且无法后退因为页面A跳转到页面B的时候,传参里面有值为null的对象。从页面B再跳转到其他页面比如页面C,该页面就无法后退,并报上面的错误//页面A跳转到页面Bthis.$u.route({url:'pages/pageB',type:'navigateTo',......
  • uniapp中登录提交密码时用base64加密
    1.在项目文件夹里面的地址栏中输入npm后回车2.在弹出来的管理员界面输入npminstallbase-64后回车3.在需要使用的页面引入importBase64from'base-64';4.提交时转换成base64后提交consten=Base64.encode(password)解密方法constde=Base64.decode(en)......
  • 高德地图安卓sdk,在uniapp中实现,地图上多个坐标点,点击坐标点,显示坐标信息
     <template><viewclass="content"><mapid="map":style="{width:'100%',height:'50vh'}":markers="markers":longitude="longitude":latitude=......
  • GridLayout 等控件来完成多行按钮操作
     第一步,在布局文件中添加一个GridLayout控件,设置它的行列数和间距等属性,例如:<GridLayoutandroid:id="@+id/grid_layout"android:layout_width="match_parent"android:layout_height="wrap_content"android:columnCount="4"andr......
  • uniapp-vue3-oadmin手机后台实例|vite5.x+uniapp多端仿ios管理系统
    原创vue3+uniapp+uni-ui跨端仿ios桌面后台OA管理模板Uni-Vue3-WeOS。uniapp-vue3-os一款基于uni-app+vite5.x+pinia等技术开发的仿ios手机桌面OA管理系统。实现了自定义桌面栅格磁贴布局、多分屏滑动管理、自定义桌面小部件、辅助触控悬浮球等功能。支持编译到H5+小程序端+App端......
  • uniApp生成的h5页面禁止浏览器上缩放页面(支持安卓,ios)
    项目场景:uniapph5内嵌原生appios样式问题:1.双击和双指滑动,内嵌的h5页面均会被放大缩小2.修改ios底部的安全距离的背景色,默认是白色问题描述1.双击和双指滑动,内嵌的h5页面均会被放大缩小2.解决ios底部的安全距离和修改背景色,默认是白色解决方案:安卓只需要在h5.template.h......