Преглед на файлове

Merge branch 'fix_share'

Karsa преди 5 месеца
родител
ревизия
fe3fa9a830
променени са 10 файла, в които са добавени 230 реда и са изтрити 87 реда
  1. 49 4
      index.html
  2. 7 0
      src/App.vue
  3. 5 0
      src/api/api.js
  4. BIN
      src/assets/img/layoutLoading.png
  5. 3 0
      src/main.js
  6. 37 15
      src/views/report/reportDetail.vue
  7. 8 4
      src/views/reportEn/detail.vue
  8. 34 13
      src/views/smartReport/detail.vue
  9. 85 50
      src/views/utils/wxShare.js
  10. 2 1
      vite.config.js

+ 49 - 4
index.html

@@ -6,13 +6,58 @@
     <title>研报</title>
     <script src="/jweixin-1.6.0.js"></script>
     <script src="/jquery-3.6.0.min.js"></script>
+    <style>
+      body{
+        width: 100vw;
+        min-height: 100vh;
+        position: relative;
+        background-color: #ffffff;
+        margin: 0;
+      }
+      .loading-model {
+          width: 100vw;
+          height: 100vh;
+          display: flex;
+          justify-content: center;
+          align-items: center;
+          position: absolute;
+          top: 0;
+          z-index: -1;
+          color: #007aff;
+      }
+
+      .loading {
+          width: 50px;
+          height: 50px;
+          background: url('./src/assets/img/layoutLoading.png') no-repeat center center;
+          margin: 0 auto 20px;
+          background-size: cover;
+          -webkit-animation: load 1.1s infinite linear;
+      }
+
+      @-webkit-keyframes load {
+          from {
+              transform: rotate(0deg);
+          }
+          to {
+              transform: rotate(360deg);
+          }
+      }
+    </style>
   </head>
-  <script type="module">
-		import { registerEtaComp } from '/public/eta_comp.js'
-		registerEtaComp()
-	 </script>
   <body>
+    <div class="loading-model" id="loadingModel">
+      <div>
+        <div class="loading"></div>
+        <div class="loading-text">资源加载中,请稍候...</div>
+      </div>
+    </div>
+
     <div id="app"></div>
     <script type="module" src="/src/main.js"></script>
+    <script type="module">
+      import { registerEtaComp } from '/public/eta_comp.js'
+      registerEtaComp()
+    </script>
   </body>
 </html>

+ 7 - 0
src/App.vue

@@ -1,4 +1,11 @@
 <template>
   <router-view />
 </template>
+<script>
+export default {
+  mounted() {
+    document.getElementById('loadingModel').style.display='none';
+  }
+}
+</script>
 

+ 5 - 0
src/api/api.js

@@ -25,4 +25,9 @@ export const getWxSign = params=>{
 // 智能研报详情
 export const smartReportDetail=params=>{
   return get('/smart_report/share/detail',params)
+}
+
+//获取分享信息
+export const getShareInfo=params=>{
+  return get('/smart_report/wechat_share/detail',params)
 }

BIN
src/assets/img/layoutLoading.png


+ 3 - 0
src/main.js

@@ -9,6 +9,9 @@ import '@vant/touch-emulator';//vant
 import 'vant/lib/index.css';
 import '@/utils/rem.js';
 
+import {injectSdk} from '@/views/utils/wxShare.js';
+injectSdk()
+
 const app=createApp(App)
 app.use(router).use(store).mount('#app')
 

+ 37 - 15
src/views/report/reportDetail.vue

@@ -81,7 +81,7 @@
       <div style="padding: 0.6rem; box-sizing: border-box; overflow: hidden">
 
         <!-- 章节报告 -->
-        <div class="chapter-wrap" v-if="reportInfo.HasChapter===1">
+        <!-- <div class="chapter-wrap" v-if="reportInfo.HasChapter===1">
           <div class="chapter-item" v-for="item in reportInfo.ChapterList" :key="item.ReportChapterId">
             <div style="margin-bottom:10px">
               <span class="type" v-if="item.TypeName">{{item.TypeName}}</span>
@@ -89,9 +89,9 @@
             </div>
             <div id="resetcss" style="overflow:hidden;" v-html="item.Content"></div>
           </div>
-        </div>
+        </div> -->
 
-        <div id="resetcss" style="overflow:hidden;" v-else>
+        <div id="resetcss" style="overflow:hidden;">
           <ul>
             <li v-for="(html,index) in realContent" :key="index" v-html="html"></li>
           </ul>
@@ -165,9 +165,10 @@
 <script>
 import {
   reportDetail,
+  getShareInfo
 } from "@/api/api.js";
 import _ from 'lodash';
-import wxShare from '../utils/wxShare.js';
+import {wxShare,injectSdk} from '../utils/wxShare.js';
 
 import AudioPlay from './audioPlay.vue';
 import { Watermark,BlindWatermark } from 'watermark-js-plus'
@@ -189,11 +190,15 @@ export default {
       Disclaimer:''
     };
   },
