Przeglądaj źródła

修改小程序扫描群聊小程序码加入群聊,修改聊天室扫描群聊小程序码加入群聊

xyg 3 lat temu
rodzic
commit
7f474ace6b

+ 36 - 19
light-application-wx/pages/chat-room/chat-room.js

@@ -526,36 +526,53 @@ Page({
             onlyFromCamera: true,
             success: (res) => {
                 console.info('scanCode', res);
-                if (res.result) {
-                    util.post({
-                        url: '/api/easemob/addGroupUser',
-                        data: {
-                            chatgroupid: res.result,
-                            usernames: [wx.getStorageSync('myUsername')]
-                        },
+                if (res.path) {
+                    let scene = res.path.split('=')[1];
+                    util.get({
+                        url: '/api/wechat/getQrCodeParams?key=' + scene,
                         success: (res) => {
                             wx.hideLoading();
-                            console.info('addGroupUser', res);
+                            console.info(res);
                             if (res.data.code != 200) {
                                 util.toast(res.data.msg);
                             } else {
-                                let datas = res.data.data;
-                                if (datas && datas.error) {
-                                    if (datas.error == 'not_found') {
-                                        util.toast('群聊不存在');
-                                    } else if (datas.error == 'forbidden_op') {
-                                        util.toast('请勿重复加入');
-                                    } else {
-                                        util.toast(datas.error);
-                                    }
+                                // 扫码加群
+                                if ('GROUP' == res.data.data.type) {
+                                    let groupId = res.data.data.groupId;
+                                    util.post({
+                                        url: '/api/easemob/addGroupUser',
+                                        data: {
+                                            chatgroupid: groupId,
+                                            usernames: [wx.getStorageSync('myUsername')]
+                                        },
+                                        success: (res) => {
+                                            wx.hideLoading();
+                                            console.info('addGroupUser', res);
+                                            if (res.data.code != 200) {
+                                                util.toast(res.data.msg);
+                                            } else {
+                                                let datas = res.data.data;
+                                                if (datas && datas.error) {
+                                                    if (datas.error == 'not_found') {
+                                                        util.toast('您要加入的群聊不存在');
+                                                    } else if (datas.error == 'forbidden_op') {
+                                                        util.toast('您已经在群聊中了,请不要重复加入');
+                                                    } else {
+                                                        util.toast(datas.error);
+                                                    }
+                                                } else {
+                                                    util.toast('群聊加入成功');
+                                                }
+                                            }
+                                        }
+                                    });
                                 } else {
-                                    util.toast(res.data.msg);
+                                    util.toast('请扫描群聊小程序码');
                                 }
                             }
                         }
                     });
                 }
-
             },
             fail: (err) => {
                 console.info('scanCode', err);

+ 47 - 10
light-application-wx/pages/index/index.js

@@ -20,13 +20,6 @@ Page({
      * 生命周期函数--监听页面加载
      */
     onLoad: function (options) {
-        // console.info('userinfo', app.globalData.userInfo);
-        // console.info('roleinfo', app.globalData.roleInfo);
-        this.setData({
-            username: app.globalData.userInfo.usernameShow,
-            role_name: app.globalData.roleInfo.name,
-            roleCode: app.globalData.roleInfo.code,
-        });
         let that = this;
         if (!app.globalData.userInfo.usernameShow || !app.globalData.userInfo.nickName || !app.globalData.userInfo.headImgUrl) {
             wx.showModal({
@@ -61,7 +54,8 @@ Page({
                                 util.toast('拒绝授权将影响您的体验感');
                                 that.setData({
                                     username: '未知用户',
-                                    role_name: app.globalData.roleInfo.name
+                                    role_name: app.globalData.roleInfo.name,
+                                    roleCode: app.globalData.roleInfo.code,
                                 });
                             }
                         });
@@ -71,7 +65,50 @@ Page({
         } else {
             that.setData({
                 username: app.globalData.userInfo.usernameShow,
-                role_name: app.globalData.roleInfo.name
+                role_name: app.globalData.roleInfo.name,
+                roleCode: app.globalData.roleInfo.code,
+            });
+        }
+
+        // 加入群聊
+        if (wx.getStorageSync('groupId')) {
+            let groupId = wx.getStorageSync('groupId');
+            util.post({
+                url: '/api/easemob/addGroupUser',
+                data: {
+                    chatgroupid: groupId,
+                    usernames: [wx.getStorageSync('myUsername')]
+                },
+                success: (res) => {
+                    wx.hideLoading();
+                    console.info('addGroupUser', res);
+                    if (res.data.code != 200) {
+                        util.toast(res.data.msg);
+                    } else {
+                        let datas = res.data.data;
+                        if (datas && datas.error) {
+                            if (datas.error == 'not_found') {
+                                wx.showModal({
+                                    content: '您要加入的群聊不存在',
+                                    showCancel: false
+                                });
+                            } else if (datas.error == 'forbidden_op') {
+                                wx.showModal({
+                                    content: '您已经在群聊中了,请不要重复加入',
+                                    showCancel: false
+                                });
+                            } else {
+                                util.toast(datas.error);
+                            }
+                        } else {
+                            wx.showModal({
+                                content: '群聊加入成功',
+                                showCancel: false
+                            });
+                        }
+                    }
+                    wx.removeStorageSync('groupId');
+                }
             });
         }
     },
@@ -106,7 +143,7 @@ Page({
                             nextUnit: datas.receptionObject
                         });
                     } else {
-                        util.toast('暂无下一场会议');
+                        // util.toast('暂无下一场会议');
                     }
                 }
             }

+ 31 - 1
light-application-wx/pages/login/login.js

@@ -23,7 +23,37 @@ Page({
      */
     onLoad: function (options) {
         console.info(options);
-        let scene = decodeURIComponent(options.scene);
+        if (options && options.scene) {
+            // let scene = decodeURIComponent(options.scene);
+            util.get({
+                url: '/api/wechat/getQrCodeParams?key=' + options.scene,
+                success: (res) => {
+                    wx.hideLoading();
+                    console.info(res);
+                    if (res.data.code != 200) {
+                        util.toast(res.data.msg);
+                    } else {
+                        // 判断时间戳是否过期(无需判断)
+                        // let timestamp = res.data.data.timeStamp;
+                        // let now = new Date().getTime();
+                        // console.info(timestamp, now);
+                        // 扫码加群
+                        if ('GROUP' == res.data.data.type) {
+                            wx.setStorageSync('groupId', res.data.data.groupId);
+                            // util.toast('登录成功后方可加入群聊');
+                            wx.showModal({
+                                content: '您需要先登录,才可加入群聊',
+                                showCancel: false
+                            });
+                        }
+                        // 扫码连接WIFI
+                        else if ('WIFI' == res.data.data.type) {
+                            // 连接WIFI代码
+                        }
+                    }
+                }
+            });
+        }
     },
 
     /**