From d1448cb0ef10f358bb7bddb4e1ec268515e0b787 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期二, 15 七月 2025 11:46:57 +0800
Subject: [PATCH] 项目初始化

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

diff --git a/uni_modules/uview-ui/components/u-swipe-action-item/nvue.js b/uni_modules/uview-ui/components/u-swipe-action-item/nvue.js
new file mode 100644
index 0000000..118e4cf
--- /dev/null
+++ b/uni_modules/uview-ui/components/u-swipe-action-item/nvue.js
@@ -0,0 +1,174 @@
+// nvue鎿嶄綔dom鐨勫簱锛岀敤浜庤幏鍙杁om鐨勫昂瀵镐俊鎭�
+const dom = uni.requireNativePlugin('dom');
+const bindingX = uni.requireNativePlugin('bindingx');
+const animation = uni.requireNativePlugin('animation');
+
+export default {
+	data() {
+		return {
+			// 鎵�鏈夋寜閽殑鎬诲搴�
+			buttonsWidth: 0,
+			// 鏄惁姝e湪绉诲姩涓�
+			moving: false
+		}
+	},
+	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(n) {
+			if(n) {
+				this.moveCellByAnimation('open') 
+			} else {
+				this.moveCellByAnimation('close') 
+			}
+		}
+	},
+	mounted() {
+		this.initialize()
+	},
+	methods: {
+		initialize() {
+			this.queryRect() 
+		},
+		// 鍏抽棴鍗曞厓鏍硷紝鐢ㄤ簬鎵撳紑涓�涓紝鑷姩鍏抽棴鍏朵粬鍗曞厓鏍肩殑鍦烘櫙
+		closeHandler() {
+			if(this.status === 'open') {
+				// 濡傛灉鍦ㄦ墦寮�鐘舵�佷笅锛岃繘琛岀偣鍑荤殑璇濓紝鐩存帴鍏抽棴鍗曞厓鏍�
+				return this.moveCellByAnimation('close') && this.unbindBindingX()
+			}
+		},
+		// 鐐瑰嚮鍗曞厓鏍�
+		clickHandler() {
+			// 濡傛灉鍦ㄧЩ鍔ㄤ腑琚偣鍑伙紝杩涜蹇界暐
+			if(this.moving) return
+			// 灏濊瘯鍏抽棴鍏朵粬鎵撳紑鐨勫崟鍏冩牸
+			this.parent && this.parent.closeOther(this)
+			if(this.status === 'open') {
+				// 濡傛灉鍦ㄦ墦寮�鐘舵�佷笅锛岃繘琛岀偣鍑荤殑璇濓紝鐩存帴鍏抽棴鍗曞厓鏍�
+				return this.moveCellByAnimation('close') && this.unbindBindingX()
+			}
+		},
+		// 婊戝姩鍗曞厓鏍�
+		onTouchstart(e) {
+			// 濡傛灉褰撳墠姝e湪绉诲姩涓紝鎴栬�卍isabled鐘舵�侊紝鍒欒繑鍥�
+			if(this.moving || this.disabled) { 
+				return this.unbindBindingX()   
+			}
+			if(this.status === 'open') {
+				// 濡傛灉鍦ㄦ墦寮�鐘舵�佷笅锛岃繘琛岀偣鍑荤殑璇濓紝鐩存帴鍏抽棴鍗曞厓鏍�
+				return this.moveCellByAnimation('close') && this.unbindBindingX()
+			}
+			// 鐗规畩鎯呭喌涓嬶紝e鍙兘涓嶄负涓�涓璞�
+			e?.stopPropagation && e.stopPropagation() 
+			e?.preventDefault && e.preventDefault()
+			this.moving = true
+			// 鑾峰彇鍏冪礌ref
+			const content = this.getContentRef()
+			let expression = `min(max(${-this.buttonsWidth}, x), 0)`
+			// 灏濊瘯鍏抽棴鍏朵粬鎵撳紑鐨勫崟鍏冩牸
+			this.parent && this.parent.closeOther(this)
+			
+			// 闃块噷涓轰簡KPI鑰屽紑婧愮殑BindingX
+			this.panEvent = bindingX.bind({
+				anchor: content,
+				eventType: 'pan',
+				props: [{
+					element: content,
+					// 缁戝畾width灞炴�э紝璁剧疆鍏跺搴﹀��
+					property: 'transform.translateX',
+					expression
+				}]
+			}, (res) => {
+				this.moving = false
+				if (res.state === 'end' || res.state === 'exit') {
+					const deltaX = res.deltaX
+					if(deltaX <= -this.buttonsWidth || deltaX >= 0) {
+						// 濡傛灉瑙︽懜婊戝姩鐨勮繃绋嬩腑锛屽ぇ浜庡崟鍏冩牸鐨勬�诲搴︼紝鎴栬�呭ぇ浜�0锛屾剰鍛崇潃宸茬粡鍔ㄨ繃婊戝姩杈惧埌浜嗘墦寮�鎴栬�呭叧闂殑鐘舵��
+						// 杩欓噷鐩存帴杩涜鐘舵�佺殑鏍囪
+						this.$nextTick(() => {
+							this.status = deltaX <= -this.buttonsWidth ? 'open' : 'close'
+						})
+					} else if(Math.abs(deltaX) > uni.$u.getPx(this.threshold)) {
+						// 鍦ㄧЩ鍔ㄥぇ浜庨槇鍊笺�佸苟涓斿皬浜庢�绘寜閽搴︽椂锛岃繘琛岃嚜鍔ㄦ墦寮�鎴栬�呭叧闂�
+						// 绉诲姩璺濈澶т簬0鏃讹紝鎰忓懗鐫�闇�瑕佸叧闂姸鎬�
+						if(Math.abs(deltaX) < this.buttonsWidth) {
+							this.moveCellByAnimation(deltaX > 0 ? 'close' : 'open')
+						}
+					} else {
+						// 鍦ㄥ皬浜庨槇鍊兼椂锛岃繘琛屽叧闂搷浣�(濡傛灉鍦ㄦ墦寮�鐘舵�佷笅锛屽皢涓嶄細鎵цbindingX)
+						this.moveCellByAnimation('close')
+					}
+				}
+			})
+		},
+		// 閲婃斁bindingX
+		unbindBindingX() {
+			// 閲婃斁涓婁竴娆$殑璧勬簮
+			if (this?.panEvent?.token != 0) {
+				bindingX.unbind({
+					token: this.panEvent?.token,
+					// pan涓烘墜鍔夸簨浠�
+					eventType: 'pan'
+				})
+			}
+		},
+		// 鏌ヨ鎸夐挳鑺傜偣淇℃伅
+		queryRect() {
+			// 鍘嗛亶鎵�鏈夋寜閽暟缁勶紝閫氳繃getRectByDom杩斿洖涓�涓猵romise
+			const promiseAll = this.options.map((item, index) => {
+				return 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鐨刣om妯″潡锛屾煡璇㈣妭鐐逛俊鎭�
+		getRectByDom(ref) {
+			return new Promise(resolve => {
+				dom.getComponentRect(ref, res => {
+					resolve(res.size)
+				})
+			}) 
+		},
+		// 绉诲姩鍗曞厓鏍煎埌宸﹁竟鎴栬�呭彸杈瑰敖澶�
+		moveCellByAnimation(status = 'open') {
+			if(this.moving) return
+			// 鏍囪瘑褰撳墠鐘舵��
+			this.moveing = true
+			const content = this.getContentRef()
+			const x = status === 'open' ? -this.buttonsWidth : 0 
+			animation.transition(content, {
+				styles: {
+					transform: `translateX(${x}px)`,
+				},
+				duration: uni.$u.getDuration(this.duration, false),
+				timingFunction: 'ease-in-out'
+			}, () => {
+				this.moving = false
+				this.status = status
+				this.unbindBindingX()
+			})
+		},
+		// 鑾峰彇鍏冪礌ref
+		getContentRef() {
+			return this.$refs['u-swipe-action-item__content'].ref
+		},
+		beforeDestroy() {
+			this.unbindBindingX()
+		}
+	}
+}

--
Gitblit v1.9.3