card.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <view class="card" @click="onClick" :style="[customStyle]" :data-i="$attrs['data-i']">
  3. <image class="card-img" mode="aspectFill" :src="src" />
  4. <view class="text-wrap text-wrap-width" v-if="!!desc">
  5. <view class="title one-t">{{title}}</view>
  6. <view class="desc one-t">{{desc}}</view>
  7. </view>
  8. <view v-else class="text-wrap-width title more-t">{{title}}</view>
  9. <image class="card-icon" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAMAAADVRocKAAABCFBMVEUAAAC/v7+qqqqZmZmLi6KJnZ2ImZmHlpaGlKGMjJmSkp6Li5eQkJuKlZ+Pj5mOjpeJkpuNjZ6IkJmHj5eLi5uKkpmGjZqJj5uLi5eIjpmIjZiKj5qKj5mJjpiHjJqJjZaGj5iKj5eIjJmKjpqHi5eGjZeIi5eHjZiIi5eHjJiIjpaHjJeIjZiGjJeIjZiGjJaGjJeIi5aGjJeHi5eHi5aHjJeHjJaHjJeGi5eHjJaHjJeGi5aGi5aHjJeHjJaGjJeGjJeHjJaHi5eGi5eHjJaHjJeGjJaGjJeHi5aHjJeHjJeHi5aGjJeHi5aGjJaHi5eGjJaHi5eHjJaGi5eGi5aHjJeGi5aGi5apAvjmAAAAV3RSTlMABAYKCw0PERMUFRYXGBkbHB0eICEjJiksLS8wMjQ1ODk7PD9ATFZXWFlaW1xdXl+Hi6msu7/Dx8vMzs/R0tTV19na3N3f4uTn6evs7e7v8PHy9PX7/P18cCTXAAABEklEQVRo3u2YWU5CQRQFn4qCM4LzhIoDAorzrIgCigiCimf/O/Gj3UIlmJxaQFXSea/T90aRMcYYY4zpG0ZPu9cZMnAi6SsLBjqS9LnJBcqSpC53Sjs/kqSPNaxwGAqtFbrQXKILjQW68DpPF17m6EI9TRdqM3TheZouVCbpQnkcK5RC4T5BF27jdOFqhC5cDtOFixhdOB+iC2cDdOEoggttLrDbk6QW5/+WJB1T/r1e+FAHWT/2q/35scsiF/w3cdZ/R13Y+8H/MMb6Hycgfz74n6ZYfzXJ+mspyF8I/vos68cep0X4eV2EB4SD4H9bZP3vy+yTtL3KjrGddXgQ34BXCVvwMmT7P69zjDHGGGP6gF83lHISOctsKQAAAABJRU5ErkJggg=="></image>
  10. </view>
  11. </template>
  12. <script>
  13. export default {
  14. props: {
  15. mode: {
  16. type: Boolean,
  17. default: false
  18. },
  19. src: String,
  20. title: String,
  21. desc: String,
  22. url: String,
  23. color: String,
  24. bgcolor: String,
  25. border: String
  26. },
  27. data () {
  28. return {
  29. }
  30. },
  31. computed: {
  32. customStyle () {
  33. return {
  34. 'background-color': this.bgColor || '#a4d0ff',
  35. border: this.border || '1px solid #FFF',
  36. color: this.color || '#000'
  37. }
  38. }
  39. },
  40. methods: {
  41. onClick (e) {
  42. if (this.url && this.url.trim().length > 6 && !this.mode) {
  43. uni.navigateTo({ url: this.url })
  44. }
  45. this.$emit('click', e)
  46. }
  47. }
  48. }
  49. </script>
  50. <style lang="scss">
  51. .one-t {
  52. overflow: hidden;
  53. white-space: nowrap;
  54. text-overflow: ellipsis;
  55. transition: all linear 0.2s;
  56. }
  57. .more-t {
  58. overflow: hidden;
  59. text-overflow: ellipsis;
  60. word-break:break-all;
  61. display: -webkit-box;
  62. -webkit-line-clamp: 2;
  63. -webkit-box-orient: vertical;
  64. transition: all linear 0.2s;
  65. }
  66. .card {
  67. width: 80%;
  68. margin: 10rpx auto;
  69. max-width: 700rpx;
  70. max-height: 140rpx;
  71. box-sizing: border-box;
  72. overflow: hidden;
  73. display: flex;
  74. justify-content: space-between;
  75. align-items: center;
  76. padding: 20rpx 0 20rpx 10rpx;
  77. border-radius: 12rpx;
  78. &-img {
  79. width: 96rpx;
  80. height: 96rpx;
  81. border-radius: 12rpx;
  82. flex: 0 0 96rpx;
  83. }
  84. &-icon {
  85. width: 30rpx;
  86. height: 96rpx;
  87. }
  88. .text-wrap {
  89. display: flex;
  90. flex-direction: column;
  91. justify-content: space-between;
  92. &-width {
  93. width: 72%;
  94. }
  95. }
  96. .title {
  97. font-weight: bold;
  98. font-size: 34rpx;
  99. line-height: 48rpx;
  100. }
  101. .desc {
  102. font-size: 27rpx;
  103. line-height: 37rpx;
  104. }
  105. }
  106. </style>