codeHtml.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <!--扫码展示-->
  2. <template>
  3. <div id="codeHtml"
  4. v-loading="loading">
  5. <div class="w-e-text w-e-text-box" 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. videoSrc:require('@/assets/ZDimages/video_bg.png')
  49. };
  50. },
  51. created() {
  52. },
  53. mounted(){
  54. this.code = this.$route.query.code;
  55. this.type = this.$route.query.type;
  56. if(this.$route.query.code&&this.$route.query.type){
  57. this.loading = true;
  58. if(this.$route.query.type==1){
  59. //查询危险化学品详情
  60. this.hazard_book_lookUp(this.$route.query.code);
  61. }else if(this.$route.query.type==2){
  62. //查询安全管理制度
  63. this.safe_book(this.$route.query.code);
  64. }else if(this.$route.query.type==3){
  65. //查询危险源
  66. this.hazardLookUp(this.$route.query.code);
  67. }
  68. }
  69. let video = document.getElementsByClassName('video-js')[0];
  70. video.setAttribute('poster',this.videoSrc);
  71. },
  72. methods: {
  73. //加载接口
  74. hazard_book_lookUp(id){
  75. hazard_book_lookUp(id).then( data => {
  76. this.text = unescape(data.data.content);
  77. this.loading = false;
  78. });
  79. },
  80. safe_book(id){
  81. safe_book(id).then( data => {
  82. this.form.content = window.location.href.split('://')[0]+'://' + this.judgmentNetworkReturnAddress() + '/' + unescape(data.data.content);
  83. this.getNumPages();
  84. });
  85. },
  86. hazardLookUp(id){
  87. hazardLookUp(id).then( data => {
  88. this.text = unescape(data.data.content);
  89. // let list = this.text.split('font-size:');
  90. // let newText = "";
  91. // for (let i=0;i<list.length;i++){
  92. // if(
  93. // (list[i][0] == '0' || list[i][0] == '1' || list[i][0] == '2' || list[i][0] == '3' || list[i][0] == '4' || list[i][0] == '5' || list[i][0] == '6' || list[i][0] == '7' || list[i][0] == '8' || list[i][0] == '9')&&
  94. // (list[i][1] == 'p')&&
  95. // (list[i][2] == 'x')
  96. // ){
  97. // let num = this.accMul(parseInt(list[i][0]),6);
  98. // num = num>140?140:num;
  99. // let textNew = list[i].slice(1)
  100. // newText = newText + 'font-size:'+num+textNew;
  101. // }else if(
  102. // (list[i][0] == ' ')&&
  103. // (list[i][1] == '0' || list[i][1] == '1' || list[i][1] == '2' || list[i][1] == '3' || list[i][1] == '4' || list[i][1] == '5' || list[i][1] == '6' || list[i][1] == '7' || list[i][1] == '8' || list[i][1] == '9')&&
  104. // (list[i][2] == 'p')&&
  105. // (list[i][3] == 'x')
  106. // ){
  107. // let num = this.accMul(parseInt(list[i][1]),6);
  108. // num = num>140?140:num;
  109. // let textNew = list[i].slice(2)
  110. // newText = newText + 'font-size:'+num+textNew;
  111. // }else if(
  112. // (list[i][0] == '0' || list[i][0] == '1' || list[i][0] == '2' || list[i][0] == '3' || list[i][0] == '4' || list[i][0] == '5' || list[i][0] == '6' || list[i][0] == '7' || list[i][0] == '8' || list[i][0] == '9')&&
  113. // (list[i][1] == '0' || list[i][1] == '1' || list[i][1] == '2' || list[i][1] == '3' || list[i][1] == '4' || list[i][1] == '5' || list[i][1] == '6' || list[i][1] == '7' || list[i][1] == '8' || list[i][1] == '9')&&
  114. // (list[i][2] == 'p')&&
  115. // (list[i][3] == 'x')
  116. // ){
  117. // let num = this.accMul(parseInt(list[i][0]+list[i][1]),6);
  118. // num = num>140?140:num;
  119. // let textNew = list[i].slice(2)
  120. // newText = newText + 'font-size:'+num+textNew;
  121. // }else if(
  122. // (list[i][0] == ' ')&&
  123. // (list[i][1] == '0' || list[i][1] == '1' || list[i][1] == '2' || list[i][1] == '3' || list[i][1] == '4' || list[i][1] == '5' || list[i][1] == '6' || list[i][1] == '7' || list[i][1] == '8' || list[i][1] == '9')&&
  124. // (list[i][2] == '0' || list[i][2] == '1' || list[i][2] == '2' || list[i][2] == '3' || list[i][2] == '4' || list[i][2] == '5' || list[i][2] == '6' || list[i][2] == '7' || list[i][2] == '8' || list[i][2] == '9')&&
  125. // (list[i][3] == 'p')&&
  126. // (list[i][4] == 'x')
  127. // ){
  128. // let num = this.accMul(parseInt(list[i][1]+list[i][2]),6);
  129. // num = num>140?140:num;
  130. // let textNew = list[i].slice(3)
  131. // newText = newText + 'font-size:'+num+textNew;
  132. // }else if(
  133. // (list[i][0] == '0' || list[i][0] == '1' || list[i][0] == '2' || list[i][0] == '3' || list[i][0] == '4' || list[i][0] == '5' || list[i][0] == '6' || list[i][0] == '7' || list[i][0] == '8' || list[i][0] == '9')&&
  134. // (list[i][1] == '0' || list[i][1] == '1' || list[i][1] == '2' || list[i][1] == '3' || list[i][1] == '4' || list[i][1] == '5' || list[i][1] == '6' || list[i][1] == '7' || list[i][1] == '8' || list[i][1] == '9')&&
  135. // (list[i][2] == '0' || list[i][2] == '1' || list[i][2] == '2' || list[i][2] == '3' || list[i][2] == '4' || list[i][2] == '5' || list[i][2] == '6' || list[i][2] == '7' || list[i][2] == '8' || list[i][2] == '9')&&
  136. // (list[i][3] == 'p')&&
  137. // (list[i][4] == 'x')
  138. // ){
  139. // let num = this.accMul(parseInt(list[i][0]+list[i][1]+list[i][2]),6);
  140. // num = num>140?140:num;
  141. // let textNew = list[i].slice(3)
  142. // newText = newText + 'font-size:'+num+textNew;
  143. // }else if(
  144. // (list[i][0] == ' ')&&
  145. // (list[i][1] == '0' || list[i][1] == '1' || list[i][1] == '2' || list[i][1] == '3' || list[i][1] == '4' || list[i][1] == '5' || list[i][1] == '6' || list[i][1] == '7' || list[i][1] == '8' || list[i][1] == '9')&&
  146. // (list[i][2] == '0' || list[i][2] == '1' || list[i][2] == '2' || list[i][2] == '3' || list[i][2] == '4' || list[i][2] == '5' || list[i][2] == '6' || list[i][2] == '7' || list[i][2] == '8' || list[i][2] == '9')&&
  147. // (list[i][3] == '0' || list[i][3] == '1' || list[i][3] == '2' || list[i][3] == '3' || list[i][3] == '4' || list[i][3] == '5' || list[i][3] == '6' || list[i][3] == '7' || list[i][3] == '8' || list[i][3] == '9')&&
  148. // (list[i][4] == 'p')&&
  149. // (list[i][5] == 'x')
  150. // ){
  151. // let num = this.accMul(parseInt(list[i][1]+list[i][2]+list[i][3]),6);
  152. // num = num>140?140:num;
  153. // let textNew = list[i].slice(4)
  154. // newText = newText + 'font-size:'+num+textNew;
  155. // }else{
  156. // newText = newText + list[i]
  157. // }
  158. // }
  159. // list = newText.split('line-height:');
  160. // newText = "";
  161. // for (let i=0;i<list.length;i++){
  162. // if(
  163. // (list[i][0] == '0' || list[i][0] == '1' || list[i][0] == '2' || list[i][0] == '3' || list[i][0] == '4' || list[i][0] == '5' || list[i][0] == '6' || list[i][0] == '7' || list[i][0] == '8' || list[i][0] == '9')&&
  164. // (list[i][1] == 'p')&&
  165. // (list[i][2] == 'x')
  166. // ){
  167. // let num = this.accMul(parseInt(list[i][0]),6);
  168. // num = num>140?140:num;
  169. // let textNew = list[i].slice(1)
  170. // newText = newText + 'line-height:'+num+textNew;
  171. // }else if(
  172. // (list[i][0] == ' ')&&
  173. // (list[i][1] == '0' || list[i][1] == '1' || list[i][1] == '2' || list[i][1] == '3' || list[i][1] == '4' || list[i][1] == '5' || list[i][1] == '6' || list[i][1] == '7' || list[i][1] == '8' || list[i][1] == '9')&&
  174. // (list[i][2] == 'p')&&
  175. // (list[i][3] == 'x')
  176. // ){
  177. // let num = this.accMul(parseInt(list[i][1]),6);
  178. // num = num>140?140:num;
  179. // let textNew = list[i].slice(2)
  180. // newText = newText + 'line-height:'+num+textNew;
  181. // }else if(
  182. // (list[i][0] == '0' || list[i][0] == '1' || list[i][0] == '2' || list[i][0] == '3' || list[i][0] == '4' || list[i][0] == '5' || list[i][0] == '6' || list[i][0] == '7' || list[i][0] == '8' || list[i][0] == '9')&&
  183. // (list[i][1] == '0' || list[i][1] == '1' || list[i][1] == '2' || list[i][1] == '3' || list[i][1] == '4' || list[i][1] == '5' || list[i][1] == '6' || list[i][1] == '7' || list[i][1] == '8' || list[i][1] == '9')&&
  184. // (list[i][2] == 'p')&&
  185. // (list[i][3] == 'x')
  186. // ){
  187. // let num = this.accMul(parseInt(list[i][0]+list[i][1]),6);
  188. // num = num>140?140:num;
  189. // let textNew = list[i].slice(2)
  190. // newText = newText + 'line-height:'+num+textNew;
  191. // }else if(
  192. // (list[i][0] == ' ')&&
  193. // (list[i][1] == '0' || list[i][1] == '1' || list[i][1] == '2' || list[i][1] == '3' || list[i][1] == '4' || list[i][1] == '5' || list[i][1] == '6' || list[i][1] == '7' || list[i][1] == '8' || list[i][1] == '9')&&
  194. // (list[i][2] == '0' || list[i][2] == '1' || list[i][2] == '2' || list[i][2] == '3' || list[i][2] == '4' || list[i][2] == '5' || list[i][2] == '6' || list[i][2] == '7' || list[i][2] == '8' || list[i][2] == '9')&&
  195. // (list[i][3] == 'p')&&
  196. // (list[i][4] == 'x')
  197. // ){
  198. // let num = this.accMul(parseInt(list[i][1]+list[i][2]),6);
  199. // num = num>140?140:num;
  200. // let textNew = list[i].slice(3)
  201. // newText = newText + 'line-height:'+num+textNew;
  202. // }else if(
  203. // (list[i][0] == '0' || list[i][0] == '1' || list[i][0] == '2' || list[i][0] == '3' || list[i][0] == '4' || list[i][0] == '5' || list[i][0] == '6' || list[i][0] == '7' || list[i][0] == '8' || list[i][0] == '9')&&
  204. // (list[i][1] == '0' || list[i][1] == '1' || list[i][1] == '2' || list[i][1] == '3' || list[i][1] == '4' || list[i][1] == '5' || list[i][1] == '6' || list[i][1] == '7' || list[i][1] == '8' || list[i][1] == '9')&&
  205. // (list[i][2] == '0' || list[i][2] == '1' || list[i][2] == '2' || list[i][2] == '3' || list[i][2] == '4' || list[i][2] == '5' || list[i][2] == '6' || list[i][2] == '7' || list[i][2] == '8' || list[i][2] == '9')&&
  206. // (list[i][3] == 'p')&&
  207. // (list[i][4] == 'x')
  208. // ){
  209. // let num = this.accMul(parseInt(list[i][0]+list[i][1]+list[i][2]),6);
  210. // num = num>140?140:num;
  211. // let textNew = list[i].slice(3)
  212. // newText = newText + 'line-height:'+num+textNew;
  213. // }else if(
  214. // (list[i][0] == ' ')&&
  215. // (list[i][1] == '0' || list[i][1] == '1' || list[i][1] == '2' || list[i][1] == '3' || list[i][1] == '4' || list[i][1] == '5' || list[i][1] == '6' || list[i][1] == '7' || list[i][1] == '8' || list[i][1] == '9')&&
  216. // (list[i][2] == '0' || list[i][2] == '1' || list[i][2] == '2' || list[i][2] == '3' || list[i][2] == '4' || list[i][2] == '5' || list[i][2] == '6' || list[i][2] == '7' || list[i][2] == '8' || list[i][2] == '9')&&
  217. // (list[i][3] == '0' || list[i][3] == '1' || list[i][3] == '2' || list[i][3] == '3' || list[i][3] == '4' || list[i][3] == '5' || list[i][3] == '6' || list[i][3] == '7' || list[i][3] == '8' || list[i][3] == '9')&&
  218. // (list[i][4] == 'p')&&
  219. // (list[i][5] == 'x')
  220. // ){
  221. // let num = this.accMul(parseInt(list[i][1]+list[i][2]+list[i][3]),6);
  222. // num = num>140?140:num;
  223. // let textNew = list[i].slice(4)
  224. // newText = newText + 'line-height:'+num+textNew;
  225. // }else{
  226. // newText = newText + list[i]
  227. // }
  228. // }
  229. // this.$set(this,'text',newText);
  230. this.loading = false;
  231. });
  232. },
  233. getNumPages() {
  234. let loadingTask = pdf.createLoadingTask(this.form.content)
  235. loadingTask.promise.then(pdf => {
  236. this.numPages = pdf.numPages;
  237. this.loading = false;
  238. }).catch(err => {
  239. console.error('pdf 加载失败', err);
  240. })
  241. },
  242. //pdf方法
  243. changePdfPage (val) {
  244. // console.log(val)
  245. if (val === 0 && this.currentPage > 1) {
  246. this.currentPage--
  247. // console.log(this.currentPage)
  248. }
  249. if (val === 1 && this.currentPage < this.pageCount) {
  250. this.currentPage++
  251. // console.log(this.currentPage)
  252. }
  253. },
  254. // pdf加载时
  255. loadPdfHandler (e) {
  256. this.currentPage = 1 // 加载的时候先加载第一页
  257. },
  258. accMul(arg1,arg2){
  259. var m=0,s1=arg1.toString(),s2=arg2.toString();
  260. try{m+=s1.split(".")[1].length}catch(e){}
  261. try{m+=s2.split(".")[1].length}catch(e){}
  262. return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m)
  263. },
  264. }
  265. };
  266. </script>
  267. <style lang="scss">
  268. #codeHtml{
  269. video{
  270. width:100%!important;
  271. /*object-fit: fill;*/
  272. height:100%!important;
  273. /*display: block;*/
  274. border: 12px solid #e0e0e0;
  275. }
  276. img{
  277. width:100%!important;
  278. height:100%!important;
  279. /*width:1500px;*/
  280. /*margin:20px 200px;*/
  281. }
  282. }
  283. </style>
  284. <style scoped lang="scss">
  285. #codeHtml {
  286. height:100%;
  287. overflow:hidden;
  288. display: flex;
  289. flex-direction: column;
  290. font-size:16px;
  291. *{
  292. margin:0;
  293. padding:0;
  294. }
  295. .pdf-max-box{
  296. flex:1;
  297. overflow-y: scroll;
  298. }
  299. .top-button-box{
  300. width:100%;
  301. display: flex;
  302. .null-p{
  303. flex:1;
  304. }
  305. }
  306. .w-e-text{
  307. flex:1;
  308. overflow-x: hidden;
  309. overflow-y: scroll;
  310. padding:8px;
  311. font-size:16px;
  312. }
  313. .w-e-text.table::-webkit-scrollbar{
  314. width: 4px; /*高宽分别对应横竖滚动条的尺寸*/
  315. height: 4px;
  316. }
  317. .w-e-text.table::-webkit-scrollbar-thumb{
  318. border-radius: 5px;
  319. -webkit-box-shadow: inset 0 0 5px #999;
  320. background: #fff;
  321. }
  322. .w-e-text.table::-webkit-scrollbar-track{
  323. -webkit-box-shadow: inset 0 0 5px rgba(255,255,255,0);
  324. border-radius: 0;
  325. background: rgba(255,255,255,0);
  326. }
  327. }
  328. </style>