card.vue 4.1 KB

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