From 1e61215b48e59e94c1ed98e4ef956227d689d6bc Mon Sep 17 00:00:00 2001
From: quanyawei <401863037@qq.com>
Date: Mon, 06 Nov 2023 08:48:39 +0800
Subject: [PATCH] fix:小程序订阅消息

---
 uni_modules/uview-ui/components/u-swipe-action-item/nvue - backup.js |  270 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 270 insertions(+), 0 deletions(-)

diff --git a/uni_modules/uview-ui/components/u-swipe-action-item/nvue - backup.js b/uni_modules/uview-ui/components/u-swipe-action-item/nvue - backup.js
new file mode 100644
index 0000000..6b9f116
--- /dev/null
+++ b/uni_modules/uview-ui/components/u-swipe-action-item/nvue - backup.js
@@ -0,0 +1,270 @@
+// nvue������dom���������������������dom���������������
+const dom = uni.requireNativePlugin('dom')
+// nvue���������������������������������������������uni.animation������������uni.animation������������nvue
+const animation = uni.requireNativePlugin('animation')
+
+export default {
+    data() {
+        return {
+            // ���������������
+            moving: false,
+            // ���������open-���������������close-������������
+            status: 'close',
+            // ������������������X���Y���������
+            startX: 0,
+            startY: 0,
+            // ���������������������������������������
+            buttons: [],
+            // ������������������������
+            buttonsWidth: 0,
+            // ���������������������������������
+            moveX: 0,
+            // ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
+            lastX: 0
+        }
+    },
+    computed: {
+        // ������������������
+        getDuratin() {
+            let duration = String(this.duration)
+            // ������ms������������������ms���������������
+            if (duration.indexOf('ms') >= 0) return parseInt(duration)
+            // ������s������������������������ms������������������������1000
+            if (duration.indexOf('s') >= 0) return parseInt(duration) * 1000
+            // ���������������������������������30������������s������
+            duration = Number(duration)
+            return duration < 30 ? duration * 1000 : duration
+        }
+    },
+    watch: {
+        show: {
+            immediate: true,
+            handler(n) {
+                // if(n === true) {
+                // 	uni.$u.sleep(50).then(() => {
+                // 		this.openSwipeAction()
+                // 	})
+                // } else {
+                // 	this.closeSwipeAction()
+                // }
+            }
+        }
+    },
+    mounted() {
+        uni.$u.sleep(20).then(() => {
+            this.queryRect()
+        })
+    },
+    methods: {
+        close() {
+            this.closeSwipeAction()
+        },
+        // ���������������
+        touchstart(event) {
+            if (this.disabled) return
+            this.closeOther()
+            const { touches } = event
+            // ���������������������������������
+            this.startX = touches[0].pageX
+            this.startY = touches[0].pageY
+        },
+        // // ������������
+        touchmove(event) {
+            if (this.disabled) return
+            const { touches } = event
+            const { pageX } = touches[0]
+            const { pageY } = touches[0]
+            let moveX = pageX - this.startX
+            const moveY = pageY - this.startY
+            const { buttonsWidth } = this
+            const len = this.buttons.length
+
+            // ������������������������������������������������������������������������������������
+            if (Math.abs(pageX - this.lastX) < 0.3) return
+            this.lastX = pageX
+
+            // ���������X���������������Y���������������������������������������������������X���������������45���������������������������
+            if (Math.abs(moveX) > Math.abs(moveY) || Math.abs(moveX) > this.threshold) {
+                event.stopPropagation()
+            }
+            // ���������������X���������������Y���������������������������������������������������������Y���������������45���������������������������������������������������������������������
+            if (Math.abs(moveX) < Math.abs(moveY)) return
+
+            // ���������������������������������������������������������������������������X������������������0������������������
+            // ������������������return������������������������������������������������������������������������������������������������
+            // ������������������������0
+            if (this.status === 'open') {
+                // ���������������������������������������������
+                if (moveX < 0) moveX = 0
+                // ������������������������������������������������������������������
+                if (moveX > buttonsWidth) moveX = buttonsWidth
+                // ������������������������������������������������������������������������
+                this.moveSwipeAction(-buttonsWidth + moveX)
+            } else {
+                // ������������������������������������
+                if (moveX > 0) moveX = 0
+                // ���������������������������������������������������������������������������������������������������������������������������������
+                if (Math.abs(moveX) > buttonsWidth) moveX = -buttonsWidth
+                // ������������������������������������������������������������������������������������������������������
+                this.moveSwipeAction(moveX)
+            }
+        },
+        // ���������������������
+        touchend(event) {
+            if (this.disabled) return
+            const touches = event.changedTouches ? event.changedTouches[0] : {}
+            const { pageX } = touches
+            const { pageY } = touches
+            const { buttonsWidth } = this
+            this.moveX = pageX - this.startX
+            if (this.status === 'open') {
+                // ���������������������������������������������������
+                if (this.moveX < 0) this.moveX = 0
+                if (this.moveX > buttonsWidth) this.moveX = buttonsWidth
+                // ������������������������������������������������moveX���0������������������������������������������������������������
+                if (this.moveX === 0) {
+                    return this.closeSwipeAction()
+                }
+                // ���������������������������������������������������������������������������������������������������������
+                if (Math.abs(this.moveX) < this.threshold) {
+                    this.openSwipeAction()
+                } else {
+                    // ������������������������������������������������������
+                    this.closeSwipeAction()
+                }
+            } else {
+                // ���������������������������������������������
+                if (this.moveX >= 0) this.moveX = 0
+                if (this.moveX <= -buttonsWidth) this.moveX = -buttonsWidth
+                // ������������
+                if (Math.abs(this.moveX) < this.threshold) {
+                    this.closeSwipeAction()
+                } else {
+                    this.openSwipeAction()
+                }
+            }
+        },
+        // ���������������������������������������������������������������������
+        moveSwipeAction(moveX) {
+            if (this.moving) return
+            this.moving = true
+
+            let previewButtonsMoveX = 0
+            const len = this.buttons.length
+            animation.transition(this.$refs['u-swipe-action-item__content'].ref, {
+                styles: {
+                    transform: `translateX(${moveX}px)`
+                },
+                timingFunction: 'linear'
+            }, () => {
+                this.moving = false
+            })
+            // ���������������������
+            for (let i = len - 1; i >= 0; i--) {
+                const buttonRef = this.$refs[`u-swipe-action-item__right__button-${i}`][0].ref
+                // ���������������������������������������������������
+                const translateX = this.buttons[i].width / this.buttonsWidth * moveX
+                // ���������������������������������������������������������������������������������������������������������������������
+                const realTranslateX = translateX + previewButtonsMoveX
+                animation.transition(buttonRef, {
+                    styles: {
+                        transform: `translateX(${realTranslateX}px)`
+                    },
+                    duration: 0,
+                    delay: 0,
+                    timingFunction: 'linear'
+                }, () => {})
+                // ���������������������������������������������������������
+                previewButtonsMoveX += translateX
+            }
+        },
+        // ������������
+        closeSwipeAction() {
+            if (this.status === 'close') return
+            this.moving = true
+            const { buttonsWidth } = this
+            animation.transition(this.$refs['u-swipe-action-item__content'].ref, {
+                styles: {
+                    transform: 'translateX(0px)'
+                },
+                duration: this.getDuratin,
+                timingFunction: 'ease-in-out'
+            }, () => {
+                this.status = 'close'
+                this.moving = false
+                this.closeHandler()
+            })
+            // ���������������������
+            const len = this.buttons.length
+            for (let i = len - 1; i >= 0; i--) {
+                const buttonRef = this.$refs[`u-swipe-action-item__right__button-${i}`][0].ref
+                // ������������������������������������
+                if (this.buttons.length === 0 || !this.buttons[i] || !this.buttons[i].width) return
+
+                animation.transition(buttonRef, {
+                    styles: {
+                        transform: 'translateX(0px)'
+                    },
+                    duration: this.getDuratin,
+                    timingFunction: 'ease-in-out'
+                }, () => {})
+            }
+        },
+        // ������������
+        openSwipeAction() {
+            if (this.status === 'open') return
+            this.moving = true
+            const buttonsWidth = -this.buttonsWidth
+            let previewButtonsMoveX = 0
+            animation.transition(this.$refs['u-swipe-action-item__content'].ref, {
+                styles: {
+                    transform: `translateX(${buttonsWidth}px)`
+                },
+                duration: this.getDuratin,
+                timingFunction: 'ease-in-out'
+            }, () => {
+                this.status = 'open'
+                this.moving = false
+                this.openHandler()
+            })
+            // ���������������������
+            const len = this.buttons.length
+            for (let i = len - 1; i >= 0; i--) {
+                const buttonRef = this.$refs[`u-swipe-action-item__right__button-${i}`][0].ref
+                // ������������������������������������
+                if (this.buttons.length === 0 || !this.buttons[i] || !this.buttons[i].width) return
+                // ���������������������������������������������������
+                const translateX = this.buttons[i].width / this.buttonsWidth * buttonsWidth
+                // ���������������������������������������������������������������������������������������������������������������������
+                const realTranslateX = translateX + previewButtonsMoveX
+                animation.transition(buttonRef, {
+                    styles: {
+                        transform: `translateX(${realTranslateX}px)`
+                    },
+                    duration: this.getDuratin,
+                    timingFunction: 'ease-in-out'
+                }, () => {})
+                previewButtonsMoveX += translateX
+            }
+        },
+        // ������������������������
+        queryRect() {
+            // ���������������������������������getRectByDom������������promise
+            const promiseAll = this.rightOptions.map((item, index) => this.getRectByDom(this.$refs[`u-swipe-action-item__right__button-${index}`][0]))
+            // ������promise.all������������������������������������������������������������������
+            Promise.all(promiseAll).then((sizes) => {
+                this.buttons = sizes
+                // ���������������������������
+                this.buttonsWidth = sizes.reduce((sum, cur) => sum + cur.width, 0)
+            })
+        },
+        // ������nvue���dom���������������������������
+        getRectByDom(ref) {
+            return new Promise((resolve) => {
+                dom.getComponentRect(ref, (res) => {
+                    resolve(res.size)
+                })
+            })
+        }
+    }
+}

--
Gitblit v1.8.0