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-col/u-col.vue | 162 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 162 insertions(+), 0 deletions(-) diff --git a/uni_modules/uview-ui/components/u-col/u-col.vue b/uni_modules/uview-ui/components/u-col/u-col.vue new file mode 100644 index 0000000..8be1517 --- /dev/null +++ b/uni_modules/uview-ui/components/u-col/u-col.vue @@ -0,0 +1,162 @@ +<template> + <view + class="u-col" + ref="u-col" + :class="[ + 'u-col-' + span + ]" + :style="[colStyle]" + @tap="clickHandler" + > + <slot></slot> + </view> +</template> + +<script> + import props from './props.js'; + /** + * CodeInput 鏍呮牸绯荤粺鐨勫垪 + * @description 璇ョ粍浠朵竴鑸敤浜嶭ayout 甯冨眬 閫氳繃鍩虹鐨� 12 鍒嗘爮锛岃繀閫熺畝渚垮湴鍒涘缓甯冨眬 + * @tutorial https://www.uviewui.com/components/Layout.html + * @property {String | Number} span 鏍呮牸鍗犳嵁鐨勫垪鏁帮紝鎬�12绛変唤 (榛樿 12 ) + * @property {String | Number} offset 鍒嗘爮宸﹁竟鍋忕Щ锛岃绠楁柟寮忎笌span鐩稿悓 (榛樿 0 ) + * @property {String} justify 姘村钩鎺掑垪鏂瑰紡锛屽彲閫夊�间负`start`(鎴朻flex-start`)銆乣end`(鎴朻flex-end`)銆乣center`銆乣around`(鎴朻space-around`)銆乣between`(鎴朻space-between`) (榛樿 'start' ) + * @property {String} align 鍨傜洿瀵归綈鏂瑰紡锛屽彲閫夊�间负top銆乧enter銆乥ottom銆乻tretch (榛樿 'stretch' ) + * @property {String} textAlign 鏂囧瓧姘村钩瀵归綈鏂瑰紡 (榛樿 'left' ) + * @property {Object} customStyle 瀹氫箟闇�瑕佺敤鍒扮殑澶栭儴鏍峰紡 + * @event {Function} click col琚偣鍑伙紝浼氶樆姝簨浠跺啋娉″埌row + * @example <u-col span="3" offset="3" > <view class="demo-layout bg-purple"></view> </u-col> + */ + export default { + name: 'u-col', + mixins: [uni.$u.mpMixin, uni.$u.mixin, props], + data() { + return { + width: 0, + parentData: { + gutter: 0 + }, + gridNum: 12 + } + }, + computed: { + uJustify() { + if (this.justify == 'end' || this.justify == 'start') return 'flex-' + this.justify + else if (this.justify == 'around' || this.justify == 'between') return 'space-' + this.justify + else return this.justify + }, + uAlignItem() { + if (this.align == 'top') return 'flex-start' + if (this.align == 'bottom') return 'flex-end' + else return this.align + }, + colStyle() { + const style = { + // 杩欓噷鍐欐垚"padding: 0 10px"鐨勫舰寮忔槸鍥犱负nvue鐨勯渶瑕� + paddingLeft: uni.$u.addUnit(uni.$u.getPx(this.parentData.gutter)/2), + paddingRight: uni.$u.addUnit(uni.$u.getPx(this.parentData.gutter)/2), + alignItems: this.uAlignItem, + justifyContent: this.uJustify, + textAlign: this.textAlign, + // #ifndef APP-NVUE + // 鍦ㄩ潪nvue涓婏紝浣跨敤鐧惧垎姣斿舰寮� + flex: `0 0 ${100 / this.gridNum * this.span}%`, + marginLeft: 100 / 12 * this.offset + '%', + // #endif + // #ifdef APP-NVUE + // 鍦╪vue涓婏紝鐢变簬鏃犳硶浣跨敤鐧惧垎姣斿崟浣嶏紝杩欓噷闇�瑕佽幏鍙栫埗缁勪欢鐨勫搴︼紝鍐嶈绠楀緱鍑鸿鏈夊搴旂殑鐧惧垎姣斿昂瀵� + width: uni.$u.addUnit(Math.floor(this.width / this.gridNum * Number(this.span))), + marginLeft: uni.$u.addUnit(Math.floor(this.width / this.gridNum * Number(this.offset))), + // #endif + } + return uni.$u.deepMerge(style, uni.$u.addStyle(this.customStyle)) + } + }, + mounted() { + this.init() + }, + methods: { + async init() { + // 鏀粯瀹濆皬绋嬪簭涓嶆敮鎸乸rovide/inject锛屾墍浠ヤ娇鐢ㄨ繖涓柟娉曡幏鍙栨暣涓埗缁勪欢锛屽湪created瀹氫箟锛岄伩鍏嶅惊鐜紩鐢� + this.updateParentData() + this.width = await this.parent.getComponentWidth() + }, + updateParentData() { + this.getParentData('u-row') + }, + clickHandler(e) { + this.$emit('click'); + } + }, + } +</script> + +<style lang="scss" scoped> + @import "../../libs/css/components.scss"; + + .u-col { + padding: 0; + /* #ifndef APP-NVUE */ + box-sizing:border-box; + /* #endif */ + /* #ifdef MP */ + display: block; + /* #endif */ + } + + // nvue涓嬬櫨鍒嗘瘮鏃犳晥 + /* #ifndef APP-NVUE */ + .u-col-0 { + width: 0; + } + + .u-col-1 { + width: calc(100%/12); + } + + .u-col-2 { + width: calc(100%/12 * 2); + } + + .u-col-3 { + width: calc(100%/12 * 3); + } + + .u-col-4 { + width: calc(100%/12 * 4); + } + + .u-col-5 { + width: calc(100%/12 * 5); + } + + .u-col-6 { + width: calc(100%/12 * 6); + } + + .u-col-7 { + width: calc(100%/12 * 7); + } + + .u-col-8 { + width: calc(100%/12 * 8); + } + + .u-col-9 { + width: calc(100%/12 * 9); + } + + .u-col-10 { + width: calc(100%/12 * 10); + } + + .u-col-11 { + width: calc(100%/12 * 11); + } + + .u-col-12 { + width: calc(100%/12 * 12); + } + + /* #endif */ +</style> -- Gitblit v1.9.3