chartDetail.vue 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <template>
  2. <web-view :src="url" @message="handleGetMessage"></web-view>
  3. </template>
  4. <script>
  5. import {h5BaseUrl} from '../utils/config'
  6. import {apiGetSceneToParams} from '@/api/common'
  7. export default {
  8. data () {
  9. return {
  10. url:'',
  11. msgObj:{},//{title:分享的标题,shareImg:分享的图片,params:页面参数}
  12. }
  13. },
  14. onLoad(options) {
  15. this.init(options)
  16. // const timestamp=new Date().getTime()
  17. // this.url=`${h5BaseUrl}/hzyb/chart/detail?ChartInfoId=${options.chartInfoId}&token=${this.$store.state.user.token}&searchVal=${options.searchVal}&MyChartId=${options.MyChartId}&MyChartClassifyId=${options.MyChartClassifyId}&timestamp=${timestamp}`
  18. },
  19. onShareAppMessage() {
  20. let paramsStr=''
  21. for(const key in this.msgObj.params){
  22. if(!paramsStr){
  23. paramsStr=`${key}=${this.msgObj.params[key]}`
  24. }else{
  25. paramsStr=`${paramsStr}&${key}=${this.msgObj.params[key]}`
  26. }
  27. }
  28. return {
  29. title:this.msgObj.title||'ETA图库',
  30. path:`/pages-chart/chartDetail?${paramsStr}&from=share`,
  31. imageUrl:this.msgObj.shareImg||''
  32. }
  33. },
  34. methods: {
  35. async init(options){
  36. if(options.scene){
  37. const res=await apiGetSceneToParams({scene_key:options.scene})
  38. if(res.code==200){
  39. options=JSON.parse(res.data)
  40. }
  41. }
  42. const queryObj={
  43. ChartInfoId:options.chartInfoId,
  44. searchVal:encodeURIComponent(options.searchVal),//避免在链接中带有中文字符,在 iOS 中会有打开白屏的问题,建议加一下 encodeURIComponent
  45. MyChartId:options.MyChartId,
  46. MyChartClassifyId:options.MyChartClassifyId,
  47. from:options.from||'',
  48. chartSource: options.chartSource||'',
  49. token:this.$store.state.user.token||uni.getStorageSync("token"),
  50. timestamp:new Date().getTime(),//防止缓存
  51. }
  52. console.log('要处理的参数',queryObj);
  53. let queryObjStr=''
  54. for (const key in queryObj) {
  55. if(!queryObjStr){
  56. queryObjStr=`${key}=${queryObj[key]}`
  57. }else{
  58. queryObjStr=`${queryObjStr}&${key}=${queryObj[key]}`
  59. }
  60. }
  61. console.log('拼接字符串:',queryObjStr);
  62. this.url=`${h5BaseUrl}/hzyb/chart/detail?${queryObjStr}#wechat_redirect`
  63. },
  64. // 获取到用户点击转发时从h5页面传来的参数
  65. handleGetMessage(e){
  66. const data=e.detail.data[e.detail.data.length-1]
  67. console.log('h5传来的数据',data);
  68. this.msgObj=data
  69. }
  70. }
  71. }
  72. </script>