From 1e25e542275a6f5c8bfc70047e4d6ab242ff5e96 Mon Sep 17 00:00:00 2001 From: yangjinfeng Date: Fri, 13 Jul 2018 16:36:10 +0800 Subject: [PATCH] =?UTF-8?q?cell-group=E6=B7=BB=E5=8A=A0titleWidth=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E6=95=B4=E4=BD=93=E6=8E=A7=E5=88=B6title=E5=8C=BA?= =?UTF-8?q?=E5=9F=9F=E5=AE=BD=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/cell-group/index.js | 9 +++++++++ packages/cell/README.md | 3 ++- packages/cell/index.js | 10 +++++++++- packages/cell/index.wxml | 2 +- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/packages/cell-group/index.js b/packages/cell-group/index.js index ea805902..19150663 100644 --- a/packages/cell-group/index.js +++ b/packages/cell-group/index.js @@ -2,6 +2,12 @@ const CELL_PATH = '../cell/index'; const FIELD_PATH = '../field/index' Component({ + properties: { + titleWidth: { + type: Number, + value: null + } + }, relations: { [CELL_PATH]: { type: 'child', @@ -43,10 +49,13 @@ Component({ const elementUpdateTimeout = setTimeout(() => { this.setData({ elementUpdateTimeout: 0 }); let elements = this.getRelationNodes(childPath); + const { titleWidth } = this.properties; + if (elements.length > 0) { let lastIndex = elements.length - 1; elements.forEach((cell, index) => { + titleWidth && cell.setTitleWidth(titleWidth) cell.updateIsLastElement(index === lastIndex); }); } diff --git a/packages/cell/README.md b/packages/cell/README.md index 51ab8e4a..5113c3a7 100644 --- a/packages/cell/README.md +++ b/packages/cell/README.md @@ -27,8 +27,9 @@ } ``` +`cell-group`提供`title-width`控制组内整体 cell 的 title 区域宽度 ```wxml - + diff --git a/packages/cell/index.js b/packages/cell/index.js index 132515ce..25151ac8 100644 --- a/packages/cell/index.js +++ b/packages/cell/index.js @@ -46,7 +46,8 @@ Component({ } }, data: { - isLastCell: true + isLastCell: true, + titleWidth: 'auto' }, methods: { footerTap() { @@ -72,6 +73,13 @@ Component({ // 用于被 cell-group 更新,标志是否是最后一个 cell updateIsLastElement(isLastCell) { this.setData({ isLastCell }); + }, + + // 设置统一的title区域宽度 + setTitleWidth(titleWidth) { + this.setData({ + titleWidth: `${titleWidth}px` + }); } } }); diff --git a/packages/cell/index.wxml b/packages/cell/index.wxml index 9dd83c03..db6db63d 100644 --- a/packages/cell/index.wxml +++ b/packages/cell/index.wxml @@ -7,7 +7,7 @@ - + {{ title }} {{ label }}