uni-card.vue 9.2 KB

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