detailPdf.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <!-- 原项目丢了 省事直接cv一下老项目代码 -->
  2. <template>
  3. <div class="wrapper" ref="wrapper" id="pdf-container">
  4. <div id="reportdtl" v-if="isshow" :style="{backgroundColor:reportInfo.CanvasColor}">
  5. <div>
  6. <div class="html-head-img-box" v-if="reportInfo && !!reportInfo.NeedSplice && reportInfo.HeadImg">
  7. <img :src="reportInfo.HeadImg" alt="" style="display:block;width:100%">
  8. <div class="head-layout-item" v-for="item in headImgStyle" :key="item.value"
  9. :style="{fontFamily:item.family,fontSize:(item.size*2)+'px',fontWeight:item.weight,textAlign:item.align,color:item.color,
  10. width:item.width,height:item.height,left:item.left,top:item.top
  11. }">
  12. {{ layoutBaseInfo[item.value] }}
  13. </div>
  14. </div>
  15. <div class="no-layout-img-box" v-if="reportInfo && !!reportInfo.NeedSplice && (!reportInfo.HeadImg) && (!reportInfo.EndImg)">
  16. <header>{{reportInfo.Title}}</header>
  17. <div style=" box-sizing:border-box; color:#666; font-size:24px; overflow:hidden;">
  18. <span>{{ reportInfo.Author}}</span>
  19. <span style="float:right;" v-if="[2,6].includes(reportInfo.State)">{{reportInfo.PublishTime}}</span>
  20. </div>
  21. </div>
  22. <div class="abstract" v-if="reportInfo && !!reportInfo.NeedSplice">
  23. <div v-if="reportInfo.Abstract">摘要: <span v-html="reportInfo.Abstract"></span></div>
  24. </div>
  25. <div id="resetcss" style="overflow:hidden;" v-html="reportInfo.Content"></div>
  26. <div class="html-end-img-box" v-if="reportInfo && !!reportInfo.NeedSplice && reportInfo.EndImg">
  27. <img :src="reportInfo.EndImg" alt="" style="display:block;width:100%">
  28. <div class="head-layout-item" v-for="item in endImgStyle" :key="item.value"
  29. :style="{fontFamily:item.family,fontSize:(item.size*2)+'px',fontWeight:item.weight,textAlign:item.align,color:item.color,
  30. width:item.width,height:item.height,left:item.left,top:item.top
  31. }">
  32. {{ layoutBaseInfo[item.value] }}
  33. </div>
  34. </div>
  35. </div>
  36. </div>
  37. </div>
  38. </template>
  39. <script>
  40. import { smartReportDetail } from "@/api/api.js";
  41. export default {
  42. data() {
  43. return {
  44. id: this.$route.query.code || "",
  45. isshow: false,
  46. /**
  47. * NeedSplice 0-不需要 1-需要
  48. */
  49. reportInfo: {},
  50. headImgStyle:null,//版头style
  51. endImgStyle:null,//版尾style
  52. layoutBaseInfo:{
  53. 研报标题:'',
  54. 研报作者:'',
  55. 创建时间:''
  56. }
  57. };
  58. },
  59. mounted() {
  60. this.getreportdetail();
  61. window.addEventListener('resize',this.pageResize)
  62. },
  63. destroyed() {
  64. window.removeEventListener('resize',this.pageResize)
  65. },
  66. methods: {
  67. pageResize(){
  68. const el=document.getElementById('reportdtl')
  69. const windowWid=document.body.clientWidth
  70. if(windowWid<800){
  71. el.style.transform=`scale(${windowWid/800})`
  72. // el.style.
  73. }
  74. },
  75. async getreportdetail() {
  76. const { Data, Ret } = await smartReportDetail({ ReportCode: this.id });
  77. if (Ret !== 200) return;
  78. this.reportInfo = Data.Report;
  79. this.headImgStyle=this.reportInfo.HeadStyle?JSON.parse(this.reportInfo.HeadStyle):[]
  80. this.endImgStyle=this.reportInfo.EndStyle?JSON.parse(this.reportInfo.EndStyle):[]
  81. this.layoutBaseInfo['研报标题']=this.reportInfo.Title
  82. this.layoutBaseInfo['研报作者']=this.reportInfo.Author
  83. // 已发布已通过的报告才显示发布时间
  84. this.layoutBaseInfo['创建时间']=[2,6].includes(this.reportInfo.State)?this.reportInfo.PublishTime:''
  85. this.reportInfo.Content=this.setReportContent(this.reportInfo.Content)
  86. this.isshow = true;
  87. this.$nextTick(()=>{
  88. this.pageResize()
  89. })
  90. },
  91. setReportContent(str){
  92. let ps = str.split('</iframe>')
  93. let returnStr=''
  94. for (let i = 0; i < ps.length; i++) {
  95. const itp = ps[i];
  96. if(itp.indexOf('chartshow')!=-1){
  97. returnStr+=itp.replace('<iframe','<eta-chart class="no-wrap"')+'</eta-chart>'
  98. }else if(itp.indexOf('sheetshow')!=-1){
  99. returnStr+=itp.replace('<iframe','<eta-table class="no-wrap"')+'</eta-table>'
  100. }else{
  101. returnStr+=itp
  102. }
  103. }
  104. return returnStr
  105. },
  106. },
  107. };
  108. </script>
  109. <style lang="scss">
  110. body{
  111. line-height: normal;
  112. }
  113. .wrapper {
  114. position: relative;
  115. height: 100%;
  116. #noaccess {
  117. width: 100%;
  118. height: 12rem;
  119. padding: 5rem 0.6rem 1rem;
  120. box-sizing: border-box;
  121. text-align: center;
  122. position: absolute;
  123. bottom: 0;
  124. background: url(~@/assets/img/accessbg.png) no-repeat;
  125. background-size: 100% auto;
  126. overflow: hidden;
  127. > a,
  128. button {
  129. width: 12rem;
  130. height: 2rem;
  131. background: url(~@/assets/img/newbtn600.png) no-repeat;
  132. background-size: 100% 100%;
  133. font-size: 0.48rem;
  134. color: #fff;
  135. border: none;
  136. margin-top: 1.5rem;
  137. }
  138. }
  139. }
  140. #reportdtl {
  141. font-size: 14px;
  142. background: #fff;
  143. overflow: auto;
  144. width: 800px;
  145. padding: 20px;
  146. margin: 0 auto;
  147. .top-header {
  148. background-image: url("@/assets/img/smart_report_bg01.png");
  149. background-size: cover;
  150. background-repeat: no-repeat;
  151. background-position: center;
  152. padding: 16px;
  153. color: #fff;
  154. .title {
  155. font-size: 16px;
  156. margin-bottom: 10px;
  157. }
  158. .flex {
  159. font-size: 12px;
  160. display: flex;
  161. justify-content: space-between;
  162. }
  163. }
  164. .html-head-img-box,.html-end-img-box{
  165. position: relative;
  166. overflow: hidden;
  167. .head-layout-item{
  168. position: absolute;
  169. overflow: hidden;
  170. box-sizing: border-box
  171. }
  172. }
  173. .no-layout-img-box{
  174. header{
  175. padding:10px 0; box-sizing:border-box; font-size:28px; font-weight:500; color:#333; background:#fff;
  176. }
  177. }
  178. .abstract{
  179. padding:10px 0; box-sizing:border-box; font-size:22px; line-height:36px;
  180. div{
  181. padding: 10px 20px;
  182. box-sizing: border-box;
  183. background: rgba(20, 121, 253, 0.1);
  184. color: #4099ef;
  185. border-radius: 10px;
  186. }
  187. }
  188. #resetcss {
  189. pre {
  190. white-space: pre-wrap;
  191. }
  192. .report-drag-item-wrap{
  193. padding: 6px;
  194. margin-bottom: 3px;
  195. }
  196. }
  197. }
  198. @media screen and (max-width:800px){
  199. #reportdtl{
  200. position: absolute;
  201. transform-origin: 0 0;
  202. }
  203. }
  204. // 不禁止页面打印,不然转pdf会出现空白页
  205. @media print{
  206. body{
  207. display: unset;
  208. }
  209. }
  210. </style>