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/components/u-grid/u-grid.vue |  108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 108 insertions(+), 0 deletions(-)

diff --git a/uview-ui/components/u-grid/u-grid.vue b/uview-ui/components/u-grid/u-grid.vue
new file mode 100644
index 0000000..6588c06
--- /dev/null
+++ b/uview-ui/components/u-grid/u-grid.vue
@@ -0,0 +1,108 @@
+<template>
+	<view class="u-grid" :class="{'u-border-top u-border-left': border}" :style="[gridStyle]"><slot /></view>
+</template>
+
+<script>
+/**
+ * grid 瀹牸甯冨眬
+ * @description 瀹牸缁勪欢涓�鑸敤浜庡悓鏃跺睍绀哄涓悓绫婚」鐩殑鍦烘櫙锛屽彲浠ョ粰瀹牸鐨勯」鐩缃窘鏍囩粍浠�(badge)锛屾垨鑰呭浘鏍囩瓑锛屼篃鍙互鎵╁睍涓哄乏鍙虫粦鍔ㄧ殑杞挱褰㈠紡銆�
+ * @tutorial https://www.uviewui.com/components/grid.html
+ * @property {String Number} col 瀹牸鐨勫垪鏁帮紙榛樿3锛�
+ * @property {Boolean} border 鏄惁鏄剧ず瀹牸鐨勮竟妗嗭紙榛樿true锛�
+ * @property {Boolean} hover-class 鐐瑰嚮瀹牸鐨勬椂鍊欙紝鏄惁鏄剧ず鎸変笅鐨勭伆鑹茶儗鏅紙榛樿false锛�
+ * @event {Function} click 鐐瑰嚮瀹牸瑙﹀彂
+ * @example <u-grid :col="3" @click="click"></u-grid>
+ */
+export default {
+	name: 'u-grid',
+	props: {
+		// 鍒嗘垚鍑犲垪
+		col: {
+			type: [Number, String],
+			default: 3
+		},
+		// 鏄惁鏄剧ず杈规
+		border: {
+			type: Boolean,
+			default: true
+		},
+		// 瀹牸瀵归綈鏂瑰紡锛岃〃鐜颁负鏁伴噺灏戠殑鏃跺�欙紝闈犲乏锛屽眳涓紝杩樻槸闈犲彸
+		align: {
+			type: String,
+			default: 'left'
+		},
+		// 瀹牸鎸夊帇鏃剁殑鏍峰紡绫伙紝"none"涓烘棤鏁堟灉
+		hoverClass: {
+			type: String,
+			default: 'u-hover-class'
+		}
+	},
+	data() {
+		return {
+			index: 0,
+		}
+	},
+	watch: {
+		// 褰撶埗缁勪欢闇�瑕佸瓙缁勪欢闇�瑕佸叡浜殑鍙傛暟鍙戠敓浜嗗彉鍖栵紝鎵嬪姩閫氱煡瀛愮粍浠�
+		parentData() {
+			if(this.children.length) {
+				this.children.map(child => {
+					// 鍒ゆ柇瀛愮粍浠�(u-radio)濡傛灉鏈塽pdateParentData鏂规硶鐨勮瘽锛屽氨灏辨墽琛�(鎵ц鐨勭粨鏋滄槸瀛愮粍浠堕噸鏂颁粠鐖剁粍浠舵媺鍙栦簡鏈�鏂扮殑鍊�)
+					typeof(child.updateParentData) == 'function' && child.updateParentData();
+				})
+			}
+		},
+	},
+	created() {
+		// 濡傛灉灏哻hildren瀹氫箟鍦╠ata涓紝鍦ㄥ井淇″皬绋嬪簭浼氶�犳垚寰幆寮曠敤鑰屾姤閿�
+		this.children = [];
+	},
+	computed: {
+		// 璁$畻鐖剁粍浠剁殑鍊兼槸鍚﹀彂鐢熷彉鍖�
+		parentData() {
+			return [this.hoverClass, this.col, this.size, this.border];
+		},
+		// 瀹牸瀵归綈鏂瑰紡
+		gridStyle() {
+			let style = {};
+			switch(this.align) {
+				case 'left':
+					style.justifyContent = 'flex-start';
+					break;
+				case 'center':
+					style.justifyContent = 'center';
+					break;
+				case 'right':
+					style.justifyContent = 'flex-end';
+					break;
+				default: style.justifyContent = 'flex-start';
+			};
+			return style;
+		}
+	},
+	methods: {
+		click(index) {
+			this.$emit('click', index);
+		}
+	}
+};
+</script>
+
+<style scoped lang="scss">
+@import "../../libs/css/style.components.scss";
+
+.u-grid {
+	width: 100%;
+	/* #ifdef MP */
+	position: relative;
+	box-sizing: border-box;
+	overflow: hidden;
+	/* #endif */
+	
+	/* #ifndef MP */
+	@include vue-flex;
+	flex-wrap: wrap;
+	align-items: center;
+	/* #endif */
+}
+</style>

--
Gitblit v1.9.3