tui-card.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <view class="tui-card-class tui-card" :class="[full?'tui-card-full':'',border?'tui-card-border':'']" @tap="handleClick"
  3. @longtap="longTap">
  4. <view class="tui-card-header" :class="{'tui-header-line':header.line}" :style="{background:header.bgcolor || '#fff'}">
  5. <view class="tui-header-left">
  6. <image :src="image.url" class="tui-header-thumb" :class="{'tui-thumb-circle':image.circle}" mode="widthFix" v-if="image.url"
  7. :style="{height:(image.height || 60)+'rpx',width:(image.width || 60)+'rpx'}"></image>
  8. <text class="tui-header-title" :style="{fontSize:(title.size || 30)+'rpx',color:(title.color || '#7A7A7A')}" v-if="title.text">{{title.text}}</text>
  9. </view>
  10. <view class="tui-header-right" :style="{fontSize:(tag.size || 24)+'rpx',color:(tag.color || '#b2b2b2')}" v-if="tag.text">
  11. {{tag.text}}
  12. </view>
  13. </view>
  14. <view class="tui-card-body">
  15. <slot name="body"></slot>
  16. </view>
  17. <view class="tui-card-footer">
  18. <slot name="footer"></slot>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. export default {
  24. name: "tuiCard",
  25. emits: ['click','longclick'],
  26. props: {
  27. //是否铺满
  28. full: {
  29. type: Boolean,
  30. default: false
  31. },
  32. image: {
  33. type: Object,
  34. default: function() {
  35. return {
  36. url: "", //图片地址
  37. height: 60, //图片高度
  38. width: 60, //图片宽度
  39. circle: false
  40. }
  41. }
  42. },
  43. //标题
  44. title: {
  45. type: Object,
  46. default: function() {
  47. return {
  48. text: "", //标题文字
  49. size: 30, //字体大小
  50. color: "#7A7A7A" //字体颜色
  51. }
  52. }
  53. },
  54. //标签,时间等
  55. tag: {
  56. type: Object,
  57. default: function() {
  58. return {
  59. text: "", //标签文字
  60. size: 24, //字体大小
  61. color: "#b2b2b2" //字体颜色
  62. }
  63. }
  64. },
  65. header: {
  66. type: Object,
  67. default: function() {
  68. return {
  69. bgcolor: "#fff", //背景颜色
  70. line: false //是否去掉底部线条
  71. }
  72. }
  73. },
  74. //是否设置外边框
  75. border: {
  76. type: Boolean,
  77. default: false
  78. },
  79. index: {
  80. type: Number,
  81. default: 0
  82. }
  83. },
  84. methods: {
  85. handleClick() {
  86. this.$emit('click', {
  87. index: this.index
  88. });
  89. },
  90. longTap() {
  91. this.$emit('longclick', {
  92. index: this.index
  93. });
  94. }
  95. }
  96. }
  97. </script>
  98. <style scoped>
  99. .tui-card {
  100. margin: 0 30rpx;
  101. font-size: 28rpx;
  102. background-color: #fff;
  103. border-radius: 10rpx;
  104. box-shadow: 0 0 10rpx #eee;
  105. box-sizing: border-box;
  106. overflow: hidden;
  107. }
  108. .tui-card-full {
  109. margin: 0 !important;
  110. border-radius: 0 !important;
  111. }
  112. .tui-card-full::after {
  113. border-radius: 0 !important;
  114. }
  115. .tui-card-border {
  116. position: relative;
  117. box-shadow: none !important
  118. }
  119. .tui-card-border::after {
  120. content: ' ';
  121. position: absolute;
  122. height: 200%;
  123. width: 200%;
  124. border: 1px solid #ddd;
  125. transform-origin: 0 0;
  126. -webkit-transform-origin: 0 0;
  127. -webkit-transform: scale(0.5);
  128. transform: scale(0.5);
  129. left: 0;
  130. top: 0;
  131. border-radius: 20rpx;
  132. box-sizing: border-box;
  133. pointer-events: none;
  134. }
  135. .tui-card-header {
  136. width: 100%;
  137. padding: 20rpx;
  138. display: flex;
  139. align-items: center;
  140. justify-content: space-between;
  141. position: relative;
  142. box-sizing: border-box;
  143. overflow: hidden;
  144. border-top-left-radius: 10rpx;
  145. border-top-right-radius: 10rpx;
  146. }
  147. .tui-card-header::after {
  148. content: '';
  149. position: absolute;
  150. border-bottom: 1rpx solid #eaeef1;
  151. -webkit-transform: scaleY(0.5);
  152. transform: scaleY(0.5);
  153. bottom: 0;
  154. right: 0;
  155. left: 0;
  156. pointer-events: none;
  157. }
  158. .tui-header-line::after {
  159. border-bottom: 0 !important;
  160. }
  161. .tui-header-thumb {
  162. height: 60rpx;
  163. width: 60rpx;
  164. vertical-align: middle;
  165. margin-right: 20rpx;
  166. border-radius: 6rpx;
  167. }
  168. .tui-thumb-circle {
  169. border-radius: 50% !important;
  170. }
  171. .tui-header-title {
  172. display: inline-block;
  173. font-size: 30rpx;
  174. color: #7a7a7a;
  175. vertical-align: middle;
  176. max-width: 460rpx;
  177. overflow: hidden;
  178. white-space: nowrap;
  179. text-overflow: ellipsis;
  180. }
  181. .tui-header-right {
  182. font-size: 24rpx;
  183. color: #b2b2b2;
  184. }
  185. .tui-card-body {
  186. font-size: 32rpx;
  187. color: #262b3a;
  188. box-sizing: border-box;
  189. }
  190. .tui-card-footer {
  191. font-size: 28rpx;
  192. color: #596d96;
  193. border-bottom-left-radius: 10rpx;
  194. border-bottom-right-radius: 10rpx;
  195. box-sizing: border-box;
  196. }
  197. </style>