index.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <template>
  2. <div class="go-text-box">
  3. <div
  4. :style="`
  5. color: ${fontColor};
  6. padding: ${paddingY}px ${paddingX}px;
  7. font-size: ${fontSize}px;
  8. letter-spacing: ${letterSpacing}px;
  9. writing-mode: ${writingMode};
  10. border-style: solid;
  11. border-width: ${borderWidth}px;
  12. border-radius: ${borderRadius}px;
  13. border-color: ${borderColor};
  14. background-color:${backgroundColor}`"
  15. >
  16. {{ option.dataset }}
  17. </div>
  18. </div>
  19. </template>
  20. <script setup lang="ts">
  21. import { PropType, toRefs, shallowReactive, watch } from 'vue'
  22. import { CreateComponentType } from '@/packages/index.d'
  23. import { useChartDataFetch } from '@/hooks'
  24. import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
  25. import { option as configOption } from './config'
  26. const props = defineProps({
  27. chartConfig: {
  28. type: Object as PropType<CreateComponentType>,
  29. required: true
  30. }
  31. })
  32. const { w, h } = toRefs(props.chartConfig.attr)
  33. const {
  34. dataset,
  35. fontColor,
  36. fontSize,
  37. letterSpacing,
  38. paddingY,
  39. paddingX,
  40. borderWidth,
  41. borderColor,
  42. borderRadius,
  43. writingMode,
  44. backgroundColor
  45. } = toRefs(props.chartConfig.option)
  46. const option = shallowReactive({
  47. dataset: configOption.dataset
  48. })
  49. // 手动更新
  50. watch(
  51. () => props.chartConfig.option.dataset,
  52. (newData: any) => {
  53. option.dataset = newData
  54. }, {
  55. immediate: true
  56. }
  57. )
  58. // 预览更新
  59. useChartDataFetch(props.chartConfig, useChartEditStore, (newData: string) => {
  60. option.dataset = newData
  61. })
  62. </script>
  63. <style lang="scss" scoped>
  64. @include go('text-box') {
  65. display: flex;
  66. align-items: center;
  67. justify-content: center;
  68. }
  69. </style>