s-block.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <!-- 装修组件容器 -->
  2. <template>
  3. <view :style="[elStyles, elBackground]"><slot /></view>
  4. </template>
  5. <script setup>
  6. /**
  7. * 容器组件 - 装修组件的样式容器
  8. */
  9. import { computed, provide, unref } from 'vue';
  10. import sheep from '@/sheep';
  11. const props = defineProps({
  12. styles: {
  13. type: Object,
  14. default() {},
  15. },
  16. });
  17. // 组件样式
  18. const elBackground = computed(() => {
  19. if (props.styles) {
  20. if (props.styles.bgType === 'color')
  21. return { background: props.styles.bgColor };
  22. if (props.styles.bgType === 'img')
  23. return {
  24. background: `url(${sheep.$url.cdn(
  25. props.styles.bgImage,
  26. )}) no-repeat top center / 100% auto`,
  27. };
  28. }
  29. });
  30. const elStyles = computed(() => {
  31. if (props.styles) {
  32. return {
  33. marginTop: `${props.styles.marginTop || 0}px`,
  34. marginBottom: `${props.styles.marginBottom || 0}px`,
  35. marginLeft: `${props.styles.marginLeft || 0}px`,
  36. marginRight: `${props.styles.marginRight || 0}px`,
  37. paddingTop: `${props.styles.paddingTop || 0}px`,
  38. paddingRight: `${props.styles.paddingRight || 0}px`,
  39. paddingBottom: `${props.styles.paddingBottom || 0}px`,
  40. paddingLeft: `${props.styles.paddingLeft || 0}px`,
  41. borderTopLeftRadius: `${props.styles.borderTopLeftRadius || 0}px`,
  42. borderTopRightRadius: `${props.styles.borderTopRightRadius || 0}px`,
  43. borderBottomRightRadius: `${props.styles.borderBottomRightRadius || 0}px`,
  44. borderBottomLeftRadius: `${props.styles.borderBottomLeftRadius || 0}px`,
  45. overflow: 'hidden',
  46. };
  47. }
  48. });
  49. </script>