chartDetail.vue 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. token:this.$store.state.user.token||uni.getStorageSync("token"),
  49. timestamp:new Date().getTime(),//防止缓存
  50. }
  51. console.log('要处理的参数',queryObj);
  52. let queryObjStr=''
  53. for (const key in queryObj) {
  54. if(!queryObjStr){
  55. queryObjStr=`${key}=${queryObj[key]}`
  56. }else{
  57. queryObjStr=`${queryObjStr}&${key}=${queryObj[key]}`
  58. }
  59. }
  60. console.log('拼接字符串:',queryObjStr);
  61. this.url=`${h5BaseUrl}/hzyb/chart/detail?${queryObjStr}#wechat_redirect`
  62. },
  63. // 获取到用户点击转发时从h5页面传来的参数
  64. handleGetMessage(e){
  65. const data=e.detail.data[e.detail.data.length-1]
  66. console.log('h5传来的数据',data);
  67. this.msgObj=data
  68. }
  69. }
  70. }
  71. </script>