wansfa 1 year ago
parent
commit
8123343943

+ 54 - 4
src/layout/index.vue

@@ -55,6 +55,7 @@ import { AppMain, Navbar, Settings, Sidebar, TagsView } from './components'
 import ResizeMixin from './mixin/ResizeHandler'
 import { mapState } from 'vuex'
 
+
 export default {
   name: 'Layout',
   components: {
@@ -73,8 +74,8 @@ export default {
       showSettings: state => state.settings.showSettings,
       needTagsView: state => state.settings.tagsView,
       fixedHeader: state => state.settings.fixedHeader,
-      isCall:state => state.user.isCall
-
+      isCall:state => state.user.isCall,
+      companyUser:state => state.user.user
     }),
     classObj() {
       return {
@@ -93,9 +94,17 @@ export default {
         open:false,
         title:'呼叫'
       },
-      
     }
   },
+  created() {
+      
+  },
+  mounted () {
+       console.log("qxj mounted companyUser:"+JSON.stringify(this.companyUser));
+       if(this.companyUser.userType=="00"){
+          this.initSocket(this.companyUser.userId);
+       }
+  },
   methods: {
     callPhone(){
         this.callNumber(this.mobile);
@@ -122,7 +131,48 @@ export default {
     callClose(){
       this.callOff()
       this.$store.dispatch('CallOff')
-    }
+    },
+    initSocket(userId) {
+        let that=this;
+        if(!!this.qwIm.aSoket){
+            this.qwIm.initASocket(userId,true,this);
+            // 监听socket连接
+            this.qwIm.aSoket.onopen = function() {
+                console.log("socket 连接成功...");
+            };
+            this.qwIm.aSoket.onerror = function() {
+                console.log("连接错误")
+            };
+            // 监听socket消息
+            const IMUI = this.$refs.IMUI;
+            this.qwIm.aSoket.onmessage = function(res) {
+                  var data=JSON.parse(res.data);
+                  //console.log("收到服务端内容", JSON.stringify(data));
+                  if(data.cmd=="heartbeat"){ //收到心跳数据不处理
+                      console.log("heartbeat");
+                  }
+                  //接收消息
+                  if(data.cmd=="warningMsg"){
+                      // that.$notify.warning({
+                      //     title:'预警消息',
+                      //     message: '收到预警消息',
+                      //     showClose: false
+                      // });
+                      that.$notify({
+                          title: '预警消息',
+                          message: data.msg,
+                          type: 'warning',
+                          position: 'top-right',
+                          showClose: false
+                      });
+                  }
+            };
+            // 监听socket重连
+            this.qwIm.aSoket.onreconnect = function(res) {
+                console.log("socket 断线重连...")
+            };
+        }
+    },
   }
 }
 </script>

+ 24 - 23
src/permission.js

@@ -17,33 +17,34 @@ router.beforeEach((to, from, next) => {
       next({ path: '/' })
       NProgress.done()
     } else {
+      
       if (store.getters.roles.length === 0) {
-        // 判断当前用户是否已拉取完user_info信息
-        store.dispatch('GetInfo').then(() => {
-          store.dispatch('GenerateRoutes').then(accessRoutes => {
-            // 根据roles权限生成可访问的路由表
-            router.addRoutes(accessRoutes) // 动态添加可访问路由表
-            next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
-          })
-        }).catch(err => {
-            store.dispatch('LogOut').then(() => {
-              //Message.error(err)
-              next({ path: '/' })
+      
+          // 判断当前用户是否已拉取完user_info信息
+          store.dispatch('GetInfo').then(() => {
+            store.dispatch('GenerateRoutes').then(accessRoutes => {
+              // 根据roles权限生成可访问的路由表
+              router.addRoutes(accessRoutes) // 动态添加可访问路由表
+              next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
             })
-        })
-
-        store.dispatch('GetSipAccount').then(() => {
+          }).catch(err => {
+              store.dispatch('LogOut').then(() => {
+                //Message.error(err)
+                next({ path: '/' })
+              })
+          })
 
-        }).catch(err => {
-          
-        });
+          store.dispatch('GetSipAccount').then(() => {
 
-        store.dispatch('getQwUserInfo').then(() => {
+          }).catch(err => {
+            
+          });
 
-        }).catch(err => {
+          store.dispatch('getQwUserInfo').then(() => {
 
-        });
+          }).catch(err => {
 
+          });
       } else {
         next()
       }
@@ -51,11 +52,11 @@ router.beforeEach((to, from, next) => {
   } else {
     // 没有token
     if (whiteList.indexOf(to.path) !== -1) {
-      // 在免登录白名单,直接进入
-      next()
+       // 在免登录白名单,直接进入
+       next()
     } else {
       next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
-      NProgress.done()
+          NProgress.done()
     }
   }
 })

+ 3 - 0
src/store/modules/user.js

@@ -195,6 +195,9 @@ const user = {
             })
           })
       }
