Skip to content
This repository was archived by the owner on Oct 27, 2021. It is now read-only.

Commit dea1d1a

Browse files
author
pengshanglong
committed
feat: add Card
1 parent 2a4b68c commit dea1d1a

File tree

3 files changed

+117
-2
lines changed

3 files changed

+117
-2
lines changed

src/components/card/index.jsx

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import classNames from 'classnames'
2+
3+
export default {
4+
name: 'Card',
5+
props: {
6+
note: {
7+
type: String,
8+
default: '',
9+
},
10+
isFull: {
11+
type: Boolean,
12+
default: false,
13+
},
14+
thumb: {
15+
type: String,
16+
default: '',
17+
},
18+
title: {
19+
type: String,
20+
default: '',
21+
},
22+
extra: {
23+
type: String,
24+
default: '',
25+
},
26+
icon: {
27+
type: Object,
28+
default: () => {},
29+
},
30+
onClick: {
31+
type: Function,
32+
default: () => () => {},
33+
},
34+
renderIcon: {
35+
type: String,
36+
default: '',
37+
},
38+
extraStyle: {
39+
type: Object,
40+
default: () => {},
41+
},
42+
className: {
43+
type: [String, Array],
44+
default: '',
45+
},
46+
},
47+
methods: {
48+
handleClick(args) {
49+
if (typeof this.onClick === 'function') {
50+
this.onClick(args)
51+
}
52+
},
53+
},
54+
render() {
55+
const { title, note, extra, extraStyle, thumb, isFull, icon, renderIcon } = this
56+
57+
const rootClass = classNames(
58+
'at-card',
59+
{
60+
'at-card--full': isFull,
61+
},
62+
this.className
63+
)
64+
const iconClass = classNames({
65+
'at-icon': true,
66+
[`at-icon-${icon && icon.value}`]: icon && icon.value,
67+
'at-card__header-icon': true,
68+
})
69+
70+
const iconStyle = {
71+
color: (icon && icon.color) || '',
72+
fontSize: (icon && `${icon.size}px`) || '',
73+
}
74+
75+
return (
76+
<view onClick={this.handleClick} class={rootClass}>
77+
<view class="at-card__header">
78+
{thumb && (
79+
<view class="at-card__header-thumb">
80+
<image class="at-card__header-thumb-info" mode="scaleToFill" src={thumb} />
81+
</view>
82+
)}
83+
{renderIcon || this.$slots.renderIcon || ''}
84+
{!thumb && icon && icon.value && <view class={iconClass} style={iconStyle}></view>}
85+
86+
<view class="at-card__header-title">{title}</view>
87+
{extra && (
88+
<view style={{ ...extraStyle }} class="at-card__header-extra">
89+
{extra}
90+
</view>
91+
)}
92+
</view>
93+
<view class="at-card__content">
94+
<view class="at-card__content-info">{this.$slots.default}</view>
95+
{note && <view class="at-card__content-note">{note}</view>}
96+
</view>
97+
</view>
98+
)
99+
},
100+
}

src/components/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Grid from './grid/index'
22
import List from './list/index'
33
import ListItem from './list/item/index'
4+
import Card from './card/index'
45

5-
export { Grid, List, ListItem }
6+
export { Grid, List, ListItem, Card }

src/pages/index/index.vue

+15-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22
<view
33
class="index"
44
>
5+
<Card
6+
note="小Tips"
7+
extra="额外信息"
8+
title="这是个标题"
9+
thumb="http://img10.360buyimg.com/jdphoto/s72x72_jfs/t5872/209/5240187906/2872/8fa98cd/595c3b2aN4155b931.png"
10+
>
11+
<Icon
12+
slot="renderIcon"
13+
value="bell"
14+
/>
15+
这也是内容区 可以随意定义功能
16+
</Card>
517
<List>
618
<ListItem
719
title="标题文字"
@@ -171,6 +183,7 @@
171183
font-color="#2d8cf0"
172184
line-color="#2d8cf0"
173185
/>
186+
</card>
174187
</view>
175188
</template>
176189

@@ -198,7 +211,7 @@ import ModalAction from '../../components/modal/action/index.jsx'
198211
import Toast from '../../components/toast/index.jsx'
199212
import SwipeAction from '../../components/swipe-action/index.jsx'
200213
import Message from '../../components/message/index.jsx'
201-
import { Grid, List, ListItem } from '../../components/index'
214+
import { Grid, List, ListItem, Card } from '../../components/index'
202215
203216
export default {
204217
name: 'Index',
@@ -228,6 +241,7 @@ export default {
228241
Grid,
229242
List,
230243
ListItem,
244+
Card,
231245
},
232246
data() {
233247
return {

0 commit comments

Comments
 (0)