uni-card.vue 5.9 KB

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