Skip to content

Commit 8b25687

Browse files
committed
fix: 使 AtGridItem 支持自定义字段 close #983
1 parent 7c47959 commit 8b25687

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

src/pages/layout/grid/index.tsx

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,16 @@
1-
import { AtGrid } from 'taro-ui';
2-
import { AtIconProps } from 'types/icon';
3-
4-
import { View } from '@tarojs/components';
5-
import Taro from '@tarojs/taro';
6-
7-
import DocsHeader from '../../components/doc-header';
1+
import { AtGrid } from 'taro-ui'
2+
import { AtGridItem } from 'types/grid'
3+
import { View } from '@tarojs/components'
4+
import Taro from '@tarojs/taro'
5+
import DocsHeader from '../../components/doc-header'
86
import './index.scss'
97

10-
type DataItem = {
11-
value: string
12-
image?: string
13-
iconInfo?: AtIconProps
14-
}
15-
168
interface GridPageState {
17-
data: DataItem[]
9+
data: AtGridItem[]
1810
}
1911

2012
export default class GridPage extends Taro.Component<{}, GridPageState> {
21-
public config: Taro.PageConfig = {
22-
navigationBarTitleText: 'Taro UI'
23-
}
24-
25-
public constructor () {
13+
public constructor() {
2614
super(...arguments)
2715
this.state = {
2816
data: [
@@ -57,17 +45,26 @@ export default class GridPage extends Taro.Component<{}, GridPageState> {
5745
size: 30,
5846
color: 'red',
5947
value: 'bookmark'
60-
}
48+
},
49+
url: '支持自定义字段'
6150
}
6251
]
6352
}
6453
}
6554

66-
private handleClick = (value: DataItem, index: number): void => {
67-
console.log(value, index)
55+
public config: Taro.PageConfig = {
56+
navigationBarTitleText: 'Taro UI'
57+
}
58+
59+
private handleClick = (value: AtGridItem, index: number): void => {
60+
Taro.showModal({
61+
title: '提示',
62+
content: `Value: ${value}, Index: ${index}`,
63+
showCancel: false
64+
})
6865
}
6966

70-
public render (): JSX.Element {
67+
public render(): JSX.Element {
7168
return (
7269
<View className='page'>
7370
<DocsHeader title='Grid 栅格' />

types/grid.d.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { MouseEvent, ComponentClass } from 'react'
1+
import { ComponentClass } from 'react'
22
import { CommonEvent } from '@tarojs/components/types/common'
3-
43
import AtComponent, { AtIconBaseProps } from './base'
54

6-
export interface Item {
5+
export interface AtGridItem {
76
/**
87
* 宫格图片
98
*/
@@ -16,13 +15,17 @@ export interface Item {
1615
* 宫格图标
1716
*/
1817
iconInfo?: AtIconBaseProps
18+
/**
19+
* 允许用户扩充 Item 字段
20+
*/
21+
[key: string]: any
1922
}
2023

2124
export interface AtGridProps extends AtComponent {
2225
/**
2326
* 宫格布局数据源
2427
*/
25-
data: Array<Item>
28+
data: Array<AtGridItem>
2629
/**
2730
* 每一列有多少个
2831
*/
@@ -40,7 +43,7 @@ export interface AtGridProps extends AtComponent {
4043
/**
4144
* 点击宫格触发的事件
4245
*/
43-
onClick?: (item: Item, index: number, event: CommonEvent) => void
46+
onClick?: (item: AtGridItem, index: number, event: CommonEvent) => void
4447
}
4548

4649
declare const AtGrid: ComponentClass<AtGridProps>

0 commit comments

Comments
 (0)