index.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. <n-button v-if="link" @click="click" text>
  17. {{ dataset }}
  18. </n-button>
  19. <span v-else>{{ dataset }}</span>
  20. </div>
  21. </div>
  22. </template>
  23. <script setup lang="ts">
  24. import { PropType, toRefs, shallowReactive, watch } from 'vue'
  25. import { CreateComponentType } from '@/packages/index.d'
  26. import { useChartDataFetch } from '@/hooks'
  27. import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
  28. import { option as configOption } from './config'
  29. const props = defineProps({
  30. chartConfig: {
  31. type: Object as PropType<CreateComponentType>,
  32. required: true
  33. }
  34. })
  35. const { w, h } = toRefs(props.chartConfig.attr)
  36. const {
  37. link,
  38. dataset,
  39. fontColor,
  40. fontSize,
  41. letterSpacing,
  42. paddingY,
  43. paddingX,
  44. borderWidth,
  45. borderColor,
  46. borderRadius,
  47. writingMode,
  48. backgroundColor
  49. } = toRefs(props.chartConfig.option)
  50. const option = shallowReactive({
  51. dataset: configOption.dataset
  52. })
  53. // 手动更新
  54. watch(
  55. () => props.chartConfig.option.dataset,
  56. (newData: any) => {
  57. option.dataset = newData
  58. },
  59. {
  60. immediate: true,
  61. deep: false
  62. }
  63. )
  64. // 预览更新
  65. useChartDataFetch(props.chartConfig, useChartEditStore, (newData: string) => {
  66. option.dataset = newData
  67. })
  68. //打开链接
  69. const click = () => {
  70. window.open(link.value)
  71. }
  72. </script>
  73. <style lang="scss" scoped>
  74. @include go('text-box') {
  75. display: flex;
  76. align-items: center;
  77. justify-content: center;
  78. }
  79. </style>