| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- <template>
- <view class="container">
- <web-view :src="pdfUrl"></web-view>
- </view>
- </template>
- <script>
- import http from "@/common/service/http.js"
- import md5 from "@/common/util/md5.js"
- export default {
- data() {
- return {
- pdfUrl: '',
- from: 'app',
- type: '1'
- }
- },
- created() {
- let url = window.location.href
- let urlOne = url.split('#')[1]
- let urlTwo = urlOne.split('?')[1]
- let urlThree = urlTwo.split('=')
- if (urlThree[0] == 'url') {
- this.pdfUrl = '/hybrid/html/web/viewer.html?file=' + decodeURIComponent(urlThree[1])
- // this.pdfUrl = '/hybrid/html/web/viewer.html?file=' + encodeURIComponent(decodeURIComponent(urlThree[1]))
- }
- },
- mounted() {
- window.addEventListener('mousedown', this.handleonmousedown)
- },
- onLoad(option) {
- if (!option.url) {
- if (option.type) {
- this.type = option.type
- }
- if (this.type == 1) {
- this.getDe(option.id)
- } else {
- this.getDe2(option.id)
- }
- }
- },
- methods: {
- handleonmousedown(e) {
- console.log(e)
- },
- /**
- * 根据报告的id查询没有盖章文档路径
- */
- getDe(id) {
- let access_token = uni.getStorageSync('Access-Token')
- console.log(access_token)
- let sql =
- `{"sql":"select FILE_PATH_ from ibps_file_attachment WHERE id_ = (SELECT bao_gao_pdf_ FROM t_lhjcbgb WHERE id_ = '${id}')"}`
- let md5 = this.sig(sql) //加密, 获取md5密文
- let requestData = sql.slice(0, 1) + '"sig":"' + md5 + '",' + sql.slice(1) //结果拼接
- this.$http.post("/ibps/business/v3/sys/universal/inputSqlSelectData", requestData).then(res => {
- if (res.data.state == 200) {
- const data = res.data.variables.data
- if (data.length > 0) {
- let dataItem = data[0]
- let url =
- http.apiHosp + dataItem.FILE_PATH_
- // this.pdfUrl = '/hybrid/html/web/viewer.html?file=' + encodeURIComponent(url)
- this.pdfUrl = '/hybrid/html/web/viewer.html?file=' + url
- }
- }
- })
- },
- /**
- * 根据报告的id查询有盖章文档路径
- */
- getDe2(id) {
- let access_token = uni.getStorageSync('Access-Token')
- console.log(access_token)
- let sql =
- `{"sql":"select FILE_PATH_ from ibps_file_attachment WHERE id_ = (SELECT bao_gao_pdf_ FROM t_lhjcbgb WHERE id_ = '${id}')"}`
- let md5 = this.sig(sql) //加密, 获取md5密文
- let requestData = sql.slice(0, 1) + '"sig":"' + md5 + '",' + sql.slice(1) //结果拼接
- this.$http.post("/ibps/business/v3/sys/universal/inputSqlSelectData", requestData).then(res => {
- if (res.data.state == 200) {
- const data = res.data.variables.data
- if (data.length > 0) {
- let dataItem = data[0]
- let url =
- http.apiHosp + dataItem.FILE_PATH_
- console.log(url)
- this.pdfUrl = '/hybrid/html/web/viewer.html?file=' + encodeURIComponent(url)
- }
- }
- })
- },
- /**
- * 下载情景
- */
- downloadPdfClick() {
- // 下载情景1:h5内嵌app,通过分享给朋友的方式进行下载
- if (this.from == 'app') {
- let item = http.apiHosp + 'h5/hybrid/html/web/pdf.html?shareUrl=' + encodeURIComponent(
- this
- .bgUrl) +
- '&shareTitle=PDF文件';
- window.open(item);
- return;
- } else if (this.from == 'wx wq') {
- // 下载情景2:h5内嵌微信小程序,从h5页面跳转到小程序页面后,然后通过调用小程序原生API进行下载
- // 注意: 先要引入微信jssdk [命令: npm install jweixin-module]
- // this.$wx.miniProgram.navigateTo({
- // url: '/pages/pdf/pdf_download?pdf='+ encodeURIComponent(this.bgUrl) //小程序页面链接
- // });
- }
- },
- sig(sql) {
- let rul = (sql.length + 9) * 12 * 3 + 168
- let salt = "JinYuanXinTong"
- return md5(rul + '' + salt)
- }
- }
- }
- </script>
- <style>
- </style>
|