tm-card.vue 6.3 KB

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