Bläddra i källkod

聊天工具栏

jiaweiqi 1 år sedan
förälder
incheckning
f9d8992e9f
5 ändrade filer med 182 tillägg och 137 borttagningar
  1. 3 1
      package.json
  2. 2 2
      serves/axios.js
  3. 5 5
      serves/prove.js
  4. 166 122
      src/views/Fuzeren/FuzerenView.vue
  5. 6 7
      src/views/Fuzeren/GetMyId.vue

+ 3 - 1
package.json

@@ -47,7 +47,9 @@
     "parserOptions": {
       "parser": "@babel/eslint-parser"
     },
-    "rules": {}
+    "rules": {
+      "no-unused-vars": "off"
+    }
   },
   "browserslist": [
     "> 1%",

+ 2 - 2
serves/axios.js

@@ -2,9 +2,9 @@ import axios from "axios";
 // import { gettoken } from "../services/token";
 // axios.defaults.withCredentials=true;
 const instance = axios.create({
-  // baseURL: 'http://192.168.2.164:8899', //请求的基础地址
+  //baseURL: 'http://192.168.2.164:8899', //请求的基础地址
   baseURL: 'https://scrm.zzliaoyuan.com/backend', //请求的基础地址
-  timeout: 5000, //请求超时的时间
+  timeout: 60000, //请求超时的时间
 });
 //发一个get请求
 

+ 5 - 5
serves/prove.js

@@ -13,15 +13,15 @@ export const forwardInfo = (userid, category) => get(`/api/content/share/?userid
 //取user_id
 export const  getUser_Id=(code)=>get(`/api/customer/chat_side/userid/?query_code=${code}`)
 //动态
-export const  getTrends=(user_id)=>get(`/api/customer/chat_side/action/?external_userid=wmWY7dCwAAJbsYIgpmdD991EvM2NbAcA&user_id=${user_id}`)
+export const  getTrends=(user_id, contact_id)=>get(`/api/customer/chat_side/action/?external_userid=${contact_id}&user_id=${user_id}`)
 //订单
-export const  getOrder=(user_id)=>get(`/api/customer/chat_side/order/?external_userid=wmWY7dCwAAJbsYIgpmdD991EvM2NbAcA&user_id=${user_id}`)
+export const  getOrder=(user_id, contact_id)=>get(`/api/customer/chat_side/order/?external_userid=${contact_id}&user_id=${user_id}`)
 //获取参数
-export const  getparameter=()=>get('/api/customer/chat_side/params/')
+export const  getparameter=(data)=>post(`/api/customer/chat_side/params/`, data)
 //获取上半页数据
-export const getUpperhalfpage=(user_id)=>get(`/api/customer/chat_side/base/?external_userid=wmWY7dCwAAJbsYIgpmdD991EvM2NbAcA&user_id=${user_id}`)
+export const getUpperhalfpage=(user_id, contact_id)=>get(`/api/customer/chat_side/base/?external_userid=${contact_id}&user_id=${user_id}`)
 //获取详情数据
-export const getDetails=(user_id)=>get(`/api/customer/chat_side/detail/?external_userid=wmWY7dCwAAJbsYIgpmdD991EvM2NbAcA&user_id=${user_id}`)
+export const getDetails=(user_id, contact_id)=>get(`/api/customer/chat_side/detail/?external_userid=${contact_id}&user_id=${user_id}`)
 //H获取首页轮播图 图片地址
 export const getSwiperUrl=()=>get(`/api/content/agent/ration/`)
 //H文章分类

+ 166 - 122
src/views/Fuzeren/FuzerenView.vue

@@ -4,7 +4,7 @@
     <div class="top-color">
       <div class="top-fuzeren">
         <span class="top-fuzeren-fs">负责人 | <ww-open-data type="userName"
-                        :openid=myId></ww-open-data> </span>
+                                                         :openid=myId></ww-open-data> </span>
       </div>
     </div>
 
@@ -152,9 +152,9 @@
                   <div class="CI-flex">
                     <span class="span1">手机号</span>
                     <div> <span class="span2"
-                            v-for="(item ,index ) in PhoneNumber"
-                            :key="index"
-                            @click="telPhoneNumber(item)">{{item}} </span></div>
+                                v-for="(item ,index ) in PhoneNumber"
+                                :key="index"
+                                @click="telPhoneNumber(item)">{{item}} </span></div>
                   </div>
                 </div>
                 <!-- second -->
@@ -249,12 +249,11 @@
 import { Tab, Tabs, Step, Steps } from "vant";
 import { getTrends, getOrder, getUpperhalfpage, getDetails, getparameter,getUser_Id } from '../../../serves/prove';//, getUser_Id
 import sessionStorage from '../../util/sessionStorage'
-// var wx=window.wx
 export default {
   data () {
     return {
-      wx_password: "淡忘-zhouzhandui",
-      xinxipass: "zhouzhandui",
+      wx_password: "",
+      xinxipass: "",
       active: 0,
       userimg: '', //头像
       labelList: [], //标签
@@ -286,36 +285,43 @@ export default {
   components: {
     Tab, Tabs, Step, Steps
   },
-  created () {
-    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: 'GetMyId' })
-      }
+  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
+            this.getConfigParams({'url': location.href.split('#')[0]});
+        } else {
+            this.$router.push({ name: 'GetMyId' })
+        }
     } else {
-      getUser_Id().then(res => {
-        if (res.code == 2000) {
-      this.myId=res.data.user_id
-          sessionStorage.setLocalstorage('user_id', res.data.user_id)
+        let result = await getUser_Id(auth_code);
+        if (result.code !== 2000) {
+            alert(result.msg)
+            return false
         }
-      })
+        let { user_id } = result.data;
+        this.myId = user_id;
+        sessionStorage.setLocalstorage('user_id', user_id);
+        this.getConfigParams({'url': location.href.split('#')[0]});
     }
   },
   methods: {
     onClick (name, title) {
       if (name == 1) {
         //动态
-        getTrends(this.myId).then(res => {
+        getTrends(this.myId, this.contactsUserId).then(res => {
           if (res.code == 2000) {
             this.action = res.data.reverse()
           }
         })
-        console.log(name, title)
       } else if (name == 2) {
         //订单
-        getOrder(this.myId).then(res => {
+        getOrder(this.myId, this.contactsUserId).then(res => {
           if (res.code === 2000) {
             this.orderData = res.data
           }
@@ -331,113 +337,151 @@ export default {
       window.location.href = item
     },
 
-    //获取参数信息
-    getUserIdparameter () {
-      getparameter().then(res => {
-        if (res.code == 2000) {
-          this.userIdparameter.corpid = res.data.appId
-          this.userIdparameter.agentid = res.data.agentid
-          this.userIdparameter.timestamp = res.data.timestamp
-          this.userIdparameter.nonceStr = res.data.nonceStr
-          this.userIdparameter.signature = res.data.signature
-          this.userIdparameter.agent_signature = res.data.agent_signature
-          this.getcontactUserId(res.data.appId, res.data.timestamp, res.data.nonceStr, res.data.signature, res.data.agentid, res.data.agent_signature)
+      //获取参数信息
+    async getConfigParams (url) {
+        let result = await getparameter(url);
+        if (result.code !== 2000) {
+            alert(result.msg)
+            return false;
         }
-      })
+        let { appId, agentid, timestamp, nonceStr, signature, agent_signature } = result.data;
+        this.userIdparameter.corpid = appId;
+        this.userIdparameter.agentid = agentid;
+        this.userIdparameter.timestamp = timestamp;
+        this.userIdparameter.nonceStr = nonceStr;
+        this.userIdparameter.signature = signature;
+        this.userIdparameter.agent_signature = agent_signature;
+        this._Config(appId, timestamp, nonceStr, signature)
+            .then(data => {
+                return this._agentConfig(appId, agentid, timestamp, nonceStr, agent_signature)
+            })
+            .then(data => {
+                return this._getContext()
+            })
+            .then(data => {
+                return this._getCurExternalContact()
+            })
+            .then(data => {
+                this.contactsUserId = data;
+                window.WWOpenData.bind(document.querySelector('ww-open-data'));
+                this.getUpperHalfPage();
+                this.getDetails();
+            })
+            .catch(data => {
+                alert(data)
+            })
     },
-    //获取联系人userId ,agentid
-    getcontactUserId (appId, timestamp, nonceStr, signature, agentid, agent_signature) {
-      console.log(this.userIdparameter)
-      // var WXconfig = require("weixin-js-sdk");
-      //console.log('---------->>window',window)
-      //  var wx = require("ts-jwsdk");
-      const wx = window.wx
-      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'], // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
-      });
-      wx.ready(function () {
-        // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。
-        console.log('------------------>>>config_success')
-      })
-      console.log('123123', appId, timestamp, nonceStr, signature, agentid, agent_signature)
-      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) {
-          console.log('agentConfig=>成功')
-          console.log('获取agentConfig的res', res)
-          //执行getContext 获取进入H5入口环境
-          wx.invoke('getContext', {
-          }, function (res) {
-            wx.WWOpenData.bind(document.querySelector('ww-open-data'))
-            if (res.err_msg == "getContext:ok") {
-              // entry  = res.entry ; 返回进入H5页面的入口类型,目前有normal、contact_profile、single_chat_tools、group_chat_tools、chat_attachment
-              // shareTicket = res.shareTicket; //可用于调用getShareInfo接口
-              wx.invoke('getCurExternalContact', {
-              }, function (res) {
-                if (res.err_msg == "getCurExternalContact:ok") {
-                  //防止数据太深拿不到数据
-                  this.$nextTick(() => {
-                    this.contactsUserId = res.userId; //返回当前外部联系人userId
-                    console.log('当前联系人id', res.userId)
-                    sessionStorage.set('contactsUserId', res.userId)
-                  });
-                } else {
-                  //错误处理
-                  console.log('无法获取当前联系人id')
-                }
-              });
-            } else {
-              //错误处理
-              console.log('请从正确的路径进入')
+    _Config (appId, timestamp, nonceStr, signature) {
+        return new Promise(function (resolve, reject) {
+            const wx = window.wx;
+            if (!wx) {
+                reject("企业微信apk引入失败,尝试刷新页面!")
             }
-          });
-        },
-        fail: function (res) {
-          console.log('agentConfig=>失败')
-          if (res.errMsg.indexOf('function not exist') > -1) {
-            console.log('版本过低请升级')
+            wx.config({
+                beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
+                debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
+                appId: appId, // 必填,企业微信的corpID
+                timestamp: timestamp, // 必填,生成签名的时间戳
+                nonceStr: nonceStr, // 必填,生成签名的随机串
+                signature: signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法
+                jsApiList: ['agentConfig'], // 必填,需要使用的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引入失败,尝试刷新页面!")
           }
-        }
-      });
-    }
-  },
-  mounted () {
-    //上半页面数据
-    getUpperhalfpage(this.myId).then(res => {
-      if (res.code == 2000) {
-        this.wx_password = res.data.nick_name
-        this.userimg = res.data.avatar
-        this.labelList = res.data.tag
-        this.relationship = res.data.service_count
-        this.tel = res.data.tel
+          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("应用注入权限验证失败")
+                  }
+              }
+          })
+        })
+    },
+    _getContext() {
+      return new Promise(function (resolve, reject) {
+        window.wx.invoke('getContext', {}, function (res) {
+            if (res.err_msg !== "getContext:ok") {
+              reject(res)
+            }
+            if (res.entry !== 'single_chat_tools') {
+              reject("请从单聊会话工具栏进入!")
+            }
+            resolve()
+        });
+      })
+    },
+    _getCurExternalContact() {
+      return new Promise(function (resolve, reject) {
+        window.wx.invoke('getCurExternalContact', {}, function (res) {
+          if (res.err_msg !== "getCurExternalContact:ok") {
+              reject("获取当前联系人id失败!")
+          }
+          resolve(res.userId)
+        });
+      })
+    },
+
+    async getUpperHalfPage() {
+      if (!this.myId || !this.contactsUserId)  {
+          alert("参数缺失!")
+          return false
       }
-    })
-    //详情
-    getDetails(this.myId).then(res => {
-      if (res.code == 2000) {
-        this.LabelBarModule.nickName = res.data.nick_name
-        this.LabelBarModule.sex = res.data.gender_f
-        this.LabelBarModule.birthday = res.data.birthday
-        this.LabelBarModule.email = res.data.email
-        this.PhoneNumber = res.data.tel
-        this.address = res.data.address
+      let result = await getUpperhalfpage(this.myId, this.contactsUserId);
+      if (result.code !== 2000) {
+          alert(result.msg)
+          return false
       }
-    })
-    //权限参数信息
-    // this.getUserIdparameter()
+      let { nick_name, avatar, tag, service_count, tel } = result.data;
+      this.wx_password = nick_name;
+      this.userimg = avatar;
+      this.labelList = tag;
+      this.relationship = service_count;
+      this.tel = tel;
+    },
 
+    async getDetails() {
+      if (!this.myId || !this.contactsUserId) {
+          alert("参数缺失!")
+          return false
+      }
+      let result = await getDetails(this.myId, this.contactsUserId);
+      if (result.code !== 2000) {
+          alert(result.msg)
+          return false
+      }
+      let { nick_name, gender_f, birthday, email, tel, address } = result.data;
+      this.LabelBarModule.nickName = nick_name;
+      this.LabelBarModule.sex = gender_f;
+      this.LabelBarModule.birthday = birthday;
+      this.LabelBarModule.email = email;
+      this.PhoneNumber = tel;
+      this.address = address;
+    },
   },
+  mounted () {},
 
 };
 </script>

+ 6 - 7
src/views/Fuzeren/GetMyId.vue

@@ -2,7 +2,6 @@
     <div></div>
 </template>
 <script>
-import { query } from 'quill';
 import { get } from '../../../serves/axios';
 
 export default{
@@ -35,18 +34,18 @@ export default{
         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
       setCode(){
-        let query =this.getQuery()
+        let query = this.getQuery()
         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`
+            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:'fuzeren',query:{code:query.code}})
+            this.$router.push({name:'fuzeren',query:{auth_code:query.code}})
         }
       }
     },