Эх сурвалжийг харах

修改登录时登录环信,修改聊天页展示

xyg 3 жил өмнө
parent
commit
100b59d468

+ 27 - 11
light-application-wx/app.js

@@ -493,8 +493,8 @@ App({
     ToastPannel,
 
     globalData: {
-        imgPath: 'http://192.168.0.46/image',
-        // imgPath: 'https://miniapp.cqjudong.com/image',
+        // imgPath: 'http://192.168.0.46/image',
+        imgPath: 'https://miniapp.cqjudong.com/image',
         path: 'https://miniapp.cqjudong.com/base',
         // path: 'http://192.168.1.218:8081',
         Authorization: '',
@@ -505,7 +505,17 @@ App({
         saveFriendList: [],
         saveGroupInvitedList: [],
         isIPX: false, //是否为iphone X
-        channel: ''
+        channel: '',
+        roleList: [{
+            code: 'ADMIN',
+            page: '../index-admin/index-admin'
+        }, {
+            code: 'OPERATION',
+            page: '../index/index'
+        }, {
+            code: 'GUEST',
+            page: '../index-guest/index-guest'
+        }]
     },
 
     conn: {
@@ -545,16 +555,22 @@ App({
         wx.hideHomeButton()
     },
 
+    /**
+     * 环信登录成功回调
+     * @param {*} myName 
+     */
     onLoginSuccess: function (myName) {
         wx.hideLoading()
-
-        wx.navigateTo({
-            url: "../chat-room/chat-room?myName=" + myName
-        });
-
-        // wx.redirectTo({
-        // 	url: "../emediaInvite/emediaInvite?myName=" + myName
-        // });
+        let roleList = getApp().globalData.roleList;
+        let roleInfo = getApp().globalData.roleInfo;
+        for (let i in roleList) {
+            if (roleList[i].code == roleInfo.code) {
+                wx.redirectTo({
+                    url: roleList[i].page,
+                });
+                break;
+            }
+        }
     },
 
     getUserInfo(cb) {

+ 13 - 66
light-application-wx/pages/chat-room/chat-room.js

@@ -12,28 +12,7 @@ Page({
         imgPath: app.globalData.imgPath,
         cursor: null,
         limit: 10,
-        list: [{
-            id: 1,
-            username: '李袁青',
-            photo: 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fup.enterdesk.com%2Fedpic_source%2Fc0%2F8e%2F28%2Fc08e28eb52da5a2b5b451ad6272a8197.jpg&refer=http%3A%2F%2Fup.enterdesk.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1652429449&t=63437c824c18680ecb5e5f27d06f941b',
-            time: '12:30',
-            content: '好的',
-            num: 1
-        }, {
-            id: 2,
-            username: '刘东航',
-            photo: 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fup.enterdesk.com%2F2021%2Fedpic%2F01%2F4b%2F7d%2F014b7d465ef76e7a3477e749f7be6fc2_1.jpg&refer=http%3A%2F%2Fup.enterdesk.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1652429449&t=a4ba7f978addbb539b819ee2a329b9d8',
-            time: '11:30',
-            content: '下次会议时间:2022年4月13日下次会议时间:2022年4月13日',
-            num: 2
-        }, {
-            id: 3,
-            username: '尚渊明',
-            photo: 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fup.enterdesk.com%2Fedpic_source%2F95%2Fe2%2F09%2F95e20960f6bcb6d444dfa59d142e9300.jpg&refer=http%3A%2F%2Fup.enterdesk.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1652429449&t=6323d7ec61e98f009818468c239f9bbf',
-            time: '10:30',
-            content: '是的我在办公室',
-            num: 0
-        }],
+        list: [],
         search_btn: true,
         search_chats: false,
         show_mask: false,
@@ -52,41 +31,9 @@ Page({
      */
     onLoad: function (options) {
         // let that = this;
-        // util.post({
-        //     url: '/api/easemob/getToken',
-        //     success: (res) => {
-        //         wx.hideLoading({
-        //           success: (res) => {},
-        //         })
-        //         console.info(res);
-        //     }
-        // });
-
-        // util.post({
-        //     url: '/api/easemob/queryUserPage',
-        //     header: {
-        //         'content-type': 'application/x-www-form-urlencoded'
-        //     },
-        //     data: {
-        //         cursor: that.data.cursor,
-        //         limit: that.data.limit
-        //     },
-        //     success: (res) => {
-        //         wx.hideLoading();
-        //         console.info(res);
-        //         that.setData({
-        //             arr: res.data.data.entities
-        //         });
-        //     }
-        // });
-
-
         // this.getRoster();
-        this.getChatList();
-
-        // if (wx.canIUse('hideHomeButton')) {
-        //     wx.hideHomeButton()
-        // }
+        this.listGroups();
+        // this.getChatList();
     },
 
     /**
@@ -147,7 +94,7 @@ Page({
         });
     },
 
-    getRoster() {
+    getRoster: function () {
         let me = this;
         let rosters = {
             success(roster) {
@@ -180,7 +127,7 @@ Page({
         WebIM.conn.getRoster(rosters);
     },
 
-    listGroups() {
+    listGroups: function () {
         var me = this;
         return WebIM.conn.getGroup({
             limit: 50,
@@ -199,7 +146,7 @@ Page({
                     key: "listGroup",
                     data: res.data
                 });
-                me.getChatList()
+                me.getChatList();
             },
             error: function (err) {
                 console.log(err)
@@ -208,7 +155,7 @@ Page({
     },
 
     // 包含陌生人版本
-    getChatList() {
+    getChatList: function () {
         var myName = wx.getStorageSync("myUsername");
         var array = [];
         const me = this
@@ -251,7 +198,7 @@ Page({
                         let timeArr = lastChatMsg.time.split(' ')[1].split(':')
                         let month = dateArr[2] < 10 ? '0' + dateArr[2] : dateArr[2]
                         lastChatMsg.dateTimeNum = `${dateArr[1]}${month}${timeArr[0]}${timeArr[1]}${timeArr[2]}`
-                        lastChatMsg.time = `${dateArr[1]}月${dateArr[2]}日 ${timeArr[0]}时${timeArr[1]}分`
+                        lastChatMsg.time = `${dateArr[1]}/${dateArr[2]} ${timeArr[0]}:${timeArr[1]}`
                         newChatMsgKeys.splice(index, 1)
                     } else {
                         let historyChatMsgs = wx.getStorageSync(historyChatMsgKeys[i]);
@@ -261,7 +208,7 @@ Page({
                             let timeArr = lastChatMsg.time.split(' ')[1].split(':')
                             let month = dateArr[2] < 10 ? '0' + dateArr[2] : dateArr[2]
                             lastChatMsg.dateTimeNum = `${dateArr[1]}${month}${timeArr[0]}${timeArr[1]}${timeArr[2]}`
-                            lastChatMsg.time = `${dateArr[1]}月${dateArr[2]}日 ${timeArr[0]}时${timeArr[1]}分`
+                            lastChatMsg.time = `${dateArr[1]}/${dateArr[2]} ${timeArr[0]}:${timeArr[1]}`
                         }
                     }
                 } else {
@@ -272,9 +219,8 @@ Page({
                         let timeArr = lastChatMsg.time.split(' ')[1].split(':')
                         let month = dateArr[2] < 10 ? '0' + dateArr[2] : dateArr[2]
                         lastChatMsg.dateTimeNum = `${dateArr[1]}${month}${timeArr[0]}${timeArr[1]}${timeArr[2]}`
-                        lastChatMsg.time = `${dateArr[1]}月${dateArr[2]}日 ${timeArr[0]}时${timeArr[1]}分`
+                        lastChatMsg.time = `${dateArr[1]}/${dateArr[2]} ${timeArr[0]}:${timeArr[1]}`
                     }
-
                 }
                 if (lastChatMsg.chatType == 'groupchat' || lastChatMsg.chatType == 'chatRoom') {
                     lastChatMsg.groupName = me.data.groupName[lastChatMsg.info.to]
@@ -294,7 +240,7 @@ Page({
                     let timeArr = lastChatMsg.time.split(' ')[1].split(':')
                     let month = dateArr[2] < 10 ? '0' + dateArr[2] : dateArr[2]
                     lastChatMsg.dateTimeNum = `${dateArr[1]}${month}${timeArr[0]}${timeArr[1]}${timeArr[2]}`
-                    lastChatMsg.time = `${dateArr[1]}月${dateArr[2]}日 ${timeArr[0]}时${timeArr[1]}分`
+                    lastChatMsg.time = `${dateArr[1]}/${dateArr[2]} ${timeArr[0]}:${timeArr[1]}`
                     if (lastChatMsg.chatType == 'groupchat' || lastChatMsg.chatType == 'chatRoom') {
                         lastChatMsg.groupName = me.data.groupName[lastChatMsg.info.to]
                     }
@@ -304,7 +250,7 @@ Page({
 
             array.sort((a, b) => {
                 return b.dateTimeNum - a.dateTimeNum
-            })
+            });
             console.info(array)
             this.setData({
                 arr: array
@@ -413,6 +359,7 @@ Page({
 
     into_chatRoom: function (event) {
         let detail = event.currentTarget.dataset.item;
+        console.info('detail:' + detail);
         //群聊的chatType居然是singlechat?脏数据? 等sdk重写后整理一下字段
         if (detail.chatType == 'groupchat' || detail.chatType == 'chatRoom' || detail.groupName) {
             this.into_groupChatRoom(detail)

+ 2 - 2
light-application-wx/pages/chat-room/chat-room.wxml

@@ -14,12 +14,12 @@
         </view>
     </view>
 </scroll-view> -->
-<scroll-view scroll-y="true" class="chat-room chat_list_wraper {{gotop? (isIPX? 'goTopX': 'goTop'): 'goback'}}" style="padding-bottom: {{isIPX?'270rpx':'226rpx'}}">
+<scroll-view scroll-y="true" class="chat-room">
     <view class="otherItem" bindtap="into_groups">
         <image src="{{imgPath}}/chat-group.png"></image>
         <text>群组</text>
     </view>
-    <view class="chat" wx:for="{{arr}}" wx:key="i" data-item="{{ item }}" catchtap="into_chatRoom">
+    <view class="chat" wx:for="{{arr}}" wx:key="i" data-item="{{item}}" catchtap="into_chatRoom">
         <image class="photo" src="{{ (item.chatType == 'groupchat' || item.chatType == 'chatRoom') ? imgPath + '/chat-group2.png' : imgPath + '/chat-user.png'}}" mode="cover"></image>
         <view class="item-row">
             <text class="chat-name">{{(item.chatType == 'groupchat' || item.chatType == 'chatRoom' || item.groupName) ? item.groupName : item.username}}</text>

+ 16 - 3
light-application-wx/pages/chat-room/chat-room.wxss

@@ -51,14 +51,25 @@
 }
 
 .chat-name {
-    font-size: 1.1em;
+    font-size: .9em;
+    width: 70%;
+    display: -webkit-box;
+    overflow: hidden;
+    text-overflow: ellipsis;
+    -webkit-box-orient: vertical;
+    -webkit-line-clamp: 1;
 }
 
 .chat-time {
-    font-size: .9em;
+    font-size: .7em;
     color: #9a9a9a;
     position: absolute;
     right: 40rpx;
+    display: -webkit-box;
+    overflow: hidden;
+    text-overflow: ellipsis;
+    -webkit-box-orient: vertical;
+    -webkit-line-clamp: 1;
 }
 
 .chat-content {
@@ -82,7 +93,9 @@
     color: white;
     position: absolute;
     right: 48rpx;
-    margin-top: 48rpx;
+    margin-top: 50rpx;
+    box-sizing: border-box;
+    font-size: .8em;
 }
 
 

+ 13 - 23
light-application-wx/pages/index-admin/index-admin.js

@@ -1,15 +1,13 @@
 // pages/index-admin/index-admin.js
 const app = getApp();
 const util = require('../../utils/util.js');
-const WebIM = require("../../utils/WebIM")["default"];
-const CusBase64 = require('../../utils/base64.js');
+
 Page({
 
     /**
      * 页面的初始数据
      */
     data: {
-        grant_type: "password",
         imgPath: app.globalData.imgPath,
         path: app.globalData.path,
         username: app.globalData.userInfo.usernameShow,
@@ -265,12 +263,13 @@ Page({
                                         SSID: wifi,
                                         password: pass,
                                         success: (res) => {
-                                            console.info(res);
-                                            // 5、连接上Wi-Fi的事件回调
-                                            wx.onWifiConnected((result) => {
-                                                console.info(result);
+                                            wx.hideLoading();
+                                            console.info('connectWifi', res);
+                                            if (res.errMsg == 'connectWifi:ok') {
                                                 util.toast('WIFI连接成功', 'success');
-                                            });
+                                            } else {
+                                                util.toast(res.errMsg);
+                                            }
                                         },
                                         fail: (e) => {
                                             console.info(e);
@@ -281,7 +280,10 @@ Page({
                                     util.toast(res.errMsg);
                                 }
                             },
-                            fail: (e) => { }
+                            fail: (e) => {
+                                console.info(e);
+                                util.toast('初始化WiFi模块失败');
+                            }
                         });
                     },
                     fail: (e) => {
@@ -310,20 +312,8 @@ Page({
      * 聊天室
      */
     chatRoom: function () {
-        let that = this;
-        that.setData({
-            user: app.globalData.userInfo.phone
-        });
-        wx.setStorage({
-            key: "myUsername",
-            data: that.data.user
-        });
-        app.conn.open({
-            // apiUrl: WebIM.config.apiURL,
-            user: that.data.user,
-            pwd: CusBase64.CusBASE64.encoder(that.data.user),
-            grant_type: that.data.grant_type,
-            appKey: WebIM.config.appkey
+        wx.navigateTo({
+            url: '../chat-room/chat-room',
         });
     },
 

+ 13 - 24
light-application-wx/pages/index-guest/index-guest.js

@@ -1,15 +1,12 @@
 // pages/index-guest/index-guest.js
 const app = getApp();
 const util = require('../../utils/util.js');
-const WebIM = require("../../utils/WebIM")["default"];
-const CusBase64 = require('../../utils/base64.js');
 Page({
 
     /**
      * 页面的初始数据
      */
     data: {
-        grant_type: "password",
         imgPath: app.globalData.imgPath,
         path: app.globalData.path,
         username: app.globalData.userInfo.usernameShow,
@@ -243,19 +240,20 @@ Page({
                         // 1、初始化Wi-Fi模块
                         wx.startWifi({
                             success: (res) => {
-                                console.info(res)
+                                console.info('startWifi', res)
                                 if (res.errMsg == 'startWifi:ok') {
                                     // 4、连接Wi-Fi
                                     wx.connectWifi({
                                         SSID: wifi,
                                         password: pass,
                                         success: (res) => {
-                                            console.info(res);
-                                            // 5、连接上Wi-Fi的事件回调
-                                            wx.onWifiConnected((result) => {
-                                                console.info(result);
+                                            wx.hideLoading();
+                                            console.info('connectWifi', res);
+                                            if (res.errMsg == 'connectWifi:ok') {
                                                 util.toast('WIFI连接成功', 'success');
-                                            });
+                                            } else {
+                                                util.toast(res.errMsg);
+                                            }
                                         },
                                         fail: (e) => {
                                             console.info(e);
@@ -266,7 +264,10 @@ Page({
                                     util.toast(res.errMsg);
                                 }
                             },
-                            fail: (e) => { }
+                            fail: (e) => {
+                                console.info(e);
+                                util.toast('初始化WiFi模块失败');
+                            }
                         });
                     },
                     fail: (e) => {
@@ -287,20 +288,8 @@ Page({
      * @param {*} e 
      */
     chatRoom: function (e) {
-        let that = this;
-        that.setData({
-            user: app.globalData.userInfo.phone
-        });
-        wx.setStorage({
-            key: "myUsername",
-            data: that.data.user
-        });
-        app.conn.open({
-            // apiUrl: WebIM.config.apiURL,
-            user: that.data.user,
-            pwd: CusBase64.CusBASE64.encoder(that.data.user),
-            grant_type: that.data.grant_type,
-            appKey: WebIM.config.appkey
+        wx.navigateTo({
+            url: '../chat-room/chat-room',
         });
     },
 

+ 13 - 34
light-application-wx/pages/index/index.js

@@ -1,15 +1,13 @@
 // pages/index/index.js
 const app = getApp();
 const util = require('../../utils/util.js');
-const WebIM = require("../../utils/WebIM")["default"];
-const CusBase64 = require('../../utils/base64.js');
+
 Page({
 
     /**
      * 页面的初始数据
      */
     data: {
-        grant_type: "password",
         imgPath: app.globalData.imgPath,
         path: app.globalData.path,
         username: app.globalData.userInfo.usernameShow,
@@ -266,23 +264,13 @@ Page({
                                         SSID: wifi,
                                         password: pass,
                                         success: (res) => {
-                                            console.info(res);
-                                            // 5、连接上Wi-Fi的事件回调
-                                            wx.onWifiConnected((result) => {
-                                                console.info(result);
+                                            wx.hideLoading();
+                                            console.info('connectWifi', res);
+                                            if (res.errMsg == 'connectWifi:ok') {
                                                 util.toast('WIFI连接成功', 'success');
-                                            });
-                                            // wx.getConnectedWifi({
-                                            //     success: (result) => {
-                                            //         wx.hideLoading();
-                                            //         console.info(result)
-                                            //         if (result.wifi.SSID === SSID) {
-                                            //             // 连接成功
-                                            //         } else {
-                                            //             // 连接失败
-                                            //         }
-                                            //     },
-                                            // });
+                                            } else {
+                                                util.toast(res.errMsg);
+                                            }
                                         },
                                         fail: (e) => {
                                             console.info(e);
@@ -293,7 +281,10 @@ Page({
                                     util.toast(res.errMsg);
                                 }
                             },
-                            fail: (e) => { }
+                            fail: (e) => {
+                                console.info(e);
+                                util.toast('初始化WiFi模块失败');
+                            }
                         });
                     },
                     fail: (e) => {
@@ -314,20 +305,8 @@ Page({
      * @param {*} e 
      */
     chatRoom: function (e) {
-        let that = this;
-        that.setData({
-            user: app.globalData.userInfo.phone
-        });
-        wx.setStorage({
-            key: "myUsername",
-            data: that.data.user
-        });
-        app.conn.open({
-            // apiUrl: WebIM.config.apiURL,
-            user: that.data.user,
-            pwd: CusBase64.CusBASE64.encoder(that.data.user),
-            grant_type: that.data.grant_type,
-            appKey: WebIM.config.appkey
+        wx.navigateTo({
+            url: '../chat-room/chat-room',
         });
     },
 

+ 28 - 49
light-application-wx/pages/login/login.js

@@ -1,6 +1,9 @@
 // pages/login/login.js
 var app = getApp();
 const util = require('../../utils/util.js');
+const WebIM = require("../../utils/WebIM")["default"];
+const CusBase64 = require('../../utils/base64.js');
+
 Page({
     /**
      * 页面的初始数据
@@ -13,16 +16,7 @@ Page({
         vCode: '',
         sendText: '发送验证码',
         disabled: false,
-        roleList: [{
-            code: 'ADMIN',
-            page: '../index-admin/index-admin'
-        }, {
-            code: 'OPERATION',
-            page: '../index/index'
-        }, {
-            code: 'GUEST',
-            page: '../index-guest/index-guest'
-        }]
+        grant_type: "password",
     },
 
     /**
@@ -83,7 +77,6 @@ Page({
 
     /**
      * 手机号赋值
-     * @param {*} e 
      */
     setPhone: function (e) {
         this.setData({
@@ -93,7 +86,6 @@ Page({
 
     /**
      * 验证码赋值
-     * @param {*} e 
      */
     setVcode: function (e) {
         this.setData({
@@ -112,30 +104,26 @@ Page({
         }
         let phone = this.data.phone;
         if (!phone) {
-            wx.showToast({
-                title: '请输入手机号',
-                icon: 'error'
-            });
+            util.toast('请输入手机号', 'error');
             return false;
         }
         let reg = /1[3-9]\d{9}/;
         if (!reg.test(phone)) {
-            wx.showToast({
-                title: '手机号格式有误',
-                icon: 'error'
-            });
+            util.toast('手机号格式有误', 'error');
             return false;
         }
-        this.setData({
+
+        that.setData({
             sendText: '60s后再次发送',
             disabled: true
         });
-        this.timeTask();
+        // 再次发送短信时间倒计时
+        that.timeTask();
+
         util.post({
             url: '/api/sms/sendSms/' + that.data.phone,
             success: (res) => {
                 wx.hideLoading();
-                console.info(res);
                 if (res.code != 200) {
                     util.toast(res.data.msg);
                 } else {
@@ -174,28 +162,20 @@ Page({
         let that = this;
         let values = e.detail.value;
         if (!values.phone) {
-            wx.showToast({
-                title: '请输入手机号',
-                icon: 'error'
-            });
+            util.toast('请输入手机号', 'error');
             return false;
         }
         let reg = /1[3-9]\d{9}/;
         if (!reg.test(values.phone)) {
-            wx.showToast({
-                title: '手机号格式有误',
-                icon: 'error'
-            });
+            util.toast('手机号格式有误', 'error');
             return false;
         }
         if (!values.code) {
-            wx.showToast({
-                title: '请输入验证码',
-                icon: 'error'
-            });
+            util.toast('请输入验证码', 'error');
             return false;
         }
         values.type = 'CAPTCHA';
+
         util.post({
             url: '/login/mobile',
             data: values,
@@ -206,10 +186,7 @@ Page({
                 console.info(res);
                 let code = res.data.code;
                 if ('200' != code) {
-                    wx.showToast({
-                        title: res.data.msg,
-                        icon: 'error'
-                    });
+                    util.toast(res.data.msg);
                 } else {
                     app.globalData.Authorization = res.data.data.Authorization;
                     that.getUserInfo();
@@ -233,15 +210,18 @@ Page({
                     let datas = res.data.data;
                     app.globalData.userInfo = datas;
                     app.globalData.roleInfo = datas.roleList[0];
-                    let roleList = that.data.roleList;
-                    for (let i in roleList) {
-                        if (roleList[i].code == datas.roleList[0].code) {
-                            wx.redirectTo({
-                                url: roleList[i].page
-                            });
-                            break;
-                        }
-                    }
+
+                    wx.setStorage({
+                        key: "myUsername",
+                        data: datas.phone
+                    });
+                    app.conn.open({
+                        // apiUrl: WebIM.config.apiURL,
+                        user: datas.phone,
+                        pwd: CusBase64.CusBASE64.encoder(datas.phone),
+                        grant_type: that.data.grant_type,
+                        appKey: WebIM.config.appkey
+                    });
                 }
             }
         });
@@ -249,7 +229,6 @@ Page({
 
     /**
      * 微信获取手机号快捷登录
-     * @param {*} res 
      */
     getPhoneNumber: function (res) {
         let that = this;