{"id":32526,"date":"2024-11-25T17:38:22","date_gmt":"2024-11-25T09:38:22","guid":{"rendered":"https:\/\/fwq.ai\/blog\/32526\/"},"modified":"2024-11-25T17:38:22","modified_gmt":"2024-11-25T09:38:22","slug":"%e5%b0%8f%e7%a8%8b%e5%ba%8f%e5%bc%80%e5%8f%91%e4%b9%8b%e5%b7%a6%e6%bb%91%e5%88%a0%e9%99%a4%e9%a1%b5%e9%9d%a2%ef%bc%88%e4%bb%a3%e7%a0%81%e7%a4%ba%e4%be%8b%ef%bc%89","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/32526\/","title":{"rendered":"\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u4e4b\u5de6\u6ed1\u5220\u9664\u9875\u9762\uff08\u4ee3\u7801\u793a\u4f8b\uff09"},"content":{"rendered":"<p>\u672c\u7bc7\u6587\u7ae0\u7ed9\u5927\u5bb6\u5e26\u6765\u7684\u5185\u5bb9\u662f\u5173\u4e8e\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u4e4b\u5de6\u6ed1\u5220\u9664\u9875\u9762\uff08\u4ee3\u7801\u793a\u4f8b\uff09\uff0c\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u4ef7\u503c\uff0c\u6709\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n<p>\u9996\u5148\u58f0\u660e\u4e24\u70b9\uff1a<\/p>\n<ol>\n<li>\n<p>\u601d\u8def\u4ee5\u53ca\u4ee3\u7801\uff0c\u662f\u6839\u636e\u8d44\u6599\u8fdb\u884c\u4e00\u4e9b\u4fee\u6539\u4ee5\u53ca\u8865\u5145\uff0c\u539f\u6587\u5730\u5740\u5728\u6b64<\/p>\n<\/li>\n<li>\n<p>\u4e0b\u9762\u7684\u53ea\u662f demo\uff0c\u5404\u4f4d\u6839\u636e\u81ea\u5df1\u7684\u9700\u8981\u8fdb\u884c\u4fee\u6539\u5b8c\u5584<\/p>\n<\/li>\n<\/ol>\n<p>\u5b9e\u73b0\u7684\u601d\u8def\u6458\u6284\u5982\u4e0b<\/p>\n<p>1\uff0c\u9996\u5148\u9875\u9762\u6bcf\u4e2aitem\u5206\u4e3a\u4e0a\u4e0b\u4e24\u5c42\uff0c\u4e0a\u9762\u4e00\u5c42\u653e\u7f6e\u6b63\u5e38\u5185\u5bb9\uff0c\u4e0b\u9762\u4e00\u5c42\u653e\u7f6e\u5de6\u6ed1\u663e\u793a\u51fa\u7684\u6309\u94ae\uff0c\u8fd9\u4e2a\u53ef\u4ee5\u4f7f\u7528z-index\u6765\u5b9e\u73b0\u5206\u5c42\u3002<\/p>\n<p>2\uff0citem\u4e0a\u5c42\u4f7f\u7528\u7edd\u5bf9\u5b9a\u4f4d\uff0c\u6211\u4eec\u64cd\u7eb5 &nbsp;left &nbsp;\u5c5e\u6027\u7684\u503c\u6765\u5b9e\u73b0\u50cf\u5de6\u79fb\u52a8\u3002<\/p>\n<p>3\uff0c\u6211\u4eec\u901a\u8fc7\u5fae\u4fe1\u5c0f\u7a0b\u5e8fapi\u63d0\u4f9b\u7684touch\u5bf9\u8c61\u548c3\u4e2a\u6709\u5173\u624b\u6307\u89e6\u6478\u7684\u51fd\u6570\uff08touchstart\uff0ctouchmove\uff0ctouchend\uff09\u6765\u5b9e\u73b0item\u968f\u624b\u6307\u79fb\u52a8\u3002<\/p>\n<p><strong>\u9875\u9762\u90e8\u5206<\/strong><\/p>\n<p>\u5728\u9875\u9762\u4e2d\u6ca1\u6709\u592a\u590d\u6742\u7684\u903b\u8f91\uff0c\u9664\u4e86\u6b63\u5e38\u7684\u5faa\u73af\u8f93\u51fa\u6570\u636e\uff0c\u9700\u8981\u6dfb\u52a0\u7ed1\u5b9a touch \u4e8b\u4ef6\u3002<\/p>\n<pre>&lt;view wx:for=\"{{array}}\"&gt;\n    &lt;view bindtouchstart=\"touchS\" bindtouchmove=\"touchM\" bindtouchend=\"touchE\" style=\"{{item.txtStyle}}\" data-index=\"{{index}}\"&gt;\n      &lt;!-- \u7701\u7565\u6570\u636e --&gt;\n\n    &lt;\/view&gt;\n    &lt;view  catchtap=\"delOrder\" data-index='{{index}}' data-order_id='{{item.order_id}}'&gt;\u5220\u9664&lt;\/view&gt;\n&lt;\/view&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>JS \u90e8\u5206<\/strong><\/p>\n<p>JS \u4e2d\u6839\u636e\u7ed1\u5b9a\u7684&nbsp;touch&nbsp;\u4e8b\u4ef6\u89e6\u53d1\u5220\u9664\u6309\u94ae\uff0c\u7528\u6237\u70b9\u51fb\u5220\u9664\uff0c\u53d1\u9001\u8bf7\u6c42\uff0c\u6839\u636e\u8fd4\u56de\u503c\u5bf9\u7528\u6237\u8fdb\u884c\u53cd\u9988\u3002<\/p>\n<pre>Page({\n\n    \/**\n     * \u9875\u9762\u7684\u521d\u59cb\u6570\u636e\n     *\/\n    data: {\n        array:[],\n        delBtnWidth: 150\/\/\u5220\u9664\u6309\u94ae\u5bbd\u5ea6\u5355\u4f4d\uff08rpx\uff09\n    },\n\n    \/**\n     * \u624b\u6307\u89e6\u6478\u5f00\u59cb\n     *\/\n    touchS: function (e) {\n        \/\/\u5224\u65ad\u662f\u5426\u53ea\u6709\u4e00\u4e2a\u89e6\u6478\u70b9\n        if (e.touches.length == 1) {\n            this.setData({\n                \/\/\u8bb0\u5f55\u89e6\u6478\u8d77\u59cb\u4f4d\u7f6e\u7684X\u5750\u6807\n                startX: e.touches[0].clientX\n            });\n        }\n    },\n\n    \/**\n     * \u624b\u6307\u89e6\u6478\u6ed1\u52a8\n     *\/\n    touchM: function (e) {\n        var that = this;\n        if (e.touches.length == 1) {\n            \/\/\u8bb0\u5f55\u89e6\u6478\u70b9\u4f4d\u7f6e\u7684X\u5750\u6807\n            var moveX = e.touches[0].clientX;\n            \/\/\u8ba1\u7b97\u624b\u6307\u8d77\u59cb\u70b9\u7684X\u5750\u6807\u4e0e\u5f53\u524d\u89e6\u6478\u70b9\u7684X\u5750\u6807\u7684\u5dee\u503c\n            var disX = that.data.startX - moveX;\n            \/\/delBtnWidth \u4e3a\u53f3\u4fa7\u6309\u94ae\u533a\u57df\u7684\u5bbd\u5ea6\n            var delBtnWidth = that.data.delBtnWidth;\n            var txtStyle = \"\";\n            if (disX == 0 || disX &lt; 0) {\/\/\u5982\u679c\u79fb\u52a8\u8ddd\u79bb\u5c0f\u4e8e\u7b49\u4e8e0\uff0c\u6587\u672c\u5c42\u4f4d\u7f6e\u4e0d\u53d8\n                txtStyle = \"left:0px\";\n            } else if (disX &gt; 0) {\/\/\u79fb\u52a8\u8ddd\u79bb\u5927\u4e8e0\uff0c\u6587\u672c\u5c42left\u503c\u7b49\u4e8e\u624b\u6307\u79fb\u52a8\u8ddd\u79bb\n                txtStyle = \"left:-\" + disX + \"px\";\n                if (disX &gt;= delBtnWidth) {\n                    \/\/\u63a7\u5236\u624b\u6307\u79fb\u52a8\u8ddd\u79bb\u6700\u5927\u503c\u4e3a\u5220\u9664\u6309\u94ae\u7684\u5bbd\u5ea6\n                    txtStyle = \"left:-\" + delBtnWidth + \"px\";\n                }\n            }\n            \/\/\u83b7\u53d6\u624b\u6307\u89e6\u6478\u7684\u662f\u54ea\u4e00\u4e2aitem\n            var index = e.currentTarget.dataset.index;\n            var list = that.data.array;\n            \/\/\u5c06\u62fc\u63a5\u597d\u7684\u6837\u5f0f\u8bbe\u7f6e\u5230\u5f53\u524ditem\u4e2d\n            list[index].txtStyle = txtStyle;\n            \/\/\u66f4\u65b0\u5217\u8868\u7684\u72b6\u6001\n            this.setData({\n                array: list\n            });\n        }\n    },\n\n    \/**\n     * \u624b\u6307\u89e6\u6478\u7ed3\u675f\n     *\/\n    touchE: function (e) {\n        var that = this;\n        if (e.changedTouches.length == 1) {\n            \/\/\u624b\u6307\u79fb\u52a8\u7ed3\u675f\u540e\u89e6\u6478\u70b9\u4f4d\u7f6e\u7684X\u5750\u6807\n            var endX = e.changedTouches[0].clientX;\n            \/\/\u89e6\u6478\u5f00\u59cb\u4e0e\u7ed3\u675f\uff0c\u624b\u6307\u79fb\u52a8\u7684\u8ddd\u79bb\n            var disX = that.data.startX - endX;\n            var delBtnWidth = that.data.delBtnWidth;\n            \/\/\u5982\u679c\u8ddd\u79bb\u5c0f\u4e8e\u5220\u9664\u6309\u94ae\u76841\/2\uff0c\u4e0d\u663e\u793a\u5220\u9664\u6309\u94ae\n            var txtStyle = disX &gt; delBtnWidth \/ 2 ? \"left:-\" + delBtnWidth + \"px\" : \"left:0px\";\n            \/\/\u83b7\u53d6\u624b\u6307\u89e6\u6478\u7684\u662f\u54ea\u4e00\u9879\n            var index = e.currentTarget.dataset.index;\n            var list = that.data.array;\n            list[index].txtStyle = txtStyle;\n            \/\/\u66f4\u65b0\u5217\u8868\u7684\u72b6\u6001\n            that.setData({\n                array: list\n            });\n        }\n    },\n\n    \/**\n     * \u5220\u9664\u8ba2\u5355\n     *\/\n    delOrder: function (e) {\n        var order_id = e.currentTarget.dataset.order_id;\n        var index = e.currentTarget.dataset.index;\n        var that = this;\n        \/\/ \u8bf7\u6c42\u63a5\u53e3\n        wx.request({\n            url: 'xxxx',\n            data: {\n                order_id: order_id\n            },\n            success: function (res) {\n                if (res.data.message == 'success') {\n                    \/\/ \u5220\u9664\u6210\u529f\n                    that.delItem(index)\n                } else if (res.data.message == 'error') {\n                    \/\/ \u5220\u9664\u5931\u8d25\n                }\n            },\n            fail: function () {\n                \/\/ \u7f51\u7edc\u8bf7\u6c42\u5931\u8d25\n            }\n        })\n    },\n\n    \/**\n     * \u5220\u9664\u9875\u9762item\n     *\/\n    delItem: function (index) {\n        var list = this.data.array\n        list.splice(index, 1);\n        this.setData({\n            array: list\n        });\n    }\n})<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><span style=\"font-family:\"><br \/><\/span> <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u4e4b\u5de6\u6ed1\u5220\u9664\u9875\u9762\uff08\u4ee3\u7801\u793a\u4f8b\uff09\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u7bc7\u6587\u7ae0\u7ed9\u5927\u5bb6\u5e26\u6765\u7684\u5185\u5bb9\u662f\u5173\u4e8e\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u4e4b\u5de6\u6ed1\u5220\u9664\u9875\u9762\uff08\u4ee3\u7801\u793a\u4f8b\uff09\uff0c\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u4ef7\u503c\uff0c\u6709\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\u3002 \u9996\u5148\u58f0\u660e\u4e24\u70b9\uff1a \u601d\u8def\u4ee5\u53ca\u4ee3\u7801\uff0c\u662f\u6839\u636e\u8d44\u6599\u8fdb\u884c\u4e00\u4e9b\u4fee\u6539\u4ee5\u53ca\u8865\u5145\uff0c\u539f\u6587\u5730\u5740\u5728\u6b64 \u4e0b\u9762\u7684\u53ea\u662f demo\uff0c\u5404\u4f4d\u6839\u636e\u81ea\u5df1\u7684\u9700\u8981\u8fdb\u884c\u4fee\u6539\u5b8c\u5584 \u5b9e\u73b0\u7684\u601d\u8def\u6458\u6284\u5982\u4e0b 1\uff0c\u9996\u5148\u9875\u9762\u6bcf\u4e2aitem\u5206\u4e3a\u4e0a\u4e0b\u4e24\u5c42\uff0c\u4e0a\u9762\u4e00\u5c42\u653e\u7f6e\u6b63\u5e38\u5185\u5bb9\uff0c\u4e0b\u9762\u4e00\u5c42\u653e\u7f6e\u5de6\u6ed1\u663e\u793a\u51fa\u7684\u6309\u94ae\uff0c\u8fd9\u4e2a\u53ef\u4ee5\u4f7f\u7528z-index\u6765\u5b9e\u73b0\u5206\u5c42\u3002 2\uff0citem\u4e0a\u5c42\u4f7f\u7528\u7edd\u5bf9\u5b9a\u4f4d\uff0c\u6211\u4eec\u64cd\u7eb5 &nbsp;left &nbsp;\u5c5e\u6027\u7684\u503c\u6765\u5b9e\u73b0\u50cf\u5de6\u79fb\u52a8\u3002 3\uff0c\u6211\u4eec\u901a\u8fc7\u5fae\u4fe1\u5c0f\u7a0b\u5e8fapi\u63d0\u4f9b\u7684touch\u5bf9\u8c61\u548c3\u4e2a\u6709\u5173\u624b\u6307\u89e6\u6478\u7684\u51fd\u6570\uff08touchstart\uff0ctouchmove\uff0ctouchend\uff09\u6765\u5b9e\u73b0item\u968f\u624b\u6307\u79fb\u52a8\u3002 \u9875\u9762\u90e8\u5206 \u5728\u9875\u9762\u4e2d\u6ca1\u6709\u592a\u590d\u6742\u7684\u903b\u8f91\uff0c\u9664\u4e86\u6b63\u5e38\u7684\u5faa\u73af\u8f93\u51fa\u6570\u636e\uff0c\u9700\u8981\u6dfb\u52a0\u7ed1\u5b9a touch \u4e8b\u4ef6\u3002 &lt;view wx:for=&#8221;{{array}}&#8221;&gt; &lt;view bindtouchstart=&#8221;touchS&#8221; bindtouchmove=&#8221;touchM&#8221; bindtouchend=&#8221;touchE&#8221; style=&#8221;{{item.txtStyle}}&#8221; data-index=&#8221;{{index}}&#8221;&gt; &lt;!&#8211; \u7701\u7565\u6570\u636e &#8211;&gt; &lt;\/view&gt; &lt;view catchtap=&#8221;delOrder&#8221; data-index='{{index}}&#8217; data-order_id='{{item.order_id}}&#8217;&gt;\u5220\u9664&lt;\/view&gt; &lt;\/view&gt; \u767b\u5f55\u540e\u590d\u5236 JS \u90e8\u5206 JS \u4e2d\u6839\u636e\u7ed1\u5b9a\u7684&nbsp;touch&nbsp;\u4e8b\u4ef6\u89e6\u53d1\u5220\u9664\u6309\u94ae\uff0c\u7528\u6237\u70b9\u51fb\u5220\u9664\uff0c\u53d1\u9001\u8bf7\u6c42\uff0c\u6839\u636e\u8fd4\u56de\u503c\u5bf9\u7528\u6237\u8fdb\u884c\u53cd\u9988\u3002 Page({ \/** * \u9875\u9762\u7684\u521d\u59cb\u6570\u636e *\/ data: { array:[], delBtnWidth: 150\/\/\u5220\u9664\u6309\u94ae\u5bbd\u5ea6\u5355\u4f4d\uff08rpx\uff09 }, \/** * \u624b\u6307\u89e6\u6478\u5f00\u59cb *\/ touchS: function (e) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-32526","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32526","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=32526"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32526\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=32526"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=32526"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=32526"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}