From 659d09ec24dab6c451220c8f3bb3943b0fdb3ba1 Mon Sep 17 00:00:00 2001
From: quanyawei <401863037@qq.com>
Date: Mon, 08 Jan 2024 16:16:12 +0800
Subject: [PATCH] fix:地图导航

---
 uni_modules/uview-ui/components/u-slider/mpother.js |  113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 113 insertions(+), 0 deletions(-)

diff --git a/uni_modules/uview-ui/components/u-slider/mpother.js b/uni_modules/uview-ui/components/u-slider/mpother.js
new file mode 100644
index 0000000..040c848
--- /dev/null
+++ b/uni_modules/uview-ui/components/u-slider/mpother.js
@@ -0,0 +1,113 @@
+/**
+ * ���������������js������������slider
+ */
+export default {
+    watch: {
+        value(n) {
+            // ���������������������������������������������value���������������������������������������������������������
+            if (this.status === 'end') {
+                this.updateSliderPlacement(n, true)
+            }
+        }
+    },
+    mounted() {
+        this.init()
+    },
+    methods: {
+        init() {
+            this.getSliderRect()
+        },
+        // ������slider������
+        getSliderRect() {
+            // ������������������������������
+            setTimeout(() => {
+                this.$uGetRect('.u-slider').then((rect) => {
+                    this.sliderRect = rect
+                    this.updateSliderPlacement(this.value, true)
+                })
+            }, 10)
+        },
+        // ������������������
+        canNotDo() {
+            return this.disabled
+        },
+        // ������������������������X������������
+        getTouchX(e) {
+            return e.touches[0].clientX
+        },
+        formatStep(value) {
+            // ���������������������������������
+            return Math.round(Math.max(this.min, Math.min(value, this.max)) / this.step) * this.step
+        },
+        // ������������
+        emitEvent(event, value) {
+            this.$emit(event, value || this.value)
+        },
+        // ���������������������������
+        setTouchStatus(status) {
+            this.status = status
+        },
+        onTouchStart(e) {
+            if (this.canNotDo()) {
+                return
+            }
+            // ������������������������������������������
+            this.emitEvent('start')
+            this.setTouchStatus('start')
+        },
+        onTouchMove(e) {
+            if (this.canNotDo()) {
+                return
+            }
+            // ������������������������������������������������������������������������������������������������
+            const x = this.getTouchX(e)
+            const { left, width } = this.sliderRect
+            const distanceX = x - left
+            // ������������������������������������������������������������������������������������������������������������
+            // ������������������������������������������������step������������������������
+            const percent = (distanceX / width) * 100
+            this.setTouchStatus('moving')
+            this.updateSliderPlacement(percent, true, 'moving')
+        },
+        onTouchEnd() {
+            if (this.canNotDo()) {
+                return
+            }
+            this.emitEvent('end')
+            this.setTouchStatus('end')
+        },
+        // ���������������������
+        updateSliderPlacement(value, drag, event) {
+            // ������������������������������������step���������������
+            const { width } = this.sliderRect
+            const percent = this.formatStep(value)
+            // ������������������
+            const barStyle = {
+                width: `${percent / 100 * width}px`
+            }
+            // ������������������������������
+            if (drag === true) {
+                barStyle.transition = 'none'
+            } else {
+                // ������������������������������������������������������css������������������
+                delete barStyle.transition
+            }
+            // ������value���
+            this.$emit('input', percent)
+            // ���������������
+            if (event) {
+                this.emitEvent(event, percent)
+            }
+            this.barStyle = barStyle
+        },
+        onClick(e) {
+            if (this.canNotDo()) {
+                return
+            }
+            // ���������������������������������������������onTouchMove������������
+            const { left, width } = this.sliderRect
+            const value = ((e.detail.x - left) / width) * 100
+            this.updateSliderPlacement(value, false, 'click')
+        }
+    }
+}

--
Gitblit v1.8.0