tm-card.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <template>
  2. <view @click="onclick" class="tm-card " :class="['mx-32', 'my-24', black_tmeme ? 'grey-darken-5' : bgColor, `round-${round}`, `shadow-${bgColor}-${shadow}`]">
  3. <view :class="['pa-24']">
  4. <view :class="[img?'flex-start':'']">
  5. <view v-if="img" class="flex-shrink mr-24">
  6. <slot name="img" :text="{data:img}">
  7. <tm-images :round="imgRound" :width="90" :src="img"></tm-images>
  8. </slot>
  9. </view>
  10. <view class="fulled">
  11. <view class="subtitle_wk flex-between ">
  12. <view v-if="subTitle" class="subtitle text-size-s text-grey">
  13. <slot name="subTitle" :text="{data:subTitle}">{{ subTitle }}</slot>
  14. </view>
  15. <view class="px-12"></view>
  16. <view v-if="statusText" class="substatus flex-shrink text px-12 py-6 text-size-xs round-6 text-weight-b" :class="[black_tmeme ? 'bk' : '', statusColor]">
  17. <slot name="statusText" :text="{data:statusText}">{{ statusText }}</slot>
  18. </view>
  19. </view>
  20. <view v-if="title" :class="[`text-size-${titleSize}`]" class=" my-16 text-weight-b text-overflow-2">
  21. <slot name="title" :text="{data:title}">{{ title }}</slot>
  22. </view>
  23. <view v-if="subText" class="text-size-s text-grey text-overflow-2">
  24. <slot name="subText" :text="{data:subText}">{{ subText }}</slot>
  25. </view>
  26. </view>
  27. </view>
  28. <view class=" py-24 flex-center" v-if="titleBorder">
  29. <view class="border-t-1 fulled" :class="[black_tmeme?'bk':'']"></view>
  30. </view>
  31. <view class="text-size-n " :class="[black_tmeme ? 'bk' : '']">
  32. <slot name="content" :text="{data:content}">
  33. <view selectable >{{ content }}</view>
  34. </slot>
  35. </view>
  36. <view class=" py-24 flex-center" v-if="actionBorder">
  37. <view class="border-t-1 fulled" :class="[black_tmeme?'bk':'']"></view>
  38. </view>
  39. <view class="flex-end" :class="[black_tmeme ? 'bk' : '']" v-if="btnColorToarrays.length > 0">
  40. <slot name="action" :action="{ btn: action, color: btnColorToarrays }">
  41. <view v-for="(item, index) in action" @click.stop="actionClick(item, index)" :key="index" class="d-inline-block">
  42. <tm-button :round="actionRound" :theme="btnColorToarrays[index]" :key="index" :black="black_tmeme" size="m">
  43. {{ item }}
  44. </tm-button>
  45. </view>
  46. </slot>
  47. </view>
  48. </view>
  49. </view>
  50. </template>
  51. <script>
  52. /**
  53. * 卡片
  54. * @param {String} title-size= [xxs|s|n|g|lg|xl] 默认:g,对应的文本尺寸:xxs,xs,s,n,g,lg,xl
  55. * @param {String} img= [] 默认:'',头像图片地址。
  56. * @param {Number} imgRound= [] 默认:4,头像圆角
  57. * @param {Number} round= [] 默认:4,卡片圆角
  58. * @param {Number} shadow= [] 默认:4,卡片投影
  59. * @param {Array|String} btnColor= [] 默认:white,按钮颜色,可以是string,或者数组['white,'red']按钮组就会依次使用该颜色,如只是一颜色,第一个使用,后面的使用默认的white.
  60. * @param {Array} action= [] 默认:[],操作按钮组
  61. * @param {Number} action-round= [] 默认:2,操作按钮组的圆角,
  62. * @param {Boolean} action-border= [] 默认:true,是否显示操作按钮上方的边线
  63. * @param {String} status-color= [] 默认:black,卡片右上角状态文件的主题色
  64. * @param {String} status-text= [] 默认:'',卡片右上角状态文本
  65. * @param {String} sub-title= [] 默认:'',卡片左上角的卡片名称
  66. * @param {String} title= [] 默认:'',标题
  67. * @param {String} sub-text= [] 默认:'',副标题
  68. * @param {Boolean} title-border= [] 默认:true,标题下方的边线。
  69. * @param {String} content= [] 默认:'',卡片的正方内容
  70. * @param {Boolean} black= [] 默认:null,是否暗黑
  71. * @param {String} bg-color= [] 默认:'white',卡片的背景色
  72. * @param {Function} click 点击卡片触发的事件
  73. * @param {Function} action-click 点击按钮组触发的事件
  74. * @example <tm-card title="简单示例" content="内容" :action="['操作按钮']"></tm-card>
  75. */
  76. import tmButton from '@/tm-vuetify/components/tm-button/tm-button.vue';
  77. export default {
  78. name: 'tm-card',
  79. components: { tmButton },
  80. props: {
  81. img:{
  82. type:String,
  83. default:''
  84. },
  85. imgRound:{
  86. type:Number | String,
  87. default:4
  88. },
  89. //卡片的圆角
  90. round: {
  91. type: Number | String,
  92. default: 4
  93. },
  94. shadow: {
  95. type: Number | String,
  96. default: 4
  97. },
  98. btnColor: {
  99. type: Array | String,
  100. default: () => 'white'
  101. },
  102. action: {
  103. type: Array,
  104. default: () => []
  105. },
  106. actionRound: {
  107. type: Number | String,
  108. default: 2
  109. },
  110. actionBorder:{
  111. type:Boolean|String,
  112. default:true
  113. },
  114. statusColor: {
  115. type: String,
  116. default: 'black'
  117. },
  118. statusText: {
  119. type: String,
  120. default: ''
  121. },
  122. //卡片名称
  123. subTitle: {
  124. type: String,
  125. default: ''
  126. },
  127. //标题
  128. title: {
  129. type: String,
  130. default: ''
  131. },
  132. titleSize: {
  133. type: String,
  134. default: 'g'
  135. },
  136. titleBorder:{
  137. type:Boolean|String,
  138. default:true
  139. },
  140. //标题介绍
  141. subText: {
  142. type: String,
  143. default: ''
  144. },
  145. content: {
  146. type: String,
  147. default: ''
  148. },
  149. black: {
  150. type: Boolean | String,
  151. default: null
  152. },
  153. bgColor: {
  154. type: String,
  155. default: 'white'
  156. }
  157. },
  158. computed: {
  159. black_tmeme: function() {
  160. if (this.black !== null) return this.black;
  161. return this.$tm.vx.state().tmVuetify.black;
  162. },
  163. btnColorToarrays: function() {
  164. let al = this.action.length;
  165. if (this.action.length == 0 || !this.action) return [];
  166. let colors = this.btnColor;
  167. colors = Array.isArray(colors) ? colors : [colors];
  168. for (let i = 0; i < al; i++) {
  169. if (!colors[i]) {
  170. colors.push('white');
  171. }
  172. }
  173. return colors;
  174. }
  175. },
  176. data() {
  177. return {};
  178. },
  179. methods:{
  180. actionClick(index){
  181. this.$emit('action-click',index);
  182. },
  183. onclick(e){
  184. this.$emit('click',e);
  185. }
  186. }
  187. };
  188. </script>
  189. <style lang="scss" scoped></style>