index.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <template>
  2. <n-progress
  3. :type="type"
  4. :height="h"
  5. :processing="processing"
  6. :percentage="option.dataset"
  7. :indicator-placement="indicatorPlacement"
  8. :color="color"
  9. :rail-color="railColor"
  10. :offset-degree="offsetDegree"
  11. >
  12. <n-text
  13. :style="{
  14. color: indicatorTextColor,
  15. fontSize: `${indicatorTextSize}px`
  16. }"
  17. >
  18. {{option.dataset}} {{unit}}
  19. </n-text>
  20. </n-progress>
  21. </template>
  22. <script setup lang="ts">
  23. import { PropType, toRefs, watch, shallowReactive } from 'vue'
  24. import { useChartDataFetch } from '@/hooks'
  25. import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
  26. import config, { option as configOption } from './config'
  27. const props = defineProps({
  28. chartConfig: {
  29. type: Object as PropType<config>,
  30. required: true
  31. }
  32. })
  33. // 取配置数据
  34. const { w, h } = toRefs(props.chartConfig.attr)
  35. const {
  36. type,
  37. unit,
  38. color,
  39. fontSize,
  40. processing,
  41. railColor,
  42. indicatorTextColor,
  43. indicatorPlacement,
  44. indicatorTextSize,
  45. offsetDegree,
  46. dataset
  47. } = toRefs(props.chartConfig.option)
  48. const option = shallowReactive({
  49. dataset: configOption.dataset
  50. })
  51. // 手动更新
  52. watch(
  53. () => props.chartConfig.option.dataset,
  54. (newData: any) => {
  55. option.dataset = newData
  56. }
  57. )
  58. // 预览更新
  59. useChartDataFetch(props.chartConfig, useChartEditStore, (newData: number) => {
  60. option.dataset = newData
  61. })
  62. </script>