Skip to content

Commit 589d153

Browse files
anlyyaotdesign-botliweijie0812
authored
feat(TabbarItem): support url and linkType props (#4523)
* feat(TabbarItem): support url and linkType props * chore: stash changelog [ci skip] * docs: sync api doc --------- Co-authored-by: tdesign-bot <tdesign@tencent.com> Co-authored-by: 黎伟杰 <674416404@qq.com>
1 parent b0912d6 commit 589d153

6 files changed

Lines changed: 46 additions & 6 deletions

File tree

packages/components/tab-bar-item/props.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,20 @@ const props: TdTabBarItemProps = {
1414
icon: {
1515
type: null,
1616
},
17+
/** 页面跳转类型 */
18+
linkType: {
19+
type: String,
20+
value: 'redirectTo',
21+
},
1722
/** 二级菜单 */
1823
subTabBar: {
1924
type: Array,
2025
},
26+
/** 点击后跳转的页面路径, 需要以 `/` 开头 */
27+
url: {
28+
type: String,
29+
value: '',
30+
},
2131
/** 标识符 */
2232
value: {
2333
type: null,

packages/components/tab-bar-item/tab-bar-item.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export default class TabBarItem extends SuperComponent {
7777
});
7878
},
7979
toggle() {
80-
const { currentName, hasChildren, isSpread } = this.data;
80+
const { currentName, hasChildren, isSpread, url, linkType } = this.data;
8181

8282
if (hasChildren) {
8383
this.setData({
@@ -86,6 +86,10 @@ export default class TabBarItem extends SuperComponent {
8686
}
8787
this.$parent.updateValue(currentName);
8888
this.$parent.changeOtherSpread(currentName);
89+
90+
if (url && wx[linkType]) {
91+
wx[linkType]({ url });
92+
}
8993
},
9094
selectChild(event) {
9195
const { value } = event.target.dataset;

packages/components/tab-bar-item/type.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,29 @@ export interface TdTabBarItemProps {
2121
type: null;
2222
value?: string | object;
2323
};
24+
/**
25+
* 页面跳转类型
26+
* @default redirectTo
27+
*/
28+
linkType?: {
29+
type: StringConstructor;
30+
value?: 'redirectTo' | 'switchTab' | 'reLaunch' | 'navigateTo';
31+
};
2432
/**
2533
* 二级菜单
2634
*/
2735
subTabBar?: {
2836
type: ArrayConstructor;
2937
value?: SubTabBarItem[];
3038
};
39+
/**
40+
* 点击后跳转的页面路径, 需要以 `/` 开头
41+
* @default ''
42+
*/
43+
url?: {
44+
type: StringConstructor;
45+
value?: string;
46+
};
3147
/**
3248
* 标识符
3349
*/

packages/components/tab-bar/README.en-US.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ split | Boolean | true | \- | N
1717
theme | String | normal | options: normal/tag | N
1818
value | String / Number / Array | - | Typescript: `string \| number \| Array<string \| number>` | N
1919
default-value | String / Number / Array | undefined | uncontrolled property。Typescript: `string \| number \| Array<string \| number>` | N
20-
z-index | Number | 1 | \- | N
20+
z-index | Number | 1 | `1.12.1` | N
2121

2222
### TabBar Events
2323

2424
name | params | description
2525
-- | -- | --
26-
change | `(value: string \| number)` | \-
26+
change | `(detail: { value: string \| number })` | \-
2727

2828
### TabBar External Classes
2929

@@ -40,7 +40,9 @@ style | Object | - | CSS(Cascading Style Sheets) | N
4040
custom-style | Object | - | CSS(Cascading Style Sheets),used to set style on virtual component | N
4141
badge-props | Object | - | Typescript: `BadgeProps`[Badge API Documents](./badge?tab=api)[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/tab-bar-item/type.ts) | N
4242
icon | String / Object | - | \- | N
43+
link-type | String | redirectTo | `1.15.2`。options: redirectTo/switchTab/reLaunch/navigateTo | N
4344
sub-tab-bar | Array | - | Typescript: `SubTabBarItem[] ` `interface SubTabBarItem { value: string; label: string }`[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/tab-bar-item/type.ts) | N
45+
url | String | - | `1.15.2` | N
4446
value | String / Number | - | \- | N
4547

4648
### TabBarItem Slots

packages/components/tab-bar/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ split | Boolean | true | 是否需要分割线 | N
7474
theme | String | normal | 选项风格。可选项:normal/tag | N
7575
value | String / Number / Array | - | 当前选中标签的索引。TS 类型:`string \| number \| Array<string \| number>` | N
7676
default-value | String / Number / Array | undefined | 当前选中标签的索引。非受控属性。TS 类型:`string \| number \| Array<string \| number>` | N
77-
z-index | Number | 1 | 标签栏层级 | N
77+
z-index | Number | 1 | `1.12.1`标签栏层级 | N
7878

7979
### TabBar Events
8080

8181
名称 | 参数 | 描述
8282
-- | -- | --
83-
change | `(value: string \| number)` | 选中标签切换时触发
83+
change | `(detail: { value: string \| number })` | 选中标签切换时触发
8484

8585
### TabBar External Classes
8686

@@ -97,14 +97,16 @@ style | Object | - | 样式 | N
9797
custom-style | Object | - | 样式,一般用于开启虚拟化组件节点场景 | N
9898
badge-props | Object | - | 图标右上角提示信息。TS 类型:`BadgeProps`[Badge API Documents](./badge?tab=api)[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/tab-bar-item/type.ts) | N
9999
icon | String / Object | - | 图标名称。传入对象时透传至 Icon 组件 | N
100+
link-type | String | redirectTo | `1.15.2`。页面跳转类型。可选项:redirectTo/switchTab/reLaunch/navigateTo | N
100101
sub-tab-bar | Array | - | 二级菜单。TS 类型:`SubTabBarItem[] ` `interface SubTabBarItem { value: string; label: string }`[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/components/tab-bar-item/type.ts) | N
102+
url | String | - | `1.15.2`。点击后跳转的页面路径, 需要以 `/` 开头 | N
101103
value | String / Number | - | 标识符 | N
102104

103105
### TabBarItem Slots
104106

105107
名称 | 描述
106108
-- | --
107-
icon | 图标插槽,用于自定义图标区域内容
109+
icon | 自定义 `icon` 显示内容
108110

109111
### CSS Variables
110112

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
pr_number: 4523
3+
contributor: anlyyao
4+
---
5+
6+
- feat(TabbarItem): 新增 `url``linkType` 属性 @anlyyao ([#4523](https://github.com/Tencent/tdesign-miniprogram/pull/4523))

0 commit comments

Comments
 (0)