uni-card.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <template>
  2. <view :class="{ 'uni-card--full': isFull === true || isFull === 'true', 'uni-card--shadow': isShadow === true || isShadow === 'true' }" class="uni-card" @click="onClick">
  3. <view v-if="mode === 'style'" class="uni-card__thumbnailimage">
  4. <view class="uni-card__thumbnailimage-box">
  5. <image class="uni-card__thumbnailimage-image" :src="thumbnail" mode="aspectFill" />
  6. </view>
  7. <view v-if="title" class="uni-card__thumbnailimage-title"><text class="uni-card__thumbnailimage-title-text">{{ title }}</text></view>
  8. </view>
  9. <view v-if="mode === 'title'" class="uni-card__title">
  10. <view class="uni-card__title-header">
  11. <image class="uni-card__title-header-image" :src="thumbnail" mode="scaleToFill" />
  12. </view>
  13. <view class="uni-card__title-content">
  14. <text class="uni-card__title-content-title">{{ title }}</text>
  15. <text class="uni-card__title-content-extra">{{ extra }}</text>
  16. </view>
  17. </view>
  18. <!-- 标题 -->
  19. <view v-if="mode === 'basic' && title" class="uni-card__header">
  20. <view v-if="thumbnail" class="uni-card__header-extra-img-view">
  21. <image :src="thumbnail" class="uni-card__header-extra-img" />
  22. </view>
  23. <text class="uni-card__header-title-text">{{ title }}</text>
  24. <text v-if="extra" class="uni-card__header-extra-text">{{ extra }}</text>
  25. </view>
  26. <!-- 内容 -->
  27. <view class="uni-card__content uni-card__content--pd">
  28. <view v-if="mode === 'style' && extra" class=""><text class="uni-card__content-extra">{{ extra }}</text></view>
  29. <slot />
  30. </view>
  31. <!-- 底部 -->
  32. <view v-if="note" class="uni-card__footer">
  33. <slot name="footer">
  34. <text class="uni-card__footer-text">{{ note }}</text>
  35. </slot>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. /**
  41. * Card 卡片
  42. * @description 卡片视图组件
  43. * @tutorial https://ext.dcloud.net.cn/plugin?id=22
  44. * @property {String} title 标题文字
  45. * @property {String} extra 标题额外信息
  46. * @property {String} note 标题左侧缩略图
  47. * @property {String} thumbnail 底部信息
  48. * @property {String} mode = [basic|style|title] 卡片模式
  49. * @value basic 基础卡片
  50. * @value style 图文卡片
  51. * @value title 标题卡片
  52. * @property {Boolean} isFull = [true | false] 卡片内容是否通栏,true 时将去除padding值
  53. * @property {Boolean} isShadow = [true | false] 卡片内容是否开启阴影
  54. * @event {Function} click 点击 Card 触发事件
  55. * @example <uni-card title="标题文字" thumbnail="https://img-cdn-qiniu.dcloud.net.cn/new-page/uni.png" extra="额外信息" note="Tips">内容主体,可自定义内容及样式</uni-card>
  56. */
  57. export default {
  58. name: 'UniCard',
  59. props: {
  60. title: {
  61. type: String,
  62. default: ''
  63. }, // 标题
  64. extra: {
  65. type: String,
  66. default: ''
  67. }, // 扩展信息
  68. note: {
  69. type: String,
  70. default: ''
  71. }, // Tips
  72. thumbnail: {
  73. type: String,
  74. default: ''
  75. }, // 缩略图
  76. // 卡片模式 , 可选值 basic:基础卡片 ;style :图文卡片 ; title :标题卡片
  77. mode: {
  78. type: String,
  79. default: 'basic'
  80. },
  81. isFull: {
  82. // 内容区域是否通栏
  83. type: Boolean,
  84. default: false
  85. },
  86. isShadow: {
  87. // 是否开启阴影
  88. type: Boolean,
  89. default: false
  90. }
  91. },
  92. methods: {
  93. onClick() {
  94. this.$emit('click')
  95. }
  96. }
  97. }
  98. </script>
  99. <style scoped>
  100. .uni-card {
  101. /* #ifndef APP-NVUE */
  102. display: flex;
  103. flex: 1;
  104. box-shadow: 0 0 0 rgba(0, 0, 0, 0);
  105. /* #endif */
  106. margin: 12px;
  107. background-color: #ffffff;
  108. position: relative;
  109. flex-direction: column;
  110. border-color: #e5e5e5;
  111. border-style: solid;
  112. border-width: 1px;
  113. border-radius: 3px;
  114. overflow: hidden;
  115. }
  116. .uni-card__thumbnailimage {
  117. position: relative;
  118. flex-direction: column;
  119. justify-content: center;
  120. height: 150px;
  121. overflow: hidden;
  122. }
  123. .uni-card__thumbnailimage-box {
  124. /* #ifndef APP-NVUE */
  125. display: flex;
  126. /* #endif */
  127. flex: 1;
  128. flex-direction: row;
  129. overflow: hidden;
  130. }
  131. .uni-card__thumbnailimage-image {
  132. flex: 1;
  133. }
  134. .uni-card__thumbnailimage-title {
  135. /* #ifndef APP-NVUE */
  136. display: flex;
  137. /* #endif */
  138. position: absolute;
  139. bottom: 0;
  140. left: 0;
  141. right: 0;
  142. flex-direction: row;
  143. padding: 16rpx 24rpx;
  144. background-color: rgba(0, 0, 0, 0.4);
  145. }
  146. .uni-card__thumbnailimage-title-text {
  147. flex: 1;
  148. font-size: 28rpx;
  149. color: #fff;
  150. }
  151. .uni-card__title {
  152. /* #ifndef APP-NVUE */
  153. display: flex;
  154. /* #endif */
  155. flex-direction: row;
  156. padding: 10px;
  157. border-bottom-color: #F5F5F5;
  158. border-bottom-style: solid;
  159. border-bottom-width: 1px;
  160. }
  161. .uni-card__title-header {
  162. width: 40px;
  163. height: 40px;
  164. overflow: hidden;
  165. border-radius: 5px;
  166. }
  167. .uni-card__title-header-image {
  168. width: 40px;
  169. height: 40px;
  170. }
  171. .uni-card__title-content {
  172. /* #ifndef APP-NVUE */
  173. display: flex;
  174. /* #endif */
  175. flex-direction: column;
  176. justify-content: center;
  177. padding-left: 10px;
  178. height: 40px;
  179. overflow: hidden;
  180. }
  181. .uni-card__title-content-title {
  182. font-size: 28rpx;
  183. line-height: 22px;
  184. lines: 1;
  185. }
  186. .uni-card__title-content-extra {
  187. font-size: 26rpx;
  188. line-height: 35rpx;
  189. color: #999;
  190. }
  191. .uni-card__header {
  192. /* #ifndef APP-NVUE */
  193. display: flex;
  194. /* #endif */
  195. position: relative;
  196. flex-direction: row;
  197. padding: 24rpx;
  198. align-items: center;
  199. border-bottom-color: #e5e5e5;
  200. border-bottom-style: solid;
  201. border-bottom-width: 1px;
  202. }
  203. .uni-card__header-title {
  204. /* #ifndef APP-NVUE */
  205. display: flex;
  206. /* #endif */
  207. flex-direction: row;
  208. margin-right: 16rpx;
  209. justify-content: flex-start;
  210. align-items: center;
  211. }
  212. .uni-card__header-title-text {
  213. font-size: 32rpx;
  214. flex: 1;
  215. /* #ifndef APP-NVUE */
  216. white-space: nowrap;
  217. /* #endif */
  218. /* #ifdef APP-NVUE */
  219. lines: 1;
  220. /* #endif */
  221. overflow: hidden;
  222. text-overflow: ellipsis;
  223. }
  224. .uni-card__header-extra-img {
  225. height: 40rpx;
  226. width: 40rpx;
  227. margin-right: 16rpx;
  228. }
  229. .uni-card__header-extra-text {
  230. flex: 1;
  231. margin-left: 16rpx;
  232. font-size: 28rpx;
  233. text-align: right;
  234. color: #999;
  235. }
  236. .uni-card__content {
  237. color: #333;
  238. }
  239. .uni-card__content--pd {
  240. padding: 24rpx;
  241. }
  242. .uni-card__content-extra {
  243. font-size: 28rpx;
  244. padding-bottom: 10px;
  245. color: #999;
  246. }
  247. .uni-card__footer {
  248. justify-content: space-between;
  249. padding: 10px;
  250. border-top-color: #e5e5e5;
  251. border-top-style: solid;
  252. border-top-width: 1px;
  253. }
  254. .uni-card__footer-text {
  255. color: #999;
  256. font-size: 28rpx;
  257. }
  258. .uni-card--shadow {
  259. border-color: #e5e5e5;
  260. border-style: solid;
  261. border-width: 1px;
  262. /* #ifndef APP-NVUE */
  263. box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.2);
  264. /* #endif */
  265. }
  266. .uni-card--full {
  267. margin: 0;
  268. border-radius: 0;
  269. }
  270. </style>