123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- <template>
- <view
- class="u-card"
- @tap.stop="click"
- :class="{ 'u-border': border, 'u-card-full': full, 'u-card--border': borderRadius > 0 }"
- :style="{
- borderRadius: borderRadius + 'rpx',
- margin: margin,
- boxShadow: boxShadow
- }"
- >
- <view
- v-if="showHead"
- class="u-card__head"
- :style="[{padding: padding + 'rpx'}, headStyle]"
- :class="{
- 'u-border-bottom': headBorderBottom
- }"
- @tap="headClick"
- >
- <view v-if="!$slots.head" class="u-flex u-row-between">
- <view class="u-card__head--left u-flex u-line-1" v-if="title">
- <image
- :src="thumb"
- class="u-card__head--left__thumb"
- mode="aspectfull"
- v-if="thumb"
- :style="{
- height: thumbWidth + 'rpx',
- width: thumbWidth + 'rpx',
- borderRadius: thumbCircle ? '100rpx' : '6rpx'
- }"
- ></image>
- <text
- class="u-card__head--left__title u-line-1"
- :style="{
- fontSize: titleSize + 'rpx',
- color: titleColor
- }"
- >
- {{ title }}
- </text>
- </view>
- <view class="u-card__head--right u-line-1" v-if="subTitle">
- <text
- class="u-card__head__title__text"
- :style="{
- fontSize: subTitleSize + 'rpx',
- color: subTitleColor
- }"
- >
- {{ subTitle }}
- </text>
- </view>
- </view>
- <slot name="head" v-else />
- </view>
- <view @tap="bodyClick" class="u-card__body" :style="[{padding: padding + 'rpx'}, bodyStyle]"><slot name="body" /></view>
- <view
- v-if="showFoot"
- class="u-card__foot"
- @tap="footClick"
- :style="[{padding: $slots.foot ? padding + 'rpx' : 0}, footStyle]"
- :class="{
- 'u-border-top': footBorderTop
- }"
- >
- <slot name="foot" />
- </view>
- </view>
- </template>
- <script>
- export default {
- name: 'u-card',
- props: {
-
- full: {
- type: Boolean,
- default: false
- },
-
- title: {
- type: String,
- default: ''
- },
-
- titleColor: {
- type: String,
- default: '#303133'
- },
-
- titleSize: {
- type: [Number, String],
- default: '30'
- },
-
- subTitle: {
- type: String,
- default: ''
- },
-
- subTitleColor: {
- type: String,
- default: '#909399'
- },
-
- subTitleSize: {
- type: [Number, String],
- default: '26'
- },
-
- border: {
- type: Boolean,
- default: true
- },
-
- index: {
- type: [Number, String, Object],
- default: ''
- },
-
- margin: {
- type: String,
- default: '30rpx'
- },
-
- borderRadius: {
- type: [Number, String],
- default: '16'
- },
-
- headStyle: {
- type: Object,
- default() {
- return {};
- }
- },
-
- bodyStyle: {
- type: Object,
- default() {
- return {};
- }
- },
-
- footStyle: {
- type: Object,
- default() {
- return {};
- }
- },
-
- headBorderBottom: {
- type: Boolean,
- default: true
- },
-
- footBorderTop: {
- type: Boolean,
- default: true
- },
-
- thumb: {
- type: String,
- default: ''
- },
-
- thumbWidth: {
- type: [String, Number],
- default: '60'
- },
-
- thumbCircle: {
- type: Boolean,
- default: false
- },
-
- padding: {
- type: [String, Number],
- default: '30'
- },
-
- showHead: {
- type: Boolean,
- default: true
- },
-
- showFoot: {
- type: Boolean,
- default: true
- },
-
- boxShadow: {
- type: String,
- default: 'none'
- }
- },
- data() {
- return {};
- },
- methods: {
- click() {
- this.$emit('click', this.index);
- },
- headClick() {
- this.$emit('head-click', this.index);
- },
- bodyClick() {
- this.$emit('body-click', this.index);
- },
- footClick() {
- this.$emit('foot-click', this.index);
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- @import "../../libs/css/style.components.scss";
-
- .u-card {
- position: relative;
- overflow: hidden;
- font-size: 28rpx;
- background-color: #ffffff;
- box-sizing: border-box;
-
- &-full {
- // 如果是与屏幕之间不留空隙,应该设置左右边距为0
- margin-left: 0 !important;
- margin-right: 0 !important;
- width: 100%;
- }
-
- &--border:after {
- border-radius: 16rpx;
- }
- &__head {
- &--left {
- color: $u-main-color;
-
- &__thumb {
- margin-right: 16rpx;
- }
-
- &__title {
- max-width: 400rpx;
- }
- }
- &--right {
- color: $u-tips-color;
- margin-left: 6rpx;
- }
- }
- &__body {
- color: $u-content-color;
- }
- &__foot {
- color: $u-tips-color;
- }
- }
- </style>
|