123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- <template>
- <view class="pc-page">
- <web-view :src="url" @message="handleGetMessage" v-if="url"/>
- </view>
- </template>
- <script>
- import {pcBaseUrl} from '../utils/config'
- const mapObj=new Map([
- ['pages/activity/activity','/activity/list'],
- ['pages/pricedriven/pricedriven','/pricedriven'],
- ['pages-activity/detail','/activity/detail'],
- ['pages/report/report','/report/index'],
- ['pages-report/classify','/report/classify'],
- ['pages-report/reportList','/report/list'],
- ['pages-report/reportDetail','/report/detail'],
- ['pages-report/chapterDetail','/report/chapterdetail'],
- ['pages-report/specialColumn/list','/report/specialcolumnlist'],
- ['pages-report/specialColumn/detail','/report/specialcolumndetail'],
- ['pages/video/videoList','/video/list'],
- ['pages-sandTable/sandTable','/sandBox/list'],
- ['pages/voice/voice','/voice/list'],
- ['pages-voice/voiceDetail','/voice/detail'],
- ['pages-roadShow/video/list','/roadshow/video/list'],
- ['pages/roadShow/video/list','/roadshow/video/list'],
- ['pages-report/reportForVariety/list','/report/varietyreportlist'],
- ['pages/positionAnalysis/index','/positionanalysis/index'],
- ['pages/positionAnalysis/detail','/positionanalysis/detail'],
- ['pages-report/chapterList','/report/detail'],
- ['pages-report/previewPDF','/report/previewPDF'],
- ['pages/question/question','/question/list'],
- ['pages/forexCalendar/index','/forexCalendar/index'],
- ])//map映射小程序页面路径对应h5页面路径
- import {apiUserInfo} from '@/api/user'
- import {apiGetSceneToParams} from '@/api/common'
- export default {
- data () {
- return {
- url:'',
- msgObj:{},//{path:小程序页面地址,params:页面参数,title:分享的标题,shareImg:分享的图片}
- times:0,//检查token次数
- }
- },
- onLoad(options) {
- this.init(options)
- },
- onShareAppMessage({webViewUrl}) {
- // console.log(webViewUrl);
- let paramsStr=''
- for(const key in this.msgObj.params){
- if(!paramsStr){
- paramsStr=`${key}=${this.msgObj.params[key]}`
- }else{
- paramsStr=`${paramsStr}&${key}=${this.msgObj.params[key]}`
- }
- }
- return {
- title: this.msgObj.title||'弘则研究',
- path: `${this.msgObj.path}?${paramsStr}`,
- imageUrl:this.msgObj.shareImg||''
- }
- },
- methods: {
- // 获取到用户点击转发时从h5页面传来的参数
- handleGetMessage(e){
- const data=e.detail.data[e.detail.data.length-1]
- console.log('h5传来的数据',data);
- this.msgObj=data
- },
- async init(options){
- // 检查token是否有效 超过十次不在检测,提示重启小程序
- const res=await apiUserInfo()
- this.times++
- if(res.code!==200){
- console.log('pc页面检查token次:',this.times);
- if(this.times<11){
- setTimeout(() => {
- this.init(options)
- }, 1000);
- }else{
- uni.showToast({
- title: '请重启小程序',
- icon: 'none'
- })
- }
- return
- }
- console.log('pc页面onload数据',options);
- // 如果是识别海报的则要解密
- if(options.scene){
- const resScene=await apiGetSceneToParams({scene_key:options.scene})
- if(resScene.code===200){
- const obj=JSON.parse(resScene.data)
- delete options.scene
- options={...options,...obj}
- console.log('pc页面解密scene数据',options);
- }
- }
- let paramsObj={
- ...options,
- token:this.$store.state.user.token||uni.getStorageSync("token"),
- timestamp:new Date().getTime(),//防止缓存
- }
- delete paramsObj.xcxPath
- console.log('要处理的参数',paramsObj);
- let paramsObjStr=''
- for (const key in paramsObj) {
- if(!paramsObjStr){
- paramsObjStr=`${key}=${paramsObj[key]}`
- }else{
- paramsObjStr=`${paramsObjStr}&${key}=${paramsObj[key]}`
- }
- }
- console.log('拼接字符串:',paramsObjStr);
- paramsObjStr +='&platform_source=xcx'
- uni.getSystemInfo({
- success: (data) => {
- // 企业微信会额外返回一个 environment 字段 值为 wxwork 在企业微信PC版中,一旦后缀带上#wechat_redirect ,就打不开,不知道为何,社区也没有找到什么结果
- this.url=`${pcBaseUrl}${mapObj.get(decodeURIComponent(options.xcxPath))||'/'}?${paramsObjStr}${data.environment=='wxwork'?'':'#wechat_redirect'}`
- // console.log(`${pcBaseUrl}${mapObj.get(decodeURIComponent(options.xcxPath))||'/'}?${paramsObjStr}${data.environment=='wxwork'?'':'#wechat_redirect'}`);
- },
- fail: (err) => {
- this.url=`${pcBaseUrl}${mapObj.get(decodeURIComponent(options.xcxPath))||'/'}?${paramsObjStr}#wechat_redirect`
- console.log(err);
- }
- })
-
- }
- },
- onShow() {
- uni.hideHomeButton({
- fail:(e)=>{
- console.log(e);
- }
- })
- }
- }
- </script>
|