uni-card.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <template>
  2. <view class="uni-card" :class="{ 'uni-card--full': isFull, 'uni-card--shadow': isShadow,'uni-card--border':border}"
  3. :style="{'margin':isFull?0:margin,'padding':spacing,'box-shadow':isShadow?shadow:''}">
  4. <!-- 封面 -->
  5. <slot name="cover">
  6. <view v-if="cover" class="uni-card__cover">
  7. <image class="uni-card__cover-image" mode="widthFix" @click="onClick('cover')" :src="cover"></image>
  8. </view>
  9. </slot>
  10. <slot name="title">
  11. <view v-if="title || extra" class="uni-card__header">
  12. <!-- 卡片标题 -->
  13. <view class="uni-card__header-box" @click="onClick('title')">
  14. <view v-if="thumbnail" class="uni-card__header-avatar">
  15. <image class="uni-card__header-avatar-image" :src="thumbnail" mode="aspectFit" />
  16. </view>
  17. <view class="uni-card__header-content">
  18. <text class="uni-card__header-content-title uni-ellipsis">{{ title }}</text>
  19. <text v-if="title&&subTitle"
  20. class="uni-card__header-content-subtitle uni-ellipsis">{{ subTitle }}</text>
  21. </view>
  22. </view>
  23. <view class="uni-card__header-extra" @click="onClick('extra')">
  24. <text class="uni-card__header-extra-text">{{ extra }}</text>
  25. </view>
  26. </view>
  27. </slot>
  28. <!-- 卡片内容 -->
  29. <view class="uni-card__content" :style="{padding:padding}" @click="onClick('content')">
  30. <slot></slot>
  31. </view>
  32. <view class="uni-card__actions" @click="onClick('actions')">
  33. <slot name="actions"></slot>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. /**
  39. * Card 卡片
  40. * @description 卡片视图组件
  41. * @tutorial https://ext.dcloud.net.cn/plugin?id=22
  42. * @property {String} title 标题文字
  43. * @property {String} subTitle 副标题
  44. * @property {Number} padding 内容内边距
  45. * @property {Number} margin 卡片外边距
  46. * @property {Number} spacing 卡片内边距
  47. * @property {String} extra 标题额外信息
  48. * @property {String} cover 封面图(本地路径需要引入)
  49. * @property {String} thumbnail 标题左侧缩略图
  50. * @property {Boolean} is-full = [true | false] 卡片内容是否通栏,为 true 时将去除padding值
  51. * @property {Boolean} is-shadow = [true | false] 卡片内容是否开启阴影
  52. * @property {String} shadow 卡片阴影
  53. * @property {Boolean} border 卡片边框
  54. * @event {Function} click 点击 Card 触发事件
  55. */
  56. export default {
  57. name: 'UniCard',
  58. emits: ['click'],
  59. props: {
  60. title: {
  61. type: String,
  62. default: ''
  63. },
  64. subTitle: {
  65. type: String,
  66. default: ''
  67. },
  68. padding: {
  69. type: String,
  70. default: '10px'
  71. },
  72. margin: {
  73. type: String,
  74. default: '15px'
  75. },
  76. spacing: {
  77. type: String,
  78. default: '0 10px'
  79. },
  80. extra: {
  81. type: String,
  82. default: ''
  83. },
  84. cover: {
  85. type: String,
  86. default: ''
  87. },
  88. thumbnail: {
  89. type: String,
  90. default: ''
  91. },
  92. isFull: {
  93. // 内容区域是否通栏
  94. type: Boolean,
  95. default: false
  96. },
  97. isShadow: {
  98. // 是否开启阴影
  99. type: Boolean,
  100. default: true
  101. },
  102. shadow: {
  103. type: String,
  104. default: '0px 0px 3px 1px rgba(0, 0, 0, 0.08)'
  105. },
  106. border: {
  107. type: Boolean,
  108. default: true
  109. }
  110. },
  111. methods: {
  112. onClick(type) {
  113. this.$emit('click', type)
  114. }
  115. }
  116. }
  117. </script>
  118. <style lang="scss">
  119. $uni-border-3: #EBEEF5 !default;
  120. $uni-shadow-base:0 0px 6px 1px rgba($color: #a5a5a5, $alpha: 0.2) !default;
  121. $uni-main-color: #3a3a3a !default;
  122. $uni-base-color: #6a6a6a !default;
  123. $uni-secondary-color: #909399 !default;
  124. $uni-spacing-sm: 8px !default;
  125. $uni-border-color:$uni-border-3;
  126. $uni-shadow: $uni-shadow-base;
  127. $uni-card-title: 15px;
  128. $uni-cart-title-color:$uni-main-color;
  129. $uni-card-subtitle: 12px;
  130. $uni-cart-subtitle-color:$uni-secondary-color;
  131. $uni-card-spacing: 10px;
  132. $uni-card-content-color: $uni-base-color;
  133. .uni-card {
  134. margin: $uni-card-spacing;
  135. padding: 0 $uni-spacing-sm;
  136. border-radius: 4px;
  137. overflow: hidden;
  138. font-family: Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, SimSun, sans-serif;
  139. background-color: #fff;
  140. flex: 1;
  141. .uni-card__cover {
  142. position: relative;
  143. margin-top: $uni-card-spacing;
  144. flex-direction: row;
  145. overflow: hidden;
  146. border-radius: 4px;
  147. .uni-card__cover-image {
  148. flex: 1;
  149. // width: 100%;
  150. /* #ifndef APP-PLUS */
  151. vertical-align: middle;
  152. /* #endif */
  153. }
  154. }
  155. .uni-card__header {
  156. display: flex;
  157. border-bottom: 1px $uni-border-color solid;
  158. flex-direction: row;
  159. align-items: center;
  160. padding: $uni-card-spacing;
  161. overflow: hidden;
  162. .uni-card__header-box {
  163. /* #ifndef APP-NVUE */
  164. display: flex;
  165. /* #endif */
  166. flex: 1;
  167. flex-direction: row;
  168. align-items: center;
  169. overflow: hidden;
  170. }
  171. .uni-card__header-avatar {
  172. width: 40px;
  173. height: 40px;
  174. overflow: hidden;
  175. border-radius: 5px;
  176. margin-right: $uni-card-spacing;
  177. .uni-card__header-avatar-image {
  178. flex: 1;
  179. width: 40px;
  180. height: 40px;
  181. }
  182. }
  183. .uni-card__header-content {
  184. /* #ifndef APP-NVUE */
  185. display: flex;
  186. /* #endif */
  187. flex-direction: column;
  188. justify-content: center;
  189. flex: 1;
  190. // height: 40px;
  191. overflow: hidden;
  192. .uni-card__header-content-title {
  193. font-size: $uni-card-title;
  194. color: $uni-cart-title-color;
  195. // line-height: 22px;
  196. }
  197. .uni-card__header-content-subtitle {
  198. font-size: $uni-card-subtitle;
  199. margin-top: 5px;
  200. color: $uni-cart-subtitle-color;
  201. }
  202. }
  203. .uni-card__header-extra {
  204. line-height: 12px;
  205. .uni-card__header-extra-text {
  206. font-size: 12px;
  207. color: $uni-cart-subtitle-color;
  208. }
  209. }
  210. }
  211. .uni-card__content {
  212. padding: $uni-card-spacing;
  213. font-size: 14px;
  214. color: $uni-card-content-color;
  215. line-height: 22px;
  216. }
  217. .uni-card__actions {
  218. font-size: 12px;
  219. }
  220. }
  221. .uni-card--border {
  222. border: 1px solid $uni-border-color;
  223. }
  224. .uni-card--shadow {
  225. position: relative;
  226. /* #ifndef APP-NVUE */
  227. box-shadow: $uni-shadow;
  228. /* #endif */
  229. }
  230. .uni-card--full {
  231. margin: 0;
  232. border-left-width: 0;
  233. border-left-width: 0;
  234. border-radius: 0;
  235. }
  236. /* #ifndef APP-NVUE */
  237. .uni-card--full:after {
  238. border-radius: 0;
  239. }
  240. /* #endif */
  241. .uni-ellipsis {
  242. /* #ifndef APP-NVUE */
  243. overflow: hidden;
  244. white-space: nowrap;
  245. text-overflow: ellipsis;
  246. /* #endif */
  247. /* #ifdef APP-NVUE */
  248. lines: 1;
  249. /* #endif */
  250. }
  251. </style>