s-block.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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.background.type == 'color')
  20. return { background: props.styles.background.bgColor };
  21. if (props.styles.background.type == 'image')
  22. return {
  23. background: `url(${sheep.$url.cdn(
  24. props.styles.background.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}px`,
  33. marginBottom: props.styles.marginBottom + 'px',
  34. marginLeft: `${props.styles.marginLeft}px`,
  35. marginRight: props.styles.marginRight + 'px',
  36. 'border-top-left-radius': props.styles.borderRadiusTop + 'px',
  37. 'border-top-right-radius': props.styles.borderRadiusTop + 'px',
  38. 'border-bottom-left-radius': props.styles.borderRadiusBottom + 'px',
  39. 'border-bottom-right-radius': props.styles.borderRadiusBottom + 'px',
  40. padding: props.styles.padding + 'px',
  41. overflow: 'hidden',
  42. };
  43. }
  44. });
  45. </script>