jiaweiqi 1 жил өмнө
parent
commit
500851348d

+ 114 - 98
src/views/userindex/indexpage/ArticleIndex.vue

@@ -28,7 +28,7 @@
     <div class="contacts"
          v-show="myId?true:false">
       <div>
-        <h3>{{ menuberinfo }}</h3>
+        <h1>{{ menuberinfo }}</h1>
         <!-- <div style="padding-bottom: 2vh;">河南建工集团||董事长</div> -->
         <div style="margin-bottom: 3vw;"><span class="iconfont icon-weixin"
                 @click="showPopup"></span><span class="iconfont icon-dianhua"
@@ -60,6 +60,7 @@ export default {
   data () {
     return {
       textdetaildata: {},
+      article_id: "",
       isgood: '',
       show: false,
       menuberinfo: '',
@@ -76,23 +77,21 @@ export default {
     }
   },
   created () {
-    
-  },
-  mounted () {
+    if (!this.$route.query.id || this.$route.query.id === "" || this.$route.query.id === "undefined") {
+        Toast("页面参数错误");
+        return false
+    }
+    this.article_id = this.$route.query.id;
     if (!this.myId) {
-      this.myId = storage.getLocalstorage('user_id')
+        this.myId = storage.getLocalstorage('user_id')
     }
     if (this.myId != null && this.myId !== '' && this.myId !== 'undefined') {
       this.getMemberapi(this.myId)
     }
-    if (this.$route.query.id) {
-      this.textdetailapi(this.$route.query.id, this.myId)
-      //获取分享的参数  执行config
-      this.getUserIdparameter()
-    } else {
-      this.textdetailapi()
-    }
-    console.log('------------------', this.$route.query.id)
+    this.getUserIdparameter({'url': location.href.split('#')[0]})
+  },
+  mounted () {
+    this.textdetailapi(this.article_id, this.myId);
   },
   components: { Popup },
   methods: {
@@ -105,33 +104,27 @@ export default {
       if (this.isgood) {
         Toast.fail('不能取消点赞');
       } else {
-        clkgoodInfo(this.$route.query.id, 'WeiQiJia')
+        clkgoodInfo(this.article_id, this.myId)
         this.isgood = true
         Toast.success('点赞成功');
-        console.log(1111);
       }
 
     },
     //文章详情接口
     async textdetailapi (id, userId) {
-      const res = await getArticleCategoryDetail(id, userId)
-      if (res.code == 2000) {
-        this.textdetaildata = res.data
-        this.isgood = res.data.like
-        // this.textdetaildata.flag = false
-        // if (!res.data.flag) this.clkgood()
-        console.log(res.data);
+      const res = await getArticleCategoryDetail(id, userId);
+      if (res.code === 2000) {
+        this.textdetaildata = res.data;
+        this.isgood = res.data.like;
       }
 
-      // this.isgood = res.data.like
     },
     GoUp () {
       this.$router.go(-1)
     },
     //分享到对话框
     shareDialogue () {
-      var wx = window.wx
-      wx.invoke(
+      window.wx.invoke(
         "shareAppMessage", {
         title: '', // 分享标题
         desc: '', // 分享描述
@@ -139,7 +132,7 @@ export default {
         imgUrl: '', // 分享封面
         enableIdTrans: 0, // 是否开启id转译,不填默认为0
       }, function (res) {
-        if (res.err_msg == "shareAppMessage:ok") {
+        if (res.err_msg === "shareAppMessage:ok") {
           //正确处理
         } else {
           //错误处理
@@ -150,13 +143,12 @@ export default {
     //获取个人信息  //WeiQiJia
     async getMemberapi (user_id) {
       const res = await getMember(user_id)
-      if (res.code == 2000) {
+      if (res.code === 2000) {
         this.menuberinfo = res.data.name
         this.avatar = res.data.avatar
         this.phone = res.data.tel
         this.qrcode = res.data.qrcode
       }
-      console.log(res)
     },
     //打电话
     callPhone () {
@@ -164,25 +156,25 @@ export default {
     },
     //获取分享参数 在wx.ready执行分享的事件分享到朋友/朋友圈等
     async getShareParmasinfo (id,myId) {
-      const res = await getShareParmas(id,myId)
-      console.log(res)
-      this.shareData.title = res.data.title
-      this.shareData.desc = res.data.desc
-      this.shareData.link = res.data.link
-      this.shareData.imgUrl = res.data.image
+      const res = await getShareParmas(id,myId);
+      let { title, desc, link, image } = res.data;
+      this.shareData.title = title;
+      this.shareData.desc = desc;
+      this.shareData.link = link;
+      this.shareData.imgUrl = image;
       window.wx.onMenuShareAppMessage({
-        title: res.data.title, // 分享标题
-        desc: res.data.desc, // 分享描述
-        link: res.data.link, // 分享链接;在微信上分享时,该链接的域名必须与企业某个应用的可信域名一致
-        imgUrl: res.data.image, // 分享图标
+        title: title, // 分享标题
+        desc: desc, // 分享描述
+        link: link, // 分享链接;在微信上分享时,该链接的域名必须与企业某个应用的可信域名一致
+        imgUrl: image, // 分享图标
         enableIdTrans: 0, // 是否开启id转译,不填默认为0
         success: function () {
-          this.postShareinfo({article:this.$route.query.id,userid:this.myId})
+            postShareinfo({'article':id,'userid':myId})
           // 用户确认分享后执行的回调函数
         },
         error: function (res) {
           if (res.errMsg.indexOf('no permission') > 0) {
-            console.log('未agentConfig')
+            alert.log('未agentConfig')
           }
         },
         cancel: function () {
@@ -190,14 +182,30 @@ export default {
         }
       });
       window.wx.onMenuShareTimeline({
-        title: res.data.title, // 分享标题
-        desc: res.data.desc, // 分享描述
-        link: res.data.link, // 分享链接;在微信上分享时,该链接的域名必须与企业某个应用的可信域名一致
-        imgUrl: res.data.image, // 分享图标
+        title: title, // 分享标题
+        link: link, // 分享链接;在微信上分享时,该链接的域名必须与企业某个应用的可信域名一致
+        imgUrl: image, // 分享图标
         enableIdTrans: 0, // 是否开启id转译,不填默认为0
         success: function () {
-          this.postShareinfo({article:this.$route.query.id,userid:this.myId})
-          // 用户确认分享后执行的回调函数
+          postShareinfo({'article':id,'userid':myId})
+        },
+        error: function (res) {
+          if (res.errMsg.indexOf('no permission') > 0) {
+            alert('未agentConfig')
+          }
+        },
+        cancel: function () {
+          // 用户取消分享后执行的回调函数
+        }
+      });
+      window.wx.onMenuShareWechat({
+        title: title, // 分享标题
+        desc: desc, // 分享描述
+        link: link, // 分享链接;在微信上分享时,该链接的域名必须与企业某个应用的可信域名一致
+        imgUrl: image, // 分享图标
+        enableIdTrans: 0, // 是否开启id转译,不填默认为0
+        success: function () {
+          postShareinfo({'article':id,'userid':myId})
         },
         error: function (res) {
           if (res.errMsg.indexOf('no permission') > 0) {
@@ -211,62 +219,70 @@ export default {
 
     },
     //config
-    async getUserIdparameter () {
-      const res = await getparameter()
-      window.wx.config({
-        beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
-        debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
-        appId: res.data.appId, // 必填,企业微信的corpID
-        timestamp: res.data.timestamp, // 必填,生成签名的时间戳
-        nonceStr: res.data.nonceStr, // 必填,生成签名的随机串
-        signature: res.data.signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法
-        jsApiList: ["onMenuShareTimeline", "onMenuShareAppMessage", "onMenuShareWechat"], // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
-      });
-      window.wx.ready(() => {
-        this.getShareParmasinfo(this.$route.query.id,this.myId)
-      })
-      window.wx.agentConfig({
-        corpid: res.data.appId, // 必填,企业微信的corpid,必须与当前登录的企业一致
-        agentid: res.data.agentid, // 必填,企业微信的应用id (e.g. 1000247)
-        timestamp: res.data.timestamp, // 必填,生成签名的时间戳
-        nonceStr: res.data.nonceStr, // 必填,生成签名的随机串
-        signature: res.data.agent_signature,// 必填,签名,见附录-JS-SDK使用权限签名算法
-        jsApiList: ['shareWechatMessage'], //必填,传入需要使用的接口名称
-        success: function (res) {
-          console.log('agentConfig=>成功')
-          console.log('获取agentConfig的res', res)
-          getShareParmas(this.$route.query.id,this.myId).then(res => {
-            window.wx.invoke('shareWechatMessage', {
-              title: res.data.title, // 分享标题
-              desc: res.data.desc, // 分享描述
-              link: res.data.link, // 分享链接
-              imgUrl: res.data.imgUrl, // 分享封面
-              enableIdTrans: 1, // 是否开启id转译,不填默认为0
-            }, function (res) {
-              if (res.err_msg == "shareWechatMessage:ok") {
-                this.postShareinfo({article:this.$route.query.id,userid:this.myId})
-                //正确处理
-              } else {
-                //错误处理
-              }
-            });
-
+    async getUserIdparameter (url) {
+      let result = await getparameter(url)
+      if (result.code !== 2000) {
+          Toast(result.msg)
+          return false;
+      }
+      let { appId, agentid, timestamp, nonceStr, signature, agent_signature } = result.data;
+      this._Config(appId, timestamp, nonceStr, signature)
+          .then(data=> {
+              return this.getShareParmasinfo(this.article_id, this.myId)
           })
-
-        },
-        fail: function (res) {
-          console.log('agentConfig=>失败')
-          if (res.errMsg.indexOf('function not exist') > -1) {
-            console.log('版本过低请升级')
-          }
+          .catch(data => {
+              Toast(data)
+          })
+    },
+    _Config (appId, timestamp, nonceStr, signature) {
+        return new Promise(function (resolve, reject) {
+            const wx = window.wx;
+            if (!wx) {
+                reject("企业微信apk引入失败,尝试刷新页面!")
+            }
+            wx.config({
+                beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
+                debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
+                appId: appId, // 必填,企业微信的corpID
+                timestamp: timestamp, // 必填,生成签名的时间戳
+                nonceStr: nonceStr, // 必填,生成签名的随机串
+                signature: signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法
+                jsApiList: ["agentConfig", "onMenuShareTimeline", "onMenuShareAppMessage", "onMenuShareWechat"], // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
+            });
+            wx.ready(function () {
+                resolve()
+            });
+            wx.error(function (res) {
+                reject("注入权限验证失败")
+            })
+        })
+    },
+    _agentConfig(appId, agentid, timestamp, nonceStr, agent_signature) {
+      return new Promise(function (resolve, reject) {
+      const wx = window.wx;
+        if (!wx) {
+            reject("企业微信apk引入失败,尝试刷新页面!")
         }
+        wx.agentConfig({
+            corpid: appId, // 必填,企业微信的corpid,必须与当前登录的企业一致
+            agentid: agentid, // 必填,企业微信的应用id (e.g. 1000247)
+            timestamp: timestamp, // 必填,生成签名的时间戳
+            nonceStr: nonceStr, // 必填,生成签名的随机串
+            signature: agent_signature,// 必填,签名,见附录-JS-SDK使用权限签名算法
+            jsApiList: ['getContext', 'getCurExternalContact'], //必填,传入需要使用的接口名称
+            success: function (res) {
+                resolve()
+            },
+            fail: function (res) {
+                if (res.errMsg.indexOf('function not exist') > -1) {
+                    reject("版本过低请升级")
+                } else {
+                    reject("应用注入权限验证失败")
+                }
+            }
+        })
       })
     },
-    //转发成功调用添加转发记录
-    async postShareinfo(data){
-      const res= await postShareinfo(data)
-      console.log('转发成功调用添加转发记录',res)
-    }
   },
 }
 </script>

+ 8 - 9
src/views/userindex/indexpage/GetUserIndexMyid.vue

@@ -3,7 +3,6 @@
 </template>
 <script>
 import { get } from '../../../../serves/axios';
-import { query } from 'quill';
 export default {
   data () {
     return {
@@ -20,7 +19,7 @@ export default {
     //获取corpid
     getCorpId () {
       get('/api/customer/chat_side/corpid/').then(res => {
-        if (res.code == 2000) {
+        if (res.code === 2000) {
           this.corpid = res.data.corpid
           if(this.corpid && this.corpid!==''&&this.corpid!=='undefind'){
               this.setCode()
@@ -29,14 +28,14 @@ export default {
       })
     },
     //截取链接中的code
-    getQuery () {
-      let { search } = window.location;
-      if (!search) {
+    getQuery(){
+      let { search } =window.location;
+      if(!search){
         return {};
       }
-      search = search.slice('&')
-      // eslint-disable-next-line no-import-assign
-      query = query.map(item => item.split('='))
+      search=search.slice(1);
+      let query = search.split("&");
+      query = query.map(item=>item.split('='))
       return Object.fromEntries(query)
     },
     //设置code
@@ -45,7 +44,7 @@ export default {
       if (!query.code) {
         return window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${this.corpid}&redirect_uri=${encodeURIComponent(window.location.href)}&response_type=code&scope=snsapi_base&state=STATE&agentid=AGENTID#wechat_redirect`
       } else {
-        this.$router.push({ name: 'index', query: { code: query.code } })
+        this.$router.push({ name: 'index', query: { auth_code: query.code } })
       }
     }
   },

+ 30 - 51
src/views/userindex/indexpage/UserIndex.vue

@@ -68,26 +68,31 @@ export default {
   components: {
     Swipe, SwipeItem, Tab, Tabs, List,
   },
-  created () {
+  async created () {
+      let auth_code = "";
+      if (this.$route.query.auth_code) {
+          auth_code = this.$route.query.auth_code
+      }
+      if (!auth_code) {
+          let userid = sessionStorage.getLocalstorage("user_id");
+          if (userid && userid !== undefined && userid !== "") {
+              this.myId = userid
+          } else {
+              this.$router.push({ name: 'GetUserIndex' })
+          }
+      } else {
+          let result = await getUser_Id(auth_code);
+          if (result.code !== 2000) {
+              Toast(result.msg)
+              return false
+          }
+          let { user_id } = result.data;
+          this.myId = user_id;
+          sessionStorage.setLocalstorage('user_id', user_id);
+       }
    
   },
   mounted () {
-     //获取自己的userId
-     if (!this.$route.query.code) {
-      let user_id = sessionStorage.getLocalstorage('user_id')
-      if (user_id && user_id != undefined && user_id != '') {
-        this.myId = user_id
-      } else {
-        this.$router.push({ name: 'GetUserIndex'})
-      }
-    } else {
-      getUser_Id().then(res => {
-        if (res.code == 2000) {
-      this.myId=res.data.user_id
-          sessionStorage.setLocalstorage('user_id', res.data.user_id)
-        }
-      })
-    }
     this.indexswiperapi()
     this.indexcategoryapi(this.id, this.limit, this.page)
     this.getSwiperUrlapi()
@@ -97,8 +102,7 @@ export default {
     async indexswiperapi () {
       const res = await articleCategory()
       if (res.code === 2000) {
-        this.category = res.data
-        sessionStorage.setItem('category', JSON.stringify(this.category))
+        this.category = res.data;
       } else {
         Toast('获取数据失败')
       }
@@ -106,40 +110,24 @@ export default {
     //轮播图url
     async getSwiperUrlapi () {
       const res = await getSwiperUrl()
-      if (res.code == 2000) {
+      if (res.code === 2000) {
         this.swiperimg = res.data
       }
     },
     //文章列表数据
     async indexcategoryapi (id, limit, page) {
-      console.log(limit, page)
-      if (id) {
-        const res = await getArticleCategoryList(id, limit, page)
-        console.log(res);
-        this.articledata = res.data.data
-        if (this.articledata.length < res.data.data.length) {
-          this.loading = false
-        } else {
-          this.finished = true
-        }
+      const res = await getArticleCategoryList(id, limit, page)
+      this.articledata = res.data.data;
+      if (this.articledata.length < res.data.data.length) {
+        this.loading = false
       } else {
-        const res = await getArticleCategoryList('', limit, page)
-        console.log(res.data);
-        this.articledata = res.data.data
-        if (this.articledata.length < res.data.data.length) {
-          this.loading = false
-        } else {
-          this.finished = true
-        }
+        this.finished = true
       }
     },
     onClick (name, title) {
       this.page = 1
       const targetid = this.category.find(obj => obj.name === title)
-      console.log(targetid.id);
       this.indexcategoryapi(targetid.id, this.limit, this.page)
-
-
     },
     wenzhangdetail (id) {
       this.$router.push({ name: 'textpage', query: { id } }
@@ -150,7 +138,7 @@ export default {
       this.loading = true;
       this.page++
       const res = await getArticleCategoryList(id, this.limit, this.page)
-      if (res.code == 2000) {
+      if (res.code === 2000) {
         this.articledata = [...this.articledata, ...res.data.data]
         if (res.data.data.length < 1) {
           this.finished = true
@@ -183,7 +171,6 @@ export default {
   .banner {
     width: 100%;
     height: 15rem;
-    background-color: red;
     overflow: hidden;
 
     .my-swipe .van-swipe-item {
@@ -198,14 +185,6 @@ export default {
       width: 100%;
       height: 15rem;
     }
-    // .my-swipe {
-    //   .swipe-item {
-    //     color: #fff;
-    //     font-size: 20px;
-    //     line-height: 150px;
-    //     text-align: center;
-    //   }
-    // }
   }
 
   //标签内容

+ 16 - 18
src/views/userindex/my/MyForward.vue

@@ -23,7 +23,7 @@
                  :key="item.id"
                  class="card">
               <div class="titile">
-                <h2 @click="gomyforwarddetail(item.article,item.id,item.count,item.title,item.acover)">{{ item.title }}</h2>
+                <h2 @click="gomyforwarddetail(item.article,item.id,item.count,item.title,item.cover)">{{ item.title }}</h2>
                 <p>{{ item.count }}人阅读</p>
               </div>
               <img :src="item.cover"
@@ -39,8 +39,8 @@
   </div>
 </template>
 <script>
-import { Tab, Tabs, List } from 'vant';
-import { getUserForwardList } from "../../../../serves/prove";
+import { Tab, Tabs, List, Toast } from 'vant';
+import { getUserForwardList, articleCategory, } from "../../../../serves/prove";
 import storage from "../../../util/sessionStorage"
 // import { query } from 'quill';
 export default {
@@ -61,28 +61,28 @@ export default {
     Tab, Tabs, List
   },
   created () {
-    //获取本地category数据
-    const data = sessionStorage.getItem('category')
-    this.category = JSON.parse(data)
-    console.log(data);
-  },
-  mounted () {
+    this.getCategory();
     if (!this.myId) {
       this.myId = storage.getLocalstorage('user_id')
     }
     if (this.myId != null && this.myId !== '' && this.myId !== 'undefined') {
       this.forwardapi(this.myId, '', this.limit, this.page)
     }
-
   },
+  mounted () { },
   methods: {
     //点击分类
+    async getCategory () {
+      const res = await articleCategory()
+      if (res.code === 2000) {
+        this.category = res.data;
+      } else {
+        Toast('获取数据失败')
+      }
+    },
     onClick (name, title) {
       this.page = 1
-      console.log(name, title);
-      console.log(this.category);
       const targetid = this.category.find(obj => obj.name === title)
-      console.log(targetid);
       this.forwardapi(this.myId, targetid.id, this.limit, this.page)  //需要传入user_id
     },
     //触底刷新
@@ -90,7 +90,7 @@ export default {
       this.loading = true;
       this.page++
       const res = await getUserForwardList(this.myId, id, this.limt, this.page)
-      if (res.code == 2000) {
+      if (res.code === 2000) {
         this.forwarddata = [...this.forwarddata, ...res.data.data]
         if (res.data.data.length < 1) {
           this.finished = true
@@ -101,8 +101,6 @@ export default {
     async forwardapi (user_id, id, limit, page) {
       if (id != null && id !== undefined) {
         const res = await getUserForwardList(user_id, id, limit, page)
-        console.log(res);
-        this.forwarddata = res.data.data
         this.forwarddata = res.data.data
         if (this.forwarddata.length < res.data.data.length) {
           this.loading = false
@@ -112,8 +110,8 @@ export default {
       }
     },
     //点击标题跳转转发详情
-    gomyforwarddetail (id,Tid,count,title,acover) {
-      this.$router.push({name:'myforwarddetail',query:{id:id,Tid:Tid,count:count,title:title,acover:acover}})
+    gomyforwarddetail (id,Tid,count,title,cover) {
+      this.$router.push({name:'myforwarddetail',query:{id:id,Tid:Tid,count:count,title:title,cover:cover}})
     },
     //返回上级
     GoUp () {

+ 1 - 3
src/views/userindex/my/MyForwarddetail.vue

@@ -42,9 +42,8 @@ export default {
   mounted () {
     this.titile=this.$route.query.title
     this.count=this.$route.query.count
-    this.acover=this.$route.query.acover 
+    this.acover=this.$route.query.cover
     this.Tid=this.$route.query.Tid
-    console.log(this.titile,this.count,this.acover)
     this.getshareDetails(this.$route.query.Tid)
   },
   methods: {
@@ -54,7 +53,6 @@ export default {
     async getshareDetails (id) {
       const res = await shareDetails(id)
       this.brows=res.data.brows
-      console.log(res)
     },
     //返回上级
     GoUp () {

+ 9 - 13
src/views/userindex/my/MyIndex.vue

@@ -51,28 +51,26 @@ export default {
     }
   },
   created () {
-  
-    
-  },
-  mounted () {
     if(!this.myId){
       this.myId = storage.getLocalstorage('user_id')
     }
     if (this.myId != null && this.myId !== '' && this.myId !== 'undefined') {
       this.getMemberapi(this.myId)
-    } 
+    }
+  },
+  mounted () {
+
   },
   methods: {
     //获取个人信息  //WeiQiJia
     async getMemberapi (user_id) {
       const res = await getMember(user_id)
-      if (res.code == 2000) {
-        this.menuberinfo = res.data.name
-        this.avatar = res.data.avatar
-        this.phone = res.data.tel
-        this.qrcode = res.data.qrcode
+      if (res.code === 2000) {
+        this.menuberinfo = res.data.name;
+        this.avatar = res.data.avatar;
+        this.phone = res.data.tel;
+        this.qrcode = res.data.qrcode;
       }
-      console.log(res)
     },
     goforward () {
       this.$router.push('myforward')
@@ -80,12 +78,10 @@ export default {
     //点击微信
     gowexin () {
       this.show = true;
-      console.log(111111);
     },
     //打电话
     callPhone(){
       window.location.href=this.phone
-      
     }
 
   },