¶Ô±ÈÐÂÎļþ |
| | |
| | | <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 该ç»ä»¶ä¸è¬ç¨äºLayout å¸å± éè¿åºç¡ç 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ãcenterãbottomãstretch (é»è®¤ '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 |
| | | // å¨nvueä¸ï¼ç±äºæ æ³ä½¿ç¨ç¾åæ¯åä½ï¼è¿ééè¦è·åç¶ç»ä»¶ç宽度ï¼å计ç®å¾åºè¯¥æå¯¹åºçç¾åæ¯å°ºå¯¸ |
| | | 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() { |
| | | // æ¯ä»å®å°ç¨åºä¸æ¯æprovide/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> |