fileView.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <view class="container">
  3. <!-- <cu-custom bgColor="bg-gradual-pink" :isBack="true">
  4. <block slot="backText">返回</block>
  5. <block slot="content">检测报告</block>
  6. </cu-custom> -->
  7. <web-view :src="pdfUrl"></web-view>
  8. <!-- <view style="position: fixed;top: 15rpx;right: 50rpx;z-index: 999;color: #ffffff;">55555</view> -->
  9. </view>
  10. </template>
  11. <script>
  12. import http from "@/common/service/http.js"
  13. import md5 from "@/common/util/md5.js"
  14. export default {
  15. data() {
  16. return {
  17. pdfUrl: '',
  18. from: 'app',
  19. type: '1'
  20. }
  21. },
  22. created() {
  23. let url = window.location.href
  24. let urlOne = url.split('#')[1]
  25. let urlTwo = urlOne.split('?')[1]
  26. let urlThree = urlTwo.split('=')
  27. if (urlThree[0] == 'url') {
  28. this.pdfUrl = '/hybrid/html/web/viewer.html?file=' + decodeURIComponent(urlThree[1])
  29. // this.pdfUrl = '/hybrid/html/web/viewer.html?file=' + encodeURIComponent(decodeURIComponent(urlThree[1]))
  30. }
  31. },
  32. mounted() {
  33. window.addEventListener('mousedown', this.handleonmousedown)
  34. },
  35. onLoad(option) {
  36. if (!option.url) {
  37. if (option.type) {
  38. this.type = option.type
  39. }
  40. if (this.type == 1) {
  41. this.getDe(option.id)
  42. } else {
  43. this.getDe2(option.id)
  44. }
  45. }
  46. },
  47. methods: {
  48. handleonmousedown(e) {
  49. console.log(e)
  50. },
  51. /**
  52. * 根据报告的id查询没有盖章文档路径
  53. */
  54. getDe(id) {
  55. let access_token = uni.getStorageSync('Access-Token')
  56. console.log(access_token)
  57. let sql =
  58. `{"sql":"select FILE_PATH_ from ibps_file_attachment WHERE id_ = (SELECT bao_gao_pdf_ FROM t_lhjcbgb WHERE id_ = '${id}')"}`
  59. let md5 = this.sig(sql) //加密, 获取md5密文
  60. let requestData = sql.slice(0, 1) + '"sig":"' + md5 + '",' + sql.slice(1) //结果拼接
  61. this.$http.post("/ibps/business/v3/sys/universal/inputSqlSelectData", requestData).then(res => {
  62. if (res.data.state == 200) {
  63. const data = res.data.variables.data
  64. if (data.length > 0) {
  65. let dataItem = data[0]
  66. let url =
  67. http.apiHosp + dataItem.FILE_PATH_
  68. // this.pdfUrl = '/hybrid/html/web/viewer.html?file=' + encodeURIComponent(url)
  69. this.pdfUrl = '/hybrid/html/web/viewer.html?file=' + url
  70. }
  71. }
  72. })
  73. },
  74. /**
  75. * 根据报告的id查询有盖章文档路径
  76. */
  77. getDe2(id) {
  78. let access_token = uni.getStorageSync('Access-Token')
  79. console.log(access_token)
  80. let sql =
  81. `{"sql":"select FILE_PATH_ from ibps_file_attachment WHERE id_ = (SELECT bao_gao_pdf_ FROM t_lhjcbgb WHERE id_ = '${id}')"}`
  82. let md5 = this.sig(sql) //加密, 获取md5密文
  83. let requestData = sql.slice(0, 1) + '"sig":"' + md5 + '",' + sql.slice(1) //结果拼接
  84. this.$http.post("/ibps/business/v3/sys/universal/inputSqlSelectData", requestData).then(res => {
  85. if (res.data.state == 200) {
  86. const data = res.data.variables.data
  87. if (data.length > 0) {
  88. let dataItem = data[0]
  89. let url =
  90. http.apiHosp + dataItem.FILE_PATH_
  91. console.log(url)
  92. this.pdfUrl = '/hybrid/html/web/viewer.html?file=' + encodeURIComponent(url)
  93. }
  94. }
  95. })
  96. },
  97. /**
  98. * 下载情景
  99. */
  100. downloadPdfClick() {
  101. // 下载情景1:h5内嵌app,通过分享给朋友的方式进行下载
  102. if (this.from == 'app') {
  103. let item = http.apiHosp + 'h5/hybrid/html/web/pdf.html?shareUrl=' + encodeURIComponent(
  104. this
  105. .bgUrl) +
  106. '&shareTitle=PDF文件';
  107. window.open(item);
  108. return;
  109. } else if (this.from == 'wx wq') {
  110. // 下载情景2:h5内嵌微信小程序,从h5页面跳转到小程序页面后,然后通过调用小程序原生API进行下载
  111. // 注意: 先要引入微信jssdk [命令: npm install jweixin-module]
  112. // this.$wx.miniProgram.navigateTo({
  113. // url: '/pages/pdf/pdf_download?pdf='+ encodeURIComponent(this.bgUrl) //小程序页面链接
  114. // });
  115. }
  116. },
  117. sig(sql) {
  118. let rul = (sql.length + 9) * 12 * 3 + 168
  119. let salt = "JinYuanXinTong"
  120. return md5(rul + '' + salt)
  121. }
  122. }
  123. }
  124. </script>
  125. <style>
  126. </style>