Detail.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <script setup>
  2. import { useRoute } from 'vue-router'
  3. import apiReport from '@/api/modules/report'
  4. import apiCommon from '@/api/modules/common'
  5. import { Message } from 'tdesign-mobile-vue';
  6. const route = useRoute()
  7. let chartId=route.query.chartId
  8. // 获取配置
  9. const chartBaseUrl = ref('')
  10. function getSystemConfig() {
  11. apiCommon.systemConfig({config:'ChartLibUrlPrefix'}).then(res => {
  12. if (res.Ret === 200) {
  13. const ConfVal = res.data.Value || ''
  14. chartBaseUrl.value = ConfVal
  15. }
  16. })
  17. }
  18. getSystemConfig()
  19. const chartInfo = ref({
  20. UniqueCode: route.query.UniqueCode,
  21. ChartName: route.query.ChartName,
  22. IsCollect: true,
  23. chartId: route.query.chartId
  24. })
  25. function getChartDetail(obj) {
  26. const {chartInfoId, chartName, uniqueCode} = obj
  27. chartInfo.value = {
  28. chartId: chartInfoId,
  29. ChartName: chartName,
  30. UniqueCode: uniqueCode,
  31. IsCollect: true
  32. }
  33. }
  34. async function handleCollect() {
  35. const data = {
  36. sourceType: 'chart',
  37. sourceId: Number(chartInfo.value.chartId)
  38. }
  39. const res = chartInfo.value.IsCollect ? await apiReport.reportCollectCancel(data) : await apiReport.reportCollect(data)
  40. if(res.Ret===200){
  41. Message.success(chartInfo.value.IsCollect?'取消收藏成功':'收藏成功')
  42. chartInfo.value.IsCollect=!chartInfo.value.IsCollect
  43. // 通知更新收藏列表
  44. wx.miniProgram.postMessage({
  45. data: 'refreshCollectList'
  46. });
  47. }
  48. }
  49. const chartRenderUrl = computed(() => {
  50. return `${chartBaseUrl.value}/chart/previewHT?code=${chartInfo.value.UniqueCode}&token=${route.query.token}`
  51. })
  52. // 获取图列表切换用
  53. let changeChartList=ref([])
  54. async function getChangeChartList(){
  55. // if(route.query.fromPage!=='myCollect') return
  56. let res=await apiReport.myChartLocate({
  57. key: route.query.searchKey,
  58. })
  59. if(res.Ret===200){
  60. changeChartList.value=res.data||[]
  61. }
  62. }
  63. getChangeChartList()
  64. // 切换上一张下一张
  65. function handleChangeChart(type){
  66. const index=changeChartList.value.findIndex(e=>e.chartInfoId==chartInfo.value.chartId)
  67. if(type==='pre'){
  68. if(index<1) return Message.warning('当前已是第一张')
  69. const obj=changeChartList.value[index-1]
  70. getChartDetail(obj)
  71. }else{
  72. if(index===changeChartList.value.length-1) return Message.warning('当前已是最后一张')
  73. const obj=changeChartList.value[index+1]
  74. getChartDetail(obj)
  75. }
  76. }
  77. </script>
  78. <template>
  79. <div class="chart-detail-page" v-if="chartInfo">
  80. <div class="chart-title">{{chartInfo.ChartName}}</div>
  81. <div class="collect-icon" @click="handleCollect" >{{chartInfo.IsCollect?'取消收藏':'收藏'}}</div>
  82. <!-- 图表渲染盒子 -->
  83. <div class="chart-render-wrap">
  84. <iframe :src="chartRenderUrl"></iframe>
  85. </div>
  86. <div v-if="chartInfo.SourcesFrom&&JSON.parse(chartInfo.SourcesFrom).text"><span>来源:{{chartInfo.SourcesFrom?JSON.parse(chartInfo.SourcesFrom).text:''}}</span></div>
  87. <div class="change-btns-box" v-if="changeChartList.length>1">
  88. <div class="btn bottom" @click="handleChangeChart('pre')">
  89. <div class="triangle-left"></div>
  90. <div>上一张</div>
  91. </div>
  92. <div class="btn" @click="handleChangeChart('next')">
  93. <div class="triangle-right"></div>
  94. <div>下一张</div>
  95. </div>
  96. </div>
  97. <!-- 收藏 -->
  98. <!-- <svg-icon @click="handleCollect" class="collect-icon" :name="chartInfo.IsCollect?'collected':'collect'" /> -->
  99. </div>
  100. </template>
  101. <style lang="scss" scoped>
  102. .chart-detail-page {
  103. background-color: #fff;
  104. padding: var(--page-padding);
  105. min-height: 100vh;
  106. .chart-title {
  107. font-size: 36px;
  108. line-height: 44px;
  109. margin-bottom: 20px;
  110. }
  111. .mz-tips {
  112. text-align: right;
  113. color: var(--primary-color);
  114. font-size: var(--font-size-small);
  115. }
  116. .chart-render-wrap {
  117. margin-top: 50px;
  118. height: 850px;
  119. margin-bottom: 40px;
  120. iframe {
  121. width: 100%;
  122. height: 100%;
  123. border: none;
  124. }
  125. }
  126. .change-btns-box {
  127. position: fixed;
  128. z-index: 99;
  129. right: 34px;
  130. bottom: 150px;
  131. .btn {
  132. width: 100%;
  133. height: 120px;
  134. background-color: #f3f5f9;
  135. display: flex;
  136. flex-direction: column; /* 垂直方向排列子元素 */
  137. justify-content: center; /* 水平居中(对于列布局,这将使整列居中) */
  138. .triangle-left {
  139. margin: 0 auto;
  140. width: 0;
  141. height: 0;
  142. border-top: 20px solid transparent;
  143. border-right: 40px solid #fff;
  144. border-bottom: 20px solid transparent;
  145. border-left: none;
  146. margin-bottom: 10px;
  147. }
  148. .triangle-right {
  149. margin: 0 auto;
  150. width: 0;
  151. height: 0;
  152. border-top: 20px solid transparent;
  153. border-left: 40px solid #fff;
  154. border-bottom: 20px solid transparent;
  155. border-right: none;
  156. margin-bottom: 10px;
  157. }
  158. }
  159. .bottom {
  160. border-bottom: #666666 1px solid;
  161. }
  162. }
  163. }
  164. .collect-icon {
  165. color: #666666;
  166. }
  167. @media (min-width: 600px) {
  168. .chart-detail-page {
  169. min-height: 100vh;
  170. .chart-title {
  171. font-size: 18px;
  172. line-height: 22px;
  173. margin-bottom: 10px;
  174. }
  175. .chart-render-wrap {
  176. margin-top: 25px;
  177. height: 400px;
  178. }
  179. .change-btns-box{
  180. bottom: 35px;
  181. justify-content: center;
  182. gap: 0 10px;
  183. .btn{
  184. max-width: 200px;
  185. height: 34px;
  186. border-radius: 34px;
  187. line-height: 34px;
  188. }
  189. }
  190. }
  191. .collect-icon{
  192. color: #666666;
  193. }
  194. }
  195. </style>