fileView.vue 3.7 KB

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