codeHtml.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <!--扫码展示-->
  2. <template>
  3. <div id="codeHtml"
  4. v-loading="loading">
  5. <div class="w-e-text" v-html="text" v-if="type==1"></div>
  6. <div v-if="type==2" class="pdf-max-box">
  7. <!--<pdf-->
  8. <!--ref="pdf"-->
  9. <!--:src="src"-->
  10. <!--v-for="i in numPages"-->
  11. <!--:key="i"-->
  12. <!--:page="i"-->
  13. <!--&gt;-->
  14. <!--</pdf>-->
  15. <pdf
  16. ref="pdf"
  17. :src="form.content"
  18. v-for="i in numPages"
  19. :key="i"
  20. :page="i"
  21. >
  22. </pdf>
  23. </div>
  24. <div class="w-e-text" v-html="text" v-if="type==3"></div>
  25. </div>
  26. </template>
  27. <script>
  28. import { hazard_book_lookUp,safe_book,hazardLookUp } from "@/api/codeHtml/index";
  29. import pdf from 'vue-pdf'
  30. export default {
  31. components:{
  32. pdf
  33. },
  34. name: "codeHtml",
  35. data() {
  36. return {
  37. //状态数据相关
  38. code:"",
  39. type:"",
  40. //富文本相关
  41. text:"",
  42. //pdf相关
  43. numPages: null, // pdf 总页数
  44. form:{},
  45. src: '', // pdf文件地址
  46. // 加载样式
  47. loading:false,
  48. };
  49. },
  50. created() {
  51. },
  52. mounted(){
  53. this.code = this.$route.query.code;
  54. this.type = this.$route.query.type;
  55. if(this.$route.query.code&&this.$route.query.type){
  56. this.loading = true;
  57. if(this.$route.query.type==1){
  58. //查询危险化学品详情
  59. this.hazard_book_lookUp(this.$route.query.code);
  60. }else if(this.$route.query.type==2){
  61. //查询安全管理制度
  62. this.safe_book(this.$route.query.code);
  63. }else if(this.$route.query.type==3){
  64. //查询危险源
  65. this.hazardLookUp(this.$route.query.code);
  66. }
  67. }
  68. },
  69. methods: {
  70. //加载接口
  71. hazard_book_lookUp(id){
  72. hazard_book_lookUp(id).then( data => {
  73. console.log('1',unescape(data.data.content))
  74. this.text = unescape(data.data.content);
  75. console.log('2',this.form.content)
  76. this.loading = false;
  77. });
  78. },
  79. safe_book(id){
  80. safe_book(id).then( data => {
  81. console.log('1',unescape(data.data.content))
  82. this.form.content = window.location.href.split('://')[0]+'://' + process.env.VUE_APP_BASE_API + '/' + unescape(data.data.content);
  83. console.log('2',this.form.content)
  84. this.getNumPages();
  85. });
  86. },
  87. hazardLookUp(id){
  88. hazardLookUp(id).then( data => {
  89. console.log('1',unescape(data.data.content))
  90. this.text = unescape(data.data.content);
  91. console.log('2',this.form.content)
  92. this.loading = false;
  93. });
  94. },
  95. getNumPages() {
  96. let loadingTask = pdf.createLoadingTask(this.form.content)
  97. loadingTask.promise.then(pdf => {
  98. this.numPages = pdf.numPages;
  99. this.loading = false;
  100. }).catch(err => {
  101. console.error('pdf 加载失败', err);
  102. })
  103. },
  104. //pdf方法
  105. changePdfPage (val) {
  106. // console.log(val)
  107. if (val === 0 && this.currentPage > 1) {
  108. this.currentPage--
  109. // console.log(this.currentPage)
  110. }
  111. if (val === 1 && this.currentPage < this.pageCount) {
  112. this.currentPage++
  113. // console.log(this.currentPage)
  114. }
  115. },
  116. // pdf加载时
  117. loadPdfHandler (e) {
  118. this.currentPage = 1 // 加载的时候先加载第一页
  119. }
  120. }
  121. };
  122. </script>
  123. <style scoped lang="scss">
  124. #codeHtml {
  125. height:100%;
  126. overflow:hidden;
  127. display: flex;
  128. flex-direction: column;
  129. .pdf-max-box{
  130. flex:1;
  131. overflow-y: scroll;
  132. }
  133. .top-button-box{
  134. width:100%;
  135. display: flex;
  136. .null-p{
  137. flex:1;
  138. }
  139. }
  140. .w-e-text{
  141. flex:1;
  142. }
  143. .w-e-text.table::-webkit-scrollbar{
  144. width: 4px; /*高宽分别对应横竖滚动条的尺寸*/
  145. height: 4px;
  146. }
  147. .w-e-text.table::-webkit-scrollbar-thumb{
  148. border-radius: 5px;
  149. -webkit-box-shadow: inset 0 0 5px #999;
  150. background: #fff;
  151. }
  152. .w-e-text.table::-webkit-scrollbar-track{
  153. -webkit-box-shadow: inset 0 0 5px rgba(255,255,255,0);
  154. border-radius: 0;
  155. background: rgba(255,255,255,0);
  156. }
  157. }
  158. </style>