From f26f29d84e0a68831a6af14dab3eec5500496d2e Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期三, 28 五月 2025 16:48:52 +0800
Subject: [PATCH] 初始化项目

---
 uview-ui/libs/mixin/mixin.js |   64 ++++++++++++++++++++++++++++++++
 1 files changed, 64 insertions(+), 0 deletions(-)

diff --git a/uview-ui/libs/mixin/mixin.js b/uview-ui/libs/mixin/mixin.js
new file mode 100644
index 0000000..e388986
--- /dev/null
+++ b/uview-ui/libs/mixin/mixin.js
@@ -0,0 +1,64 @@
+module.exports = {
+	data() {
+		return {}
+	},
+	onLoad() {
+		// getRect鎸傝浇鍒�$u涓婏紝鍥犱负杩欐柟娉曢渶瑕佷娇鐢╥n(this)锛屾墍浠ユ棤娉曟妸瀹冪嫭绔嬫垚涓�涓崟鐙殑鏂囦欢瀵煎嚭
+		this.$u.getRect = this.$uGetRect
+	},
+	methods: {
+		// 鏌ヨ鑺傜偣淇℃伅
+		// 鐩墠姝ゆ柟娉曞湪鏀粯瀹濆皬绋嬪簭涓棤娉曡幏鍙栫粍浠惰窡鎺ョ偣鐨勫昂瀵革紝涓烘敮浠樺疂鐨刡ug(2020-07-21)
+		// 瑙e喅鍔炴硶涓哄湪缁勪欢鏍归儴鍐嶅涓�涓病鏈変换浣曚綔鐢ㄧ殑view鍏冪礌
+		$uGetRect(selector, all) {
+			return new Promise(resolve => {
+				uni.createSelectorQuery().
+				in(this)[all ? 'selectAll' : 'select'](selector)
+					.boundingClientRect(rect => {
+						if (all && Array.isArray(rect) && rect.length) {
+							resolve(rect)
+						}
+						if (!all && rect) {
+							resolve(rect)
+						}
+					})
+					.exec()
+			})
+		},
+		getParentData(parentName = '') {
+			// 閬垮厤鍦╟reated涓幓瀹氫箟parent鍙橀噺
+			if(!this.parent) this.parent = false;
+			// 杩欓噷鐨勬湰璐ㄥ師鐞嗘槸锛岄�氳繃鑾峰彇鐖剁粍浠跺疄渚�(涔熷嵆u-radio-group鐨則his)
+			// 灏嗙埗缁勪欢this涓搴旂殑鍙傛暟锛岃祴鍊肩粰鏈粍浠�(u-radio鐨則his)鐨刾arentData瀵硅薄涓搴旂殑灞炴��
+			// 涔嬫墍浠ラ渶瑕佽繖涔堝仛锛屾槸鍥犱负鎵�鏈夌涓紝澶存潯灏忕▼搴忎笉鏀寔閫氳繃this.parent.xxx鍘荤洃鍚埗缁勪欢鍙傛暟鐨勫彉鍖�
+			this.parent = this.$u.$parent.call(this, parentName);
+			if(this.parent) {
+				// 鍘嗛亶parentData涓殑灞炴�э紝灏唒arent涓殑鍚屽悕灞炴�ц祴鍊肩粰parentData
+				Object.keys(this.parentData).map(key => {
+					this.parentData[key] = this.parent[key];
+				});
+			}
+		},
+		// 闃绘浜嬩欢鍐掓场
+		preventEvent(e) {
+			e && e.stopPropagation && e.stopPropagation()
+		}
+	},
+	onReachBottom() {
+		uni.$emit('uOnReachBottom')
+	},
+	beforeDestroy() {
+		// 鍒ゆ柇褰撳墠椤甸潰鏄惁瀛樺湪parent鍜宑hldren锛屼竴鑸湪checkbox鍜宑heckbox-group鐖跺瓙鑱斿姩鐨勫満鏅細鏈夋鎯呭喌
+		// 缁勪欢閿�姣佹椂锛岀Щ闄ゅ瓙缁勪欢鍦ㄧ埗缁勪欢children鏁扮粍涓殑瀹炰緥锛岄噴鏀捐祫婧愶紝閬垮厤鏁版嵁娣蜂贡
+		if(this.parent && uni.$u.test.array(this.parent.children)) {
+			// 缁勪欢閿�姣佹椂锛岀Щ闄ょ埗缁勪欢涓殑children鏁扮粍涓搴旂殑瀹炰緥
+			const childrenList = this.parent.children
+			childrenList.map((child, index) => {
+				// 濡傛灉鐩哥瓑锛屽垯绉婚櫎
+				if(child === this) {
+					childrenList.splice(index, 1)
+				}
+			})
+		}
+	}
+}

--
Gitblit v1.9.3