ChartWrap.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <script setup>
  2. import {computed,onMounted,ref} from 'vue'
  3. import apiChart from '@/api/chart.js'
  4. import {chartRender,useChartRender} from '@/hooks/chart/render'
  5. const {setLimitData,isUseSelfLimit}=useChartRender()
  6. const props=defineProps({
  7. itemData:{
  8. type:Object,
  9. default:{}
  10. }
  11. })
  12. const renderId=computed(()=>{
  13. if(props.itemData?.chartId){
  14. return 'chart'+props.itemData.chartId+'_'+props.itemData.pptPageIndex+'_'+props.itemData.position
  15. }
  16. })
  17. const sourceFrom=ref(null)
  18. // 获取图表详情
  19. let chartIsDelete=ref(false)//图表是否被删除
  20. async function getChartInfo(){
  21. const res=await apiChart.chartInfoByCode({UniqueCode:props.itemData.chartId,IsCache: true})
  22. if(res.Ret===200){
  23. if(!res.Data.ChartInfo){
  24. chartIsDelete.value=true
  25. return
  26. }
  27. let showChartTitle=false
  28. const {Source,ChartType}=res.Data.ChartInfo
  29. sourceFrom.value= res.Data.ChartInfo.SourcesFrom?JSON.parse(res.Data.ChartInfo.SourcesFrom):''
  30. if((Source==1&&[2,7,10].includes(ChartType))||(Source==2&&ChartType==8)){
  31. showChartTitle=true
  32. }
  33. //初始化上下限
  34. isUseSelfLimit.value = true
  35. setLimitData(res.Data)
  36. chartRender({
  37. data:res.Data,
  38. renderId:renderId.value,
  39. lang:window.location.pathname.startsWith('/ppten')?'en':'zh',
  40. changeLangIsCheck:true,
  41. showChartTitle,
  42. shouldUseSelfLimit:true,
  43. })
  44. }
  45. }
  46. onMounted(()=>{
  47. getChartInfo()
  48. })
  49. </script>
  50. <template>
  51. <div class="ppt-chart-box">
  52. <div class="chart-box" :id="renderId">
  53. <img v-if="chartIsDelete" class="empty-img" src="https://hzstatic.hzinsights.com/static/ppt_default.png" alt="">
  54. </div>
  55. <div class="chart-source">
  56. <span
  57. v-if="sourceFrom && sourceFrom.isShow"
  58. :style="`color: ${sourceFrom.isShow ? sourceFrom.color : '#999'};font-size: ${ sourceFrom.fontSize }px;`"
  59. >来源:{{ sourceFrom.text}}</span>
  60. </div>
  61. </div>
  62. </template>
  63. <style lang="scss" scoped>
  64. .ppt-chart-box{
  65. width: 100%;
  66. height: 100%;
  67. position: relative;
  68. z-index: 10;
  69. display: flex;
  70. flex-direction: column;
  71. .chart-box{
  72. width: 100%;
  73. // height: 100%;
  74. flex-grow: 1;
  75. .empty-img{
  76. width: 100%;
  77. height: 100%;
  78. object-fit: contain;
  79. }
  80. }
  81. .chart-source{
  82. width: 100%;
  83. text-overflow: ellipsis;
  84. white-space: nowrap;
  85. overflow: hidden;
  86. }
  87. }
  88. </style>