previewPDF.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <template>
  2. <web-view :src="url" @message="handleGetMessage"/>
  3. </template>
  4. <script>
  5. import {h5BaseUrl} from '@/utils/config'
  6. import {apiGetPDFDetail} from '@/api/report.js'
  7. import {apiGetSceneToParams} from '@/api/common'
  8. export default {
  9. data() {
  10. return {
  11. msgObj:{},
  12. url:'',
  13. pdf_id:0,
  14. pdf_name:'',
  15. pdf_url:''
  16. };
  17. },
  18. onLoad(options) {
  19. this.init(options)
  20. wx.setVisualEffectOnCapture({visualEffect:'hidden'})
  21. },
  22. onShareAppMessage() {
  23. return {
  24. title:this.msgObj.title||this.pdf_name||'',
  25. path:`/pages-report/previewPDF?pdf_id=${this.pdf_id}`,
  26. imageUrl:this.msgObj.shareImg||this.globalImgUrls.pdfShareImg
  27. }
  28. },
  29. methods: {
  30. async init(options){
  31. if(options.scene){
  32. const res=await apiGetSceneToParams({scene_key:options.scene})
  33. if(res.code==200){
  34. const obj=JSON.parse(res.data)
  35. options.pdf_id = obj.pdf_id
  36. this.pdf_id = Number(obj.pdf_id)
  37. this.getPDFDetail()
  38. }
  39. }else{
  40. this.pdf_id = Number(options.pdf_id)||0
  41. this.getPDFDetail()
  42. }
  43. },
  44. getPDFDetail(){
  45. if(!this.pdf_id){
  46. uni.showToast({
  47. title: '未找到PDF',
  48. icon: 'none'
  49. })
  50. return
  51. }
  52. apiGetPDFDetail({pdf_id:this.pdf_id}).then(res=>{
  53. if(res.code!==200) return
  54. this.pdf_name=res.data.pdf_name||''
  55. this.pdf_url=res.data.pdf_url||''
  56. const token=this.$store.state.user.token
  57. this.url = `${h5BaseUrl}/hzyb/report/previewpdf?pdfSrc=${this.pdf_url}&token=${token}#wechat_redirect`
  58. //this.url = `http://192.168.77.31:3000/xcx_h5/hzyb/report/previewpdf?pdfSrc=${this.pdf_url}&token=${token}#wechat_redirect`
  59. })
  60. },
  61. handleGetMessage(e){
  62. const data=e.detail.data[e.detail.data.length-1]
  63. console.log('h5传来的数据',data);
  64. this.msgObj=data
  65. },
  66. },
  67. };
  68. </script>
  69. <style scoped lang="scss">
  70. </style>