fs-card.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <view class="fs-card" :class="{ 'fs-card-full': full, 'fs-card-gutter': gutter }" @click="handleClick">
  3. <view class="fs-card-box" :class="{ 'fs-card-radius': radius, shadow }">
  4. <view class="fs-card-title" v-if="slots.title || title" :style="titleStyle">
  5. <slot name="title">{{ title }}</slot>
  6. </view>
  7. <view :class="{ 'fs-card-content': contentPadding }"><slot></slot></view>
  8. <view class="fs-card-ft" v-if="slots.footer"><slot name="footer"></slot></view>
  9. </view>
  10. </view>
  11. </template>
  12. <script>
  13. /**
  14. * 卡片组件
  15. * @description 卡片组件
  16. * @property {String} title 标题
  17. * @property {Object} titleStyle 标题样式
  18. * @property {Boolean} full 是否通屏
  19. * @property {Boolean} gutter 是否有下边距
  20. * @property {Boolean} radius 是否圆角
  21. * @property {Boolean} shadow 是否带阴影
  22. * @property {String} link 跳转地址
  23. * @property {String} linkType 跳转类型
  24. */
  25. export default {
  26. name: 'fs-card'
  27. }
  28. </script>
  29. <script setup>
  30. import { useSlots } from 'vue'
  31. const props = defineProps({
  32. title: String,
  33. titleStyle: {
  34. type: Object,
  35. default() {
  36. return {}
  37. }
  38. },
  39. full: Boolean,
  40. gutter: Boolean,
  41. radius: {
  42. type: Boolean,
  43. default: true
  44. },
  45. shadow: {
  46. type: Boolean,
  47. default: false
  48. },
  49. contentPadding: Boolean,
  50. link: String,
  51. linkType: {
  52. type: String,
  53. default: 'navigateTo'
  54. }
  55. })
  56. const slots = useSlots()
  57. const emits = defineEmits(['click'])
  58. const handleClick = () => {
  59. if (props.link) {
  60. uni[props.linkType]({
  61. url: props.link
  62. })
  63. }
  64. emits('click')
  65. }
  66. </script>
  67. <style lang="scss" scoped>
  68. .fs-card {
  69. margin-left: var(--gutter);
  70. margin-right: var(--gutter);
  71. &-box {
  72. background-color: #fff;
  73. overflow: hidden;
  74. }
  75. &-radius {
  76. border-radius: var(--radius);
  77. }
  78. &-title {
  79. padding: 20rpx var(--gutter);
  80. border-bottom: 2rpx solid var(--border-color);
  81. }
  82. &-ft {
  83. padding: 20rpx var(--gutter);
  84. border-top: 2rpx solid var(--border-color);
  85. }
  86. &-content {
  87. padding: 20rpx var(--gutter);
  88. }
  89. &-full {
  90. margin-left: 0;
  91. margin-right: 0;
  92. }
  93. &-gutter {
  94. margin-bottom: var(--gutter-v);
  95. }
  96. }
  97. </style>