+
+
+      
   }
 }
 

+ 1 - 1
src/utils/WebsocketHeartbeat.js

@@ -63,7 +63,7 @@
         };
         this.ws.onmessage = (event) => {
             var data=JSON.parse(event.data);
-            console.log("qxj onmessage data:"+JSON.stringify(data));
+            //console.log("qxj onmessage data:"+JSON.stringify(data));
             this.onmessage(event);
             //如果获取到消息,心跳检测重置
             //拿到任何消息都说明当前连接是正常的

+ 0 - 2
src/utils/call.js

@@ -78,8 +78,6 @@ export function callNumber(customerId,contactsId){
 				mobile: response.displayMobile,
 				sessionId: response.logs.sessionId
 			})
-			 
-
         }
         else{
 			that.$notify.error({

+ 26 - 2
src/utils/webSocket.js

@@ -2,15 +2,19 @@
 import WebsocketHeartbeat from "./WebsocketHeartbeat";
 
 var server = "";  
+var aServer="";
 if (process.env.NODE_ENV === 'development') {
     server = "ws://localhost:7018/imserver/r:";
+    aServer = "ws://localhost:7018/imserver/u:";
 }else{
     server = "wss://im.yjf.runtzh.com/imserver/r:";  
+    aServer = "wss://im.yjf.runtzh.com/imserver/u:";  
     //server = "ws://139.186.77.83:7018/imserver/r:";  
 }
 
 export default {
     socket: {},
+    aSoket:{},
     hasLogin:false,
     initSocket: function(uid,reset) {
         if(typeof(WebSocket) === "undefined"){
@@ -22,11 +26,10 @@ export default {
                 //this.socket = new WebSocket(server+uid);
                 this.socket=new WebsocketHeartbeat({
                     url: server+uid,
-                    userId:'r:'+uid,
+                    userId:"r:"+uid,
                     pingTimeout: 15000,
                     pongTimeout: 10000
                 });
-                let that=this;
                 // this.socket.onopen = function () {
                 //     console.log('connect success');
                 //     console.log('send massage: test');
@@ -44,6 +47,27 @@ export default {
                 this.hasLogin=true;
             }
             
+        }
+    },
+    initASocket: function(uid,reset,that) {
+        if(typeof(WebSocket) === "undefined"){
+            that.$notify.error({
+                title: '您的浏览器不支持socket',
+                showClose: false
+            });
+            console.log("您的浏览器不支持socket")
+        }else{
+            // 实例化socket
+            if(!this.aSoket || reset){
+                console.log("实例化aSocket");
+                this.aSoket=new WebsocketHeartbeat({
+                    url: aServer+uid,
+                    userId:"u:"+uid,
+                    pingTimeout: 20000,
+                    pongTimeout: 15000
+                });
+            }
+            
         }
     }
 }

+ 3 - 5
src/views/qw/qwAccounts/index.vue

@@ -3,12 +3,11 @@
     <el-row :gutter="10" class="mb8">
       <el-col :span="1.5">
         <el-button
-        type="primary"
+          type="primary"
           icon="el-icon-plus"
           size="mini"
           @click="handleAdd"
-          v-hasPermi="['qw:account:add']"
-        >添加账号</el-button>
+          v-hasPermi="['qw:account:add']">添加账号</el-button>
       </el-col>
        <right-toolbar showSearch.sync="false" @queryTable="getList"></right-toolbar>
     </el-row>
@@ -22,8 +21,7 @@
           <el-popover
             placement="right"
             title=""
-            trigger="hover"
-          >
+            trigger="hover">
             <img slot="reference" :src="scope.row.avatar" width="70">
             <img :src="scope.row.avatar" style="max-width: 120px;">
           </el-popover>

+ 9 - 3
src/views/qw/qwChat/qq.vue

@@ -96,11 +96,11 @@
         </lemon-imui>
       </div>
    
-
-       <el-dialog :visible.sync="dialogVisible">
-         <img width="100%" :src="dialogImageUrl" alt="" />
+      <el-dialog :visible.sync="dialogVisible" append-to-body width="35%">
+         <img style="width:100%;height:auto" :src="dialogImageUrl" alt="" />
       </el-dialog>
 
+     
        <el-dialog :visible.sync="dialogVideoVisible"
                :close-on-click-modal="false"
                :destroy-on-close="true"
@@ -500,6 +500,8 @@ export default {
                       console.log("socket 断线重连...")
                   };
               }
+   
+   
     },
     getRoomInfo(roomId){
         getRoomInfo(roomId).then(response => {
@@ -875,6 +877,10 @@ export default {
     /deep/.el-dialog__headerbtn{
          top:10px;
     }
+
+    /deep/.el-dialog:not(.is-fullscreen) {
+        margin-top: 0 !important;
+    }
     
 </style>
 

+ 48 - 53
src/views/qw/qwLogin/index.vue

@@ -4,7 +4,6 @@
       <el-row v-loading="loading" align="middle" justify="center">
         <el-col :span="24">
           <el-card class="scan-card" shadow="hover">
-
             <div class="scan-card-content">
               <h1 class="title">扫码登录</h1>
                <el-form-item label="账号" prop="account" style="width:100%" v-if="!showVerifyCode">
@@ -68,13 +67,9 @@ export default {
       
   },
   mounted () {
-      // 初始化
-      //this.initSocket(this.companyUser.userId);
-      //console.log("userId:"+JSON.stringify(this.companyUser));
-      console.log("qxj process:"+JSON.stringify(process));
-      if (process.env.NODE_ENV === 'development') {
-            this.qwForm.account = "1261818888";
-       }
+      // if (process.env.NODE_ENV === 'development') {
+      //       this.qwForm.account = "1261818888";
+      //  }
   },
   methods: {
     handleLogin() {
@@ -136,51 +131,51 @@ export default {
               });
     },
      initSocket(userId) {
-               let that=this;
-              if(!!this.qwIm.socket){
-                  this.qwIm.initSocket(userId,true);
-                    // 监听socket连接
-                  this.qwIm.socket.onopen = function() {
-                        console.log("socket 连接成功");
-                  };
-                  // 监听socket错误信息
-                  this.qwIm.socket.onerror = function() {
-                      console.log("连接错误")
-                  };
-                  // 监听socket消息
-                  this.qwIm.socket.onmessage = function(res) {
-                        var data=JSON.parse(res.data);
-                        console.log("收到服务端内容", JSON.stringify(data));
-                        if(data.cmd=="heartbeat"){ //收到心跳数据不处理
-                            console.log("收到心跳数据 heartbeat");
-                        }
-                        if(data.cmd=="loginSucc"){
-                            var qwUserInfo=JSON.parse(data.msg);
-                            Notification.success({title: "登录成功!" });
-                            that.$store.dispatch("qwUser", qwUserInfo);
-                            that.showQRCode=false;
-                            setTimeout(() => {
-                                that.$router.push({path:'/qw/qwChat',query:{"isFromLogin":1}});
-                            }, 2000);
-                        }
-                        if(data.cmd=="verifyCode"){
-                            that.loginTips="登录";
-                            that.showQRCode=false;
-                            that.showVerifyCode=true;
-                        }
-                        // if(data.cmd=="offline"){
-                        //     that.loginTips="获取验证码";
-                        //     that.showQRCode=true;
-                        //     that.showVerifyCode=false;
-                        //     that.$store.dispatch('qwLoginOut').then(() => {
-                        //     });
-                        // }
-                  };
-                  // 监听socket重连
-                  this.qwIm.socket.onreconnect = function(res) {
-                      console.log("socket 断线重连...")
-                  };
-              }
+          let that=this;
+          if(!!this.qwIm.socket){
+              this.qwIm.initSocket(userId,true);
+                // 监听socket连接
+              this.qwIm.socket.onopen = function() {
+                    console.log("socket 连接成功");
+              };
+              // 监听socket错误信息
+              this.qwIm.socket.onerror = function() {
+                  console.log("连接错误")
+              };
+              // 监听socket消息
+              this.qwIm.socket.onmessage = function(res) {
+                    var data=JSON.parse(res.data);
+                    console.log("收到服务端内容", JSON.stringify(data));
+                    if(data.cmd=="heartbeat"){ //收到心跳数据不处理
+                        console.log("收到心跳数据 heartbeat");
+                    }
+                    if(data.cmd=="loginSucc"){
+                        var qwUserInfo=JSON.parse(data.msg);
+                        Notification.success({title: "登录成功!" });
+                        that.$store.dispatch("qwUser", qwUserInfo);
+                        that.showQRCode=false;
+                        setTimeout(() => {
+                            that.$router.push({path:'/qw/qwChat',query:{"isFromLogin":1}});
+                        }, 2000);
+                    }
+                    if(data.cmd=="verifyCode"){
+                        that.loginTips="登录";
+                        that.showQRCode=false;
+                        that.showVerifyCode=true;
+                    }
+                    // if(data.cmd=="offline"){
+                    //     that.loginTips="获取验证码";
+                    //     that.showQRCode=true;
+                    //     that.showVerifyCode=false;
+                    //     that.$store.dispatch('qwLoginOut').then(() => {
+                    //     });
+                    // }
+              };
+              // 监听socket重连
+              this.qwIm.socket.onreconnect = function(res) {
+                  console.log("socket 断线重连...")
+              };
+          }
       },
       open() {
             console.log("socket连接成功");