uni-card.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. <template>
  2. <view class="uni-card uni-border" :class="{ 'uni-card--full': isFull === true || isFull === 'true', 'uni-card--shadow': isShadow === true || isShadow === 'true'}">
  3. <!-- 基础 -->
  4. <view v-if="mode === 'basic' && title" class="uni-card__header uni-border-bottom" @click.stop="onClick">
  5. <view v-if="thumbnail" class="uni-card__header-extra-img-view">
  6. <image :src="thumbnail" class="uni-card__header-extra-img" />
  7. </view>
  8. <text class="uni-card__header-title-text">{{ title }}</text>
  9. <text v-if="extra" class="uni-card__header-extra-text">{{ extra }}</text>
  10. </view>
  11. <!-- 标题 -->
  12. <view v-if="mode === 'title'" class="uni-card__title uni-border-bottom" @click.stop="onClick">
  13. <view class="uni-card__title-box">
  14. <view class="uni-card__title-header">
  15. <image class="uni-card__title-header-image" :src="thumbnail" mode="scaleToFill" />
  16. </view>
  17. <view class="uni-card__title-content">
  18. <text class="uni-card__title-content-title uni-ellipsis">{{ title }}</text>
  19. <text class="uni-card__title-content-extra uni-ellipsis">{{ subTitle }}</text>
  20. </view>
  21. </view>
  22. <view v-if="extra">
  23. <text class="uni-card__header-extra-text">{{ extra }}</text>
  24. </view>
  25. </view>
  26. <!-- 图文 -->
  27. <view v-if="mode === 'style'" class="uni-card__thumbnailimage" @click.stop="onClick">
  28. <view class="uni-card__thumbnailimage-box">
  29. <image class="uni-card__thumbnailimage-image" :src="thumbnail" mode="aspectFill" />
  30. </view>
  31. <view v-if="title" class="uni-card__thumbnailimage-title"><text class="uni-card__thumbnailimage-title-text">{{ title }}</text></view>
  32. </view>
  33. <!-- 内容 -->
  34. <view class="uni-card__content uni-card__content--pd" @click.stop="onClick">
  35. <view v-if="mode === 'style' && extra" class=""><text class="uni-card__content-extra">{{ extra }}</text></view>
  36. <slot />
  37. </view>
  38. <!-- 底部 -->
  39. <view v-if="note" class="uni-card__footer uni-border-top">
  40. <slot name="footer">
  41. <text class="uni-card__footer-text">{{ note }}</text>
  42. </slot>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. /**
  48. * Card 卡片
  49. * @description 卡片视图组件
  50. * @tutorial https://ext.dcloud.net.cn/plugin?id=22
  51. * @property {String} title 标题文字
  52. * @property {String} subTitle 副标题(仅仅mode=title下生效)
  53. * @property {String} extra 标题额外信息
  54. * @property {String} note 标题左侧缩略图
  55. * @property {String} thumbnail 底部信息
  56. * @property {String} mode = [basic|style|title] 卡片模式
  57. * @value basic 基础卡片
  58. * @value style 图文卡片
  59. * @value title 标题卡片
  60. * @property {Boolean} isFull = [true | false] 卡片内容是否通栏,为 true 时将去除padding值
  61. * @property {Boolean} isShadow = [true | false] 卡片内容是否开启阴影
  62. * @event {Function} click 点击 Card 触发事件
  63. * @example <uni-card title="标题文字" thumbnail="https://img-cdn-qiniu.dcloud.net.cn/new-page/uni.png" extra="额外信息" note="Tips">内容主体,可自定义内容及样式</uni-card>
  64. */
  65. export default {
  66. name: 'UniCard',
  67. props: {
  68. title: {
  69. type: String,
  70. default: ''
  71. },
  72. subTitle: {
  73. type: String,
  74. default: ''
  75. },
  76. extra: {
  77. type: String,
  78. default: ''
  79. },
  80. note: {
  81. type: String,
  82. default: ''
  83. },
  84. thumbnail: {
  85. type: String,
  86. default: ''
  87. },
  88. mode: {
  89. type: String,
  90. default: 'basic'
  91. },
  92. isFull: {
  93. // 内容区域是否通栏
  94. type: Boolean,
  95. default: false
  96. },
  97. isShadow: {
  98. // 是否开启阴影
  99. type: [Boolean, String],
  100. default: false
  101. }
  102. },
  103. methods: {
  104. onClick() {
  105. this.$emit('click')
  106. }
  107. }
  108. }
  109. </script>
  110. <style scoped>
  111. .uni-card {
  112. /* #ifndef APP-NVUE */
  113. display: flex;
  114. flex: 1;
  115. box-shadow: 0 0 0 rgba(0, 0, 0, 0);
  116. /* #endif */
  117. margin: 12px 15px;
  118. background-color: #ffffff;
  119. position: relative;
  120. flex-direction: column;
  121. border-radius: 5px;
  122. overflow: hidden;
  123. }
  124. .uni-border {
  125. position: relative;
  126. /* #ifdef APP-NVUE */
  127. border-color: #e5e5e5;
  128. border-style: solid;
  129. border-width: 0.5px;
  130. /* #endif */
  131. z-index: 1;
  132. }
  133. /* #ifndef APP-NVUE */
  134. .uni-border:after {
  135. content: '';
  136. position: absolute;
  137. bottom: 0;
  138. left: 0;
  139. top: 0;
  140. right: 0;
  141. border: 1px solid #e5e5e5;
  142. border-radius: 10px;
  143. box-sizing: border-box;
  144. width: 200%;
  145. height: 200%;
  146. transform: scale(0.5);
  147. transform-origin: left top;
  148. z-index: -1;
  149. }
  150. /* #endif */
  151. .uni-border-bottom {
  152. position: relative;
  153. /* #ifdef APP-NVUE */
  154. border-bottom-color: #e5e5e5;
  155. border-bottom-style: solid;
  156. border-bottom-width: 0.5px;
  157. /* #endif */
  158. z-index: 1;
  159. }
  160. /* #ifndef APP-NVUE */
  161. .uni-border-bottom:after {
  162. content: '';
  163. position: absolute;
  164. bottom: 0;
  165. left: 0;
  166. top: 0;
  167. right: 0;
  168. border-bottom: 1px solid #e5e5e5;
  169. box-sizing: border-box;
  170. width: 200%;
  171. height: 200%;
  172. transform: scale(0.5);
  173. transform-origin: left top;
  174. z-index: -1;
  175. }
  176. /* #endif */
  177. .uni-border-top {
  178. position: relative;
  179. /* #ifdef APP-NVUE */
  180. border-top-color: #e5e5e5;
  181. border-top-style: solid;
  182. border-top-width: 0.5px;
  183. /* #endif */
  184. z-index: 1;
  185. }
  186. /* #ifndef APP-NVUE */
  187. .uni-border-top:after {
  188. content: '';
  189. position: absolute;
  190. bottom: 0;
  191. left: 0;
  192. top: 0;
  193. right: 0;
  194. border-top: 1px solid #e5e5e5;
  195. box-sizing: border-box;
  196. width: 200%;
  197. height: 200%;
  198. transform: scale(0.5);
  199. transform-origin: left top;
  200. z-index: -1;
  201. }
  202. /* #endif */
  203. .uni-card__thumbnailimage {
  204. position: relative;
  205. flex-direction: column;
  206. justify-content: center;
  207. height: 150px;
  208. overflow: hidden;
  209. }
  210. .uni-card__thumbnailimage-box {
  211. /* #ifndef APP-NVUE */
  212. display: flex;
  213. /* #endif */
  214. flex: 1;
  215. flex-direction: row;
  216. overflow: hidden;
  217. }
  218. .uni-card__thumbnailimage-image {
  219. flex: 1;
  220. }
  221. .uni-card__thumbnailimage-title {
  222. /* #ifndef APP-NVUE */
  223. display: flex;
  224. /* #endif */
  225. position: absolute;
  226. bottom: 0;
  227. left: 0;
  228. right: 0;
  229. flex-direction: row;
  230. padding: 8px 12px;
  231. background-color: rgba(0, 0, 0, 0.4);
  232. }
  233. .uni-card__thumbnailimage-title-text {
  234. flex: 1;
  235. font-size: 14px;
  236. color: #fff;
  237. }
  238. .uni-card__title {
  239. /* #ifndef APP-NVUE */
  240. display: flex;
  241. /* #endif */
  242. flex-direction: row;
  243. align-items: center;
  244. padding: 10px;
  245. }
  246. .uni-card__title-box {
  247. /* #ifndef APP-NVUE */
  248. display: flex;
  249. /* #endif */
  250. flex: 1;
  251. flex-direction: row;
  252. align-items: center;
  253. overflow: hidden;
  254. }
  255. .uni-card__title-header {
  256. width: 40px;
  257. height: 40px;
  258. overflow: hidden;
  259. border-radius: 5px;
  260. }
  261. .uni-card__title-header-image {
  262. width: 40px;
  263. height: 40px;
  264. }
  265. .uni-card__title-content {
  266. /* #ifndef APP-NVUE */
  267. display: flex;
  268. /* #endif */
  269. flex-direction: column;
  270. justify-content: center;
  271. flex: 1;
  272. padding-left: 10px;
  273. height: 40px;
  274. overflow: hidden;
  275. }
  276. .uni-card__title-content-title {
  277. font-size: 14px;
  278. line-height: 22px;
  279. }
  280. .uni-card__title-content-extra {
  281. font-size: 12px;
  282. line-height: 27px;
  283. color: #999;
  284. }
  285. .uni-card__header {
  286. /* #ifndef APP-NVUE */
  287. display: flex;
  288. /* #endif */
  289. position: relative;
  290. flex-direction: row;
  291. padding: 12px;
  292. align-items: center;
  293. }
  294. .uni-card__header-title {
  295. /* #ifndef APP-NVUE */
  296. display: flex;
  297. /* #endif */
  298. flex-direction: row;
  299. margin-right: 8px;
  300. justify-content: flex-start;
  301. align-items: center;
  302. }
  303. .uni-card__header-title-text {
  304. font-size: 16;
  305. flex: 1;
  306. color: #333;
  307. }
  308. .uni-card__header-extra-img {
  309. height: 20px;
  310. width: 20px;
  311. margin-right: 8px;
  312. }
  313. .uni-card__header-extra-text {
  314. flex: 1;
  315. margin-left: 8px;
  316. font-size: 12px;
  317. text-align: right;
  318. color: #999;
  319. }
  320. .uni-card__content {
  321. color: #333;
  322. }
  323. .uni-card__content--pd {
  324. padding: 12px;
  325. }
  326. .uni-card__content-extra {
  327. font-size: 14px;
  328. padding-bottom: 10px;
  329. color: #999;
  330. }
  331. .uni-card__footer {
  332. justify-content: space-between;
  333. padding: 12px;
  334. }
  335. .uni-card__footer-text {
  336. color: #999;
  337. font-size: 12px;
  338. }
  339. .uni-card--shadow {
  340. position: relative;
  341. /* #ifndef APP-NVUE */
  342. box-shadow: 0px 0px 5px 1px rgba(0, 0, 0, 0.1);
  343. /* #endif */
  344. }
  345. .uni-card--full {
  346. margin: 0;
  347. border-radius: 0;
  348. }
  349. /* #ifndef APP-NVUE */
  350. .uni-card--full:after {
  351. border-radius: 0;
  352. }
  353. /* #endif */
  354. .uni-ellipsis {
  355. /* #ifndef APP-NVUE */
  356. overflow: hidden;
  357. white-space: nowrap;
  358. text-overflow: ellipsis;
  359. /* #endif */
  360. /* #ifdef APP-NVUE */
  361. lines: 1
  362. /* #endif */
  363. }
  364. </style>