s-block.vue 1.6 KB

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