From 0f49866541e724797804e4a512c91739c5b01960 Mon Sep 17 00:00:00 2001 From: Y Date: Mon, 5 Feb 2024 15:58:39 +0800 Subject: [PATCH] feat(Cell): leftIcon and rightIcon attributes support object type (#2589) * feat: leftIcon and rightIcon attributes support object type * test: update snapshots * feat(Cell): support observers --- src/cell/README.md | 8 +++---- .../__test__/__snapshots__/index.test.js.snap | 19 +-------------- src/cell/cell.ts | 20 ++++++++++++++++ src/cell/cell.wxml | 23 +++++++++++-------- src/cell/props.ts | 6 ++--- src/cell/type.ts | 12 +++++----- .../__test__/__snapshots__/index.test.js.snap | 4 ++++ 7 files changed, 52 insertions(+), 40 deletions(-) diff --git a/src/cell/README.md b/src/cell/README.md index 188ebad1e..f6c0769f3 100644 --- a/src/cell/README.md +++ b/src/cell/README.md @@ -44,16 +44,16 @@ isComponent: true 名称 | 类型 | 默认值 | 说明 | 必传 -- | -- | -- | -- | -- align | String | middle | 内容的对齐方式,默认居中对齐。可选项:top/middle/bottom | N -arrow | Boolean | false | 是否显示右侧箭头 | N -bordered | Boolean | true | 是否显示下边框 | N +arrow | Boolean / Object | false | 是否显示右侧箭头 | N +bordered | Boolean| true | 是否显示下边框 | N description | String / Slot | - | 下方内容描述 | N hover | Boolean | - | 是否开启点击反馈 | N image | String / Slot | - | 主图 | N jump-type | String | navigateTo | 链接跳转类型。可选项:switchTab/reLaunch/redirectTo/navigateTo | N -left-icon | String / Slot | - | 左侧图标,出现在单元格标题的左侧 | N +left-icon | String / Object / Slot | - | 左侧图标,出现在单元格标题的左侧 | N note | String / Slot | - | 和标题同行的说明文字 | N required | Boolean | false | 是否显示表单必填星号 | N -right-icon | String / Slot | - | 最右侧图标 | N +right-icon | String / Object / Slot | - | 最右侧图标 | N title | String / Slot | - | 标题 | N url | String | - | 点击后跳转链接地址。如果值为空,则表示不需要跳转 | N diff --git a/src/cell/__test__/__snapshots__/index.test.js.snap b/src/cell/__test__/__snapshots__/index.test.js.snap index e3787862d..99f2b3dbb 100644 --- a/src/cell/__test__/__snapshots__/index.test.js.snap +++ b/src/cell/__test__/__snapshots__/index.test.js.snap @@ -32,24 +32,7 @@ exports[`cell :base 1`] = ` /> - - - - - - + /> diff --git a/src/cell/cell.ts b/src/cell/cell.ts index 08b5427f2..b94b731c1 100644 --- a/src/cell/cell.ts +++ b/src/cell/cell.ts @@ -1,6 +1,7 @@ import { SuperComponent, wxComponent, RelationsOptions } from '../common/src/index'; import config from '../common/config'; import props from './props'; +import { calcIcon } from '../common/utils'; const { prefix } = config; const name = `${prefix}-cell`; @@ -39,6 +40,25 @@ export default class Cell extends SuperComponent { isLastChild: false, }; + observers = { + leftIcon(v) { + this.setIcon('_leftIcon', v, ''); + }, + rightIcon(v) { + this.setIcon('_rightIcon', v, ''); + }, + arrow(v) { + this.setIcon('_arrow', v, 'chevron-right'); + }, + }; + + setIcon(name, value, defaultValue) { + if (!value) return; + this.setData({ + [name]: calcIcon(value, defaultValue), + }); + } + onClick(e) { this.triggerEvent('click', e.detail); this.jumpLink(); diff --git a/src/cell/cell.wxml b/src/cell/cell.wxml index 31b9a6092..c65c9a671 100644 --- a/src/cell/cell.wxml +++ b/src/cell/cell.wxml @@ -1,3 +1,4 @@ + - - - +