fileView.vue 3.7 KB

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