reportDetailPdf.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. <!-- 原项目丢了 省事直接cv一下老项目代码 -->
  2. <template>
  3. <div class="wrapper" ref="wrapper">
  4. <div id="reportdtl" v-if="isshow">
  5. <header>
  6. <p>
  7. <span style="margin-left: -0.45rem"
  8. >{{
  9. reportInfo.Title
  10. }}</span
  11. >
  12. <span v-if="reportInfo.CreateTime"
  13. >({{ reportInfo.CreateTime.substring(5, 7)
  14. }}{{ reportInfo.CreateTime.substring(8, 10) }})</span
  15. >
  16. </p>
  17. <img class="logo" :src="configInfo.ReportLogo" alt="" v-if="configInfo.ReportLogo"/>
  18. </header>
  19. <div
  20. style="
  21. padding: 0rem 0.8rem 0.4rem;
  22. box-sizing: border-box;
  23. color: #666;
  24. font-size: 0.66rem;
  25. overflow: hidden;
  26. "
  27. >
  28. <span>{{ reportInfo.Author }}</span>
  29. <span style="float: right">{{ reportInfo.PublishTime||reportInfo.PrePublishTime }}</span>
  30. </div>
  31. <div id="abstract" v-if="reportInfo.Abstract">
  32. <div class="abstract_cont">
  33. <div>摘要:{{ reportInfo.Abstract }}</div>
  34. </div>
  35. </div>
  36. <div style="padding: 0.6rem; box-sizing: border-box; overflow: hidden">
  37. <!-- 晨报周报 -->
  38. <div class="chapter-wrap" v-if="reportInfo.HasChapter===1">
  39. <div class="chapter-item" v-for="item in reportInfo.ChapterList" :key="item.ReportChapterId">
  40. <div style="margin-bottom:10px">
  41. <span class="type" v-if="item.TypeName">{{item.TypeName}}</span>
  42. <span class="title">{{item.Title}}</span>
  43. </div>
  44. <div id="resetcss" style="overflow:hidden;" v-html="setReportContent(item.Content)"></div>
  45. </div>
  46. </div>
  47. <div id="resetcss" style="overflow:hidden;" v-else>
  48. <div v-html="reportInfo.Content"></div>
  49. </div>
  50. <div class="disclaimer" v-if="configInfo.Disclaimer">
  51. <h3>免责声明:</h3>
  52. <div v-html="configInfo.Disclaimer"></div>
  53. </div>
  54. </div>
  55. </div>
  56. </div>
  57. </template>
  58. <script>
  59. import {
  60. reportDetail,
  61. } from "@/api/api.js";
  62. import { BlindWatermark } from 'watermark-js-plus'
  63. import { Base64 } from 'js-base64';
  64. export default {
  65. data() {
  66. return {
  67. id: this.$route.query.code || '',
  68. isshow: false,
  69. reportInfo: {},
  70. configInfo: {}
  71. };
  72. },
  73. updated() {
  74. // $('#resetcss').css({font:"0.76rem/1.5 '微软雅黑'",color:"#333",letterSpacing:"0.05rem"});
  75. $("#resetcss")
  76. .find("img")
  77. .css({ display: "block", margin: "0 auto", maxWidth: "100%" });
  78. $("#resetcss")
  79. .find("video")
  80. .css({ display: "block", margin: "0 auto", maxWidth: "100%" });
  81. $("#resetcss")
  82. .find("p")
  83. .css({
  84. margin: "0 auto 0",
  85. font: "0.7rem/1.5 'PingFang-SC-Regular'",
  86. color: "#333",
  87. letterSpacing: "0.08rem",
  88. lineHeight: "1.3rem",
  89. wordBreak: 'break-all'
  90. });
  91. $("#resetcss")
  92. .find("span.fr-emoticon")
  93. .css({
  94. width: "20px",
  95. height: "20px",
  96. backgroundRepeat: "no-repeat",
  97. backgroundSize: "cover",
  98. display: "inline-block",
  99. verticalAlign: "middle",
  100. });
  101. $("#resetcss").find("ol").css({ listStyleType: "disc" });
  102. $("#resetcss")
  103. .find("pre")
  104. .css({ display: "block", whiteSpace: "pre-wrap" });
  105. },
  106. mounted() {
  107. this.getreportdetail();
  108. },
  109. methods: {
  110. async getreportdetail() {
  111. const { Data,Ret } = await reportDetail({ ReportCode: this.id,IsReplace:1 });
  112. if (Ret !== 200) return
  113. this.reportInfo = Data.Report;
  114. this.configInfo = {
  115. ...Data,
  116. Report:null
  117. };
  118. this.reportInfo.Content=this.setReportContent(this.reportInfo.Content)
  119. this.isshow = true;
  120. //水印
  121. localStorage.setItem('waterMarkStr',this.$route.query.flag||'')
  122. const temwaterMarkStr=this.$route.query.flag||localStorage.getItem('waterMarkStr')
  123. let waterMarkStr=Base64.decode(temwaterMarkStr)
  124. waterMarkStr=decodeURIComponent(waterMarkStr)
  125. this.$nextTick(()=>{
  126. if(Data.WatermarkReport==='true'){
  127. this.setWaterMark(waterMarkStr)
  128. }
  129. this.setBlindWaterMark(waterMarkStr)
  130. })
  131. },
  132. setReportContent(str){
  133. let ps = str.split('</iframe>')
  134. let returnStr=''
  135. for (let i = 0; i < ps.length; i++) {
  136. const itp = ps[i];
  137. if(itp.indexOf('chartshow')!=-1){
  138. returnStr+=itp.replace('<iframe','<eta-chart class="no-wrap"')+'</eta-chart>'
  139. }else if(itp.indexOf('sheetshow')!=-1){
  140. returnStr+=itp.replace('<iframe','<eta-table class="no-wrap"')+'</eta-table>'
  141. }else{
  142. returnStr+=itp
  143. }
  144. }
  145. return returnStr
  146. },
  147. setWaterMark(str){
  148. const text=str||''
  149. const target=document.getElementById('resetcss')
  150. const canvas = document.createElement("canvas");
  151. const ctx = canvas.getContext("2d");
  152. ctx.font = "18px Arial";
  153. ctx.rotate((-45 * Math.PI) / 200);
  154. ctx.fillStyle='#f1f1f1'
  155. ctx.fillText(text, 30, 200);
  156. ctx.fillText(text, -40, 100);
  157. // 将canvas的内容转换为base64编码
  158. const data = canvas.toDataURL("image/png");
  159. target.style.background = "url(" + data + ") repeat";
  160. },
  161. // 设置水印
  162. setBlindWaterMark(str){
  163. const blindwatermark = new BlindWatermark({
  164. content: str||'',
  165. width: 200,
  166. height: 200,
  167. onSuccess: () => {
  168. // success callback
  169. }
  170. })
  171. blindwatermark.create()
  172. }
  173. },
  174. };
  175. </script>
  176. <style lang="scss">
  177. .wrapper {
  178. position: relative;
  179. overflow: hidden;
  180. height: 100%;
  181. #noaccess {
  182. width: 100%;
  183. height: 12rem;
  184. padding: 5rem 0.6rem 1rem;
  185. box-sizing: border-box;
  186. text-align: center;
  187. position: absolute;
  188. bottom: 0;
  189. background: url(~@/assets/img/accessbg.png) no-repeat;
  190. background-size: 100% auto;
  191. overflow: hidden;
  192. > a,
  193. button {
  194. width: 12rem;
  195. height: 2rem;
  196. background: url(~@/assets/img/newbtn600.png) no-repeat;
  197. background-size: 100% 100%;
  198. font-size: 0.48rem;
  199. color: #fff;
  200. border: none;
  201. margin-top: 1.5rem;
  202. }
  203. }
  204. }
  205. #reportdtl {
  206. background: #fff;
  207. overflow: auto;
  208. max-width: 1200px;
  209. margin: 0 auto;
  210. header {
  211. padding: 0.6rem;
  212. box-sizing: border-box;
  213. text-align: left;
  214. background: #fff;
  215. display: flex;
  216. justify-content: space-between;
  217. p {
  218. font-size: 0.84rem;
  219. font-weight: 600;
  220. color: #000;
  221. }
  222. .logo {
  223. flex-shrink: 0;
  224. height: fit-content;
  225. }
  226. }
  227. #playcon {
  228. padding: 0 0.6rem;
  229. box-sizing: border-box;
  230. background: #fff;
  231. overflow: hidden;
  232. > div {
  233. width: 100%;
  234. height: 2.96rem;
  235. padding: 0.48rem 0.6rem;
  236. box-sizing: border-box;
  237. background: #f1f1f1;
  238. border-radius: 0.2rem;
  239. }
  240. }
  241. #abstract {
  242. padding: 0.6rem;
  243. box-sizing: border-box;
  244. font-size: 0.7rem;
  245. line-height: 1.4rem;
  246. letter-spacing: 0.1rem;
  247. .abstract_cont {
  248. border-left: 0.2rem solid #007aff;
  249. padding: 0.14rem 0.4rem;
  250. box-sizing: border-box;
  251. color: #333;
  252. }
  253. }
  254. #noaccess {
  255. width: 100%;
  256. height: 12rem;
  257. padding: 5rem 0.6rem 1rem;
  258. box-sizing: border-box;
  259. text-align: center;
  260. position: relative;
  261. top: -4rem;
  262. background: url(~@/assets/img/accessbg.png) no-repeat;
  263. background-size: 100% auto;
  264. margin-bottom: -4rem;
  265. overflow: hidden;
  266. > a,
  267. button {
  268. width: 12rem;
  269. height: 2rem;
  270. background: url(~@/assets/img/newbtn600.png) no-repeat;
  271. background-size: 100% 100%;
  272. font-size: 0.48rem;
  273. color: #fff;
  274. border: none;
  275. margin-top: 1.5rem;
  276. }
  277. }
  278. table {
  279. border-top: 1px solid #ccc;
  280. border-left: 1px solid #ccc;
  281. border-collapse: collapse;
  282. th,
  283. td {
  284. border-right: 1px solid #ccc;
  285. border-bottom: 1px solid #ccc;
  286. padding: 0.1rem 0.2rem;
  287. box-sizing: border-box;
  288. }
  289. }
  290. #resetcss {
  291. pre {
  292. white-space: pre-wrap;
  293. }
  294. .no-wrap{
  295. page-break-inside: avoid;
  296. display: block;
  297. }
  298. }
  299. .chapter-wrap{
  300. .chapter-item{
  301. margin-bottom: 20px;
  302. padding-bottom: 20px;
  303. border-bottom: 1px dashed #ccc;
  304. &:last-child {
  305. border-bottom: none;
  306. }
  307. .type{
  308. font-size: 15px;
  309. color: #fff;
  310. padding: 5px 10px;
  311. background-color: #E6A23C;
  312. border-radius: 4px;
  313. }
  314. .title{
  315. font-size: 15px;
  316. margin-left: 10px;
  317. font-weight: bold;
  318. }
  319. }
  320. }
  321. .disclaimer{
  322. margin-top: 30px;
  323. font-size: 0.58rem;
  324. padding: 30px 0;
  325. border-top: 1px solid #ccc;
  326. h3 {
  327. margin-bottom: 20px;
  328. }
  329. }
  330. }
  331. // 不禁止页面打印,不然转pdf会出现空白页
  332. @media print{
  333. body{
  334. display: unset;
  335. }
  336. }
  337. </style>