From 3ae8a654aff7764b80bf53665c0de4c9de0e33fa Mon Sep 17 00:00:00 2001 From: anlyyao Date: Sun, 4 Feb 2024 15:58:29 +0800 Subject: [PATCH 1/3] feat: leftIcon and rightIcon attributes support object type --- src/cell/README.md | 8 +++---- .../__test__/__snapshots__/index.test.js.snap | 19 +-------------- src/cell/cell.ts | 17 ++++++++++++++ src/cell/cell.wxml | 23 +++++++++++-------- src/cell/props.ts | 6 ++--- src/cell/type.ts | 12 +++++----- 6 files changed, 45 insertions(+), 40 deletions(-) diff --git a/src/cell/README.md b/src/cell/README.md index 188ebad1e..5ed4f3641 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 | 是否显示右侧箭头。值为字符串表示图标名称,值为 `Object` 类型,表示透传至 `icon`。 | 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 | - | 左侧图标,出现在单元格标题的左侧。值为字符串表示图标名称,值为 `Object` 类型,表示透传至 `icon`。 | N note | String / Slot | - | 和标题同行的说明文字 | N required | Boolean | false | 是否显示表单必填星号 | N -right-icon | String / Slot | - | 最右侧图标 | N +right-icon | String / Object / Slot | - | 最右侧图标。值为字符串表示图标名称,值为 `Object` 类型,表示透传至 `icon`。 | 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..b5d38459b 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,22 @@ export default class Cell extends SuperComponent { isLastChild: false, }; + lifetimes = { + ready() { + const { leftIcon, rightIcon, arrow } = this.properties; + this.setIcon('_leftIcon', leftIcon, ''); + this.setIcon('_rightIcon', rightIcon, ''); + this.setIcon('_arrow', arrow, '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 @@ + - - - +