s-block.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 '@/common';
  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(${props.styles.bgImage}) no-repeat top center / 100% auto`,
  25. };
  26. }
  27. });
  28. const elStyles = computed(() => {
  29. if (props.styles) {
  30. return {
  31. marginTop: `${props.styles.marginTop || 0}rpx`,
  32. marginBottom: `${props.styles.marginBottom || 0}rpx`,
  33. marginLeft: `${props.styles.marginLeft || 0}rpx`,
  34. marginRight: `${props.styles.marginRight || 0}rpx`,
  35. paddingTop: `${props.styles.paddingTop || 0}rpx`,
  36. paddingRight: `${props.styles.paddingRight || 0}rpx`,
  37. paddingBottom: `${props.styles.paddingBottom || 0}rpx`,
  38. paddingLeft: `${props.styles.paddingLeft || 0}rpx`,
  39. borderTopLeftRadius: `${props.styles.borderTopLeftRadius || 0}rpx`,
  40. borderTopRightRadius: `${props.styles.borderTopRightRadius || 0}rpx`,
  41. borderBottomRightRadius: `${props.styles.borderBottomRightRadius || 0}rpx`,
  42. borderBottomLeftRadius: `${props.styles.borderBottomLeftRadius || 0}rpx`,
  43. overflow: 'hidden',
  44. };
  45. }
  46. });
  47. </script>