-  mounted() {
+  created() {
     wx.ready(function(){
-        wx.hideOptionMenu();
+      wx.hideOptionMenu();
     });
-    this.getreportdetail();
+  },
+  mounted() {
+    // injectSdk().then(res => {
+      this.getShareData()
+    // })
     window.addEventListener('scroll', this.loadMoreHandle);
   },
 
@@ -241,6 +246,13 @@ export default {
       .css({ display: "block", whiteSpace: "pre-wrap" });
   },
   methods: {
+    async getShareData() {
+      let res = await getShareInfo({ ReportCode: this.id })
+      if(res.Ret !== 200) return 
+      
+      wxShare(document.location.href,res.Data.H5ShareName||document.title,res.Data.H5ShareTitle,res.Data.H5ReportShareImg,0);
+      this.getreportdetail()
+    },
     showTips() {
       //免责声明显示
       $("#tipsAlert").animate({ top: 0 });
@@ -280,16 +292,16 @@ export default {
         document.title=(Data && Data.H5ShareName) || "研报"
         if (Ret !== 200) return
         // console.log('data',Data)
-        let H5ShareName = Data.H5ShareName
-        let H5ReportShareImg = Data.H5ReportShareImg
-        let wxShareTitle=!!Data.Hz?
-        '【第'+Data.Report.Stage+'期|FICC'+'】'+Data.Report.Title+'('+Data.Report.CreateTime.substring(5,7)+Data.Report.CreateTime.substring(8,10)+')':
-                          Data.Report.Title+'('+Data.Report.CreateTime.substring(5,7)+Data.Report.CreateTime.substring(8,10)+')'
+        // let H5ShareName = Data.H5ShareName
+        // let H5ReportShareImg = Data.H5ReportShareImg
+        // let wxShareTitle=!!Data.Hz?
+        // '【第'+Data.Report.Stage+'期|FICC'+'】'+Data.Report.Title+'('+Data.Report.CreateTime.substring(5,7)+Data.Report.CreateTime.substring(8,10)+')':
+        //                   Data.Report.Title+'('+Data.Report.CreateTime.substring(5,7)+Data.Report.CreateTime.substring(8,10)+')'
         this.reportInfo = Data.Report;
         this.Disclaimer = Data.Disclaimer||'';
         this.isshow = true;
 
-        this.splitContentHandle(this.reportInfo.Content);
+        this.splitContentHandle();
 
         $(document).on("click", "#resetcss img", function (event) {
           let imgArray = [];
@@ -303,7 +315,7 @@ export default {
             wx.previewImage({ current: curImageSrc, urls: imgArray });
           }
         });
-        wxShare(document.location.href,H5ShareName || document.title,wxShareTitle,H5ReportShareImg,0);
+
         //水印
         localStorage.setItem('waterMarkStr',this.$route.query.flag||'')
         const temwaterMarkStr=this.$route.query.flag||localStorage.getItem('waterMarkStr')
@@ -350,12 +362,22 @@ export default {
 
 
     /*内容分割*/
-    splitContentHandle(content) {
+    splitContentHandle() {
+      let content='';
+      if(this.reportInfo.HasChapter===1) {
+        this.reportInfo.ChapterList.forEach(item => {
+          content+=item.Content
+        })
+      }else {
+        content = this.reportInfo.Content;
+      }
+
       const arr = content.split("</p>");
       this.totalContent = arr.map((_) => _ + "</p>");
       this.realContent = this.totalContent.slice(0, this.pageSize);
       this.total_page = parseInt(this.totalContent.length / this.pageSize) + 1;
       // console.log(this.realContent, this.totalContent);
+
     },
 
     /* 加载下一页内容 */

+ 8 - 4
src/views/reportEn/detail.vue

@@ -115,7 +115,7 @@ import {
   reportEnDetail,
 } from "@/api/api.js";
 import _ from 'lodash';
-import wxShare from '../utils/wxShare.js'
+import {wxShare,injectSdk} from '../utils/wxShare.js'
 import { Watermark,BlindWatermark } from 'watermark-js-plus'
 import { Base64 } from 'js-base64';
 export default {
@@ -133,11 +133,15 @@ export default {
       total_page: 0,
     };
   },
-  mounted() {
+  created() {
     wx.ready(function(){
-        wx.hideOptionMenu();
+      wx.hideOptionMenu();
     });
-    this.getreportdetail();
+  },
+  mounted() {
+    // injectSdk().then(res => {
+      this.getreportdetail()
+    // })
     window.addEventListener('scroll', this.loadMoreHandle);
   },
   destroyed() {

+ 34 - 13
src/views/smartReport/detail.vue

@@ -94,9 +94,9 @@
 </template>
 
 <script>
-import { smartReportDetail,reportDetail } from "@/api/api.js";
+import { getShareInfo,reportDetail } from "@/api/api.js";
 import _ from "lodash";
-import wxShare from "../utils/wxShare.js";
+import {wxShare,injectSdk} from "../utils/wxShare.js";
 
 export default {
   data() {
@@ -124,11 +124,15 @@ export default {
       }
     };
   },
-  mounted() {
+  created() {
     wx.ready(function(){
-        wx.hideOptionMenu();
+      wx.hideOptionMenu();
     });
-    this.getreportdetail();
+  },
+  mounted() {
+    // injectSdk().then(res => {
+      this.getShareData()
+    // })
     window.addEventListener("scroll", this.loadMoreHandle);
     window.addEventListener('resize',this.pageResize)
   },
@@ -139,6 +143,13 @@ export default {
   },
 
   methods: {
+    async getShareData() {
+      let res = await getShareInfo({ ReportCode: this.id })
+      if(res.Ret !== 200) return 
+      
+      wxShare(document.location.href,res.Data.H5ShareName||document.title,res.Data.H5ShareTitle,res.Data.H5ReportShareImg,0);
+      this.getreportdetail()
+    },
     pageResize(){
       const el=document.getElementById('reportdtl')
       const windowWid=document.body.clientWidth
@@ -165,11 +176,11 @@ export default {
       document.title = (Data && Data.H5ShareName) || "研报";
       if (Ret !== 200) return;
       // console.log('data',Data)
-      let H5ShareName = Data.H5ShareName;
-      let H5ReportShareImg = Data.H5ReportShareImg;
-      let wxShareTitle = !!Data.Hz
-        ? "【第" + Data.Report.Stage + "期|FICC" + "】" + Data.Report.Title + "(" + Data.Report.CreateTime.substring(5, 7) + Data.Report.CreateTime.substring(8, 10) + ")"
-        : Data.Report.Title + "(" + Data.Report.CreateTime.substring(5, 7) + Data.Report.CreateTime.substring(8, 10) + ")";
+      // let H5ShareName = Data.H5ShareName;
+      // let H5ReportShareImg = Data.H5ReportShareImg;
+      // let wxShareTitle = !!Data.Hz
+      //   ? "【第" + Data.Report.Stage + "期|FICC" + "】" + Data.Report.Title + "(" + Data.Report.CreateTime.substring(5, 7) + Data.Report.CreateTime.substring(8, 10) + ")"
+      //   : Data.Report.Title + "(" + Data.Report.CreateTime.substring(5, 7) + Data.Report.CreateTime.substring(8, 10) + ")";
       this.reportInfo = Data.Report || {};
       this.headImgStyle=this.reportInfo.HeadStyle?JSON.parse(this.reportInfo.HeadStyle):[]
       this.endImgStyle=this.reportInfo.EndStyle?JSON.parse(this.reportInfo.EndStyle):[]
@@ -184,7 +195,9 @@ export default {
         this.pageResize()
       })
 
-      this.splitContentHandle(this.reportInfo.Content);
+      // wxShare(document.location.href, H5ShareName || document.title, wxShareTitle, H5ReportShareImg, 0);
+
+      // this.splitContentHandle();
 
       $(document).on("click", "#resetcss img", function (event) {
         let imgArray = [];
@@ -198,11 +211,19 @@ export default {
           wx.previewImage({ current: curImageSrc, urls: imgArray });
         }
       });
-      wxShare(document.location.href, H5ShareName || document.title, wxShareTitle, H5ReportShareImg, 0);
     },
 
     /*内容分割*/
-    splitContentHandle(content) {
+    splitContentHandle() {
+      let content='';
+      if(this.reportInfo.HasChapter===1) {
+        this.reportInfo.ChapterList.forEach(item => {
+          content+=item.Content
+        })
+      }else {
+        content = this.reportInfo.Content;
+      }
+
       const regex = new RegExp(`<div[^>]*class="?report-drag-item-wrap"?>`);
       const arr = content.split(regex);
       this.totalContent = arr.map((_) => _ + "<div class='report-drag-item-wrap'>");

+ 85 - 50
src/views/utils/wxShare.js

@@ -1,35 +1,33 @@
 import {getWxSign} from '@/api/api';
 import { Toast } from 'vant';
 // import utils from '@/utils/utils';
-export default function wxShare(shareurl,title,desc,imgurl,hide){
-  getWxSign({
-    // Url: decodeURIComponent(utils.isIos() ? window.entryUrl : window.location.href)
-    Url:window.location.href
-  }).then((res)=>{
-    if( res.Ret===200 ){
-      wx.config({
-        debug:false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
-        appId:res.Data.AppId, // 必填,企业号的唯一标识,此处填写企业号corpid
-        timestamp:res.Data.Timestamp, // 必填,生成签名的时间戳
-        nonceStr:res.Data.NonceStr, // 必填,生成签名的随机串
-        signature:res.Data.Signature,// 必填,签名,见附录1
-        jsApiList:['updateTimelineShareData',//1.4.0的分享接口,注意:使用新版本的分享功能,一定要在该列表加上对应的老版本功能接口,否则新接口不起作用
-        'updateAppMessageShareData',//1.4.0的分享接口,注意:使用新版本的分享功能,一定要在该列表加上对应的老版本功能接口,否则新接口不起作用
-        'onMenuShareAppMessage',//老版本分享接口。
-        'onMenuShareTimeline',
-        'hideOptionMenu',
-        'showOptionMenu',
-        'hideMenuItems']
-      });
-    }else {
-      console.log(res)
-      if(res.Ret!==4003){
-        Toast('获取签名失败,请刷新重试!')
-      }
-      //如果需要强制刷新
-      //window.location.reload()
-      return 
-    }
+export function wxShare(shareurl,title,desc,imgurl,hide){
+  // getWxSign({
+  //   Url:window.location.href.split('#')[0]
+  // }).then((res)=>{
+  //   if( res.Ret===200 ){
+  //     wx.config({
+  //       debug:false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
+  //       appId:res.Data.AppId, // 必填,企业号的唯一标识,此处填写企业号corpid
+  //       timestamp:res.Data.Timestamp, // 必填,生成签名的时间戳
+  //       nonceStr:res.Data.NonceStr, // 必填,生成签名的随机串
+  //       signature:res.Data.Signature,// 必填,签名,见附录1
+  //       jsApiList:['updateTimelineShareData',//1.4.0的分享接口,注意:使用新版本的分享功能,一定要在该列表加上对应的老版本功能接口,否则新接口不起作用
+  //       'updateAppMessageShareData',//1.4.0的分享接口,注意:使用新版本的分享功能,一定要在该列表加上对应的老版本功能接口,否则新接口不起作用
+  //       'hideOptionMenu',
+  //       'showOptionMenu',
+  //       'hideMenuItems']
+  //       // 'onMenuShareAppMessage',//老版本分享接口。
+  //       // 'onMenuShareTimeline',
+  //     });
+  //   }else {
+  //     console.log(res)
+  //     if(res.Ret!==4003){
+  //       Toast('获取签名失败,请刷新重试!')
+  //     }
+      
+  //     return 
+  //   }
     if( hide==1 ){
       wx.ready(function(){
         wx.hideOptionMenu();
@@ -39,28 +37,13 @@ export default function wxShare(shareurl,title,desc,imgurl,hide){
       wx.ready(function(){
         // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。
         
-        wx.showOptionMenu();
+        // wx.showOptionMenu();
 
-        wx.onMenuShareTimeline({
-          title:title, // 分享标题
-          link:shareurl, // 分享链接,该链接域名必须与当前企业的可信域名一致
-          imgUrl:imgurl, // 分享图标
-          success: function () {
-            // 用户确认分享后执行的回调函数
-            console.log('分享成功,地址:'+shareurl)
-          },
-          cancel: function () {
-            // 用户取消分享后执行的回调函数
-            console.log('取消分享')
-          }
-        });
-        wx.onMenuShareAppMessage({
-          title:title, // 分享标题
-          desc:desc, // 分享描述
+        let shareData = {
+          title, // 分享标题
+          desc, // 分享描述
           link:shareurl, // 分享链接,该链接域名必须与当前企业的可信域名一致
           imgUrl:imgurl, // 分享图标
-          type:'', // 分享类型,music、video或link,不填默认为link
-          dataUrl:'', // 如果type是music或video,则要提供数据链接,默认为空
           success:function () {
             // 用户确认分享后执行的回调函数
             console.log( "分享成功,当前链接:"+shareurl );
@@ -69,15 +52,67 @@ export default function wxShare(shareurl,title,desc,imgurl,hide){
             // 用户取消分享后执行的回调函数
             console.log('取消分享')
           }
-        });
+        }
+
+        wx.updateAppMessageShareData(shareData)
+
+        wx.updateTimelineShareData(shareData)
+
+        wx.onMenuShareTimeline(shareData);
+
+        wx.onMenuShareAppMessage(shareData);
+
         wx.hideMenuItems({
           menuList: ['menuItem:share:qq','menuItem:share:weiboApp','menuItem:share:facebook','menuItem:share:QZone','menuItem:openWithSafari','menuItem:share:email'] // 要隐藏的菜单项,只能隐藏“传播类”和“保护类”按钮,所有menu项见附录3
         });
+
+        setTimeout(() => {
+          wx.showOptionMenu();
+        },2000)
       });
       
       wx.error(function(res){
         console.log(res);
       });
     }
-  });
+  // });
 }
+
+
+export  function injectSdk() {
+  return new Promise((resove,reject) => {
+    getWxSign({
+      Url:window.location.href.split('#')[0]
+    }).then((res)=>{
+      if( res.Ret===200 ){
+        wx.config({
+          debug:false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
+          appId:res.Data.AppId, // 必填,企业号的唯一标识,此处填写企业号corpid
+          timestamp:res.Data.Timestamp, // 必填,生成签名的时间戳
+          nonceStr:res.Data.NonceStr, // 必填,生成签名的随机串
+          signature:res.Data.Signature,// 必填,签名,见附录1
+          jsApiList:['updateTimelineShareData',//1.4.0的分享接口,注意:使用新版本的分享功能,一定要在该列表加上对应的老版本功能接口,否则新接口不起作用
+          'updateAppMessageShareData',//1.4.0的分享接口,注意:使用新版本的分享功能,一定要在该列表加上对应的老版本功能接口,否则新接口不起作用
+          'hideOptionMenu',
+          'showOptionMenu',
+          'hideMenuItems']
+          // 'onMenuShareAppMessage',//老版本分享接口。
+          // 'onMenuShareTimeline',
+        });
+
+        resove(res)
+
+        wx.ready(function(){
+          wx.hideOptionMenu();
+        });
+      }else {
+        console.log(res)
+        if(res.Ret!==4003){
+          Toast('获取签名失败,请刷新重试!')
+        }
+        
+        reject(res) 
+      }
+    })
+  })
+}

+ 2 - 1
vite.config.js

@@ -1,11 +1,12 @@
 import { defineConfig,loadEnv } from 'vite'
 import vue from '@vitejs/plugin-vue'
 import path from "path";
+
 // https://vitejs.dev/config/
 export default ({mode})=>defineConfig({
   base:loadEnv(mode, process.cwd()).VITE_APP_BASE_URL,
   plugins: [
-    vue(),
+    vue()
   ],
   resolve: {
     alias: {