Bläddra i källkod

处理艺人申请通知

hwt 6 år sedan
förälder
incheckning
c3b273d987
3 ändrade filer med 64 tillägg och 21 borttagningar
  1. 45 12
      assets/scripts/Game.js
  2. 15 9
      assets/scripts/net/Api.js
  3. 4 0
      assets/scripts/net/FriendSystemApi.js

+ 45 - 12
assets/scripts/Game.js

@@ -182,8 +182,8 @@ cc.Class({
 
         let seq = 1;
 
-        if(CC_WECHATGAME) {
-            if(this.ws.readyState == 'closed') {
+        if (CC_WECHATGAME) {
+            if (this.ws.readyState == 'closed') {
                 this.ws.reconnect()
             }
         }
@@ -223,9 +223,13 @@ cc.Class({
             let u8Arr = new Uint8Array(data)
             let decodeMsg = Message.decode(u8Arr);
             console.log("[Response msg type]: ", decodeMsg.type);
-            
+
             console.log("[Response text msg]: ", decodeMsg);
 
+            if (decodeMsg.type == 0) {
+                this.toastNotification(decodeMsg.msg);//成为我的老板,我的艺人,我的好友主界面toast提醒。
+            }
+
             if (decodeMsg.notificationMessage) {
                 switch (decodeMsg.notificationMessage.nType) {
                     case 1:
@@ -255,7 +259,7 @@ cc.Class({
                 }
             }
 
-            if(decodeMsg.buildingItems) {
+            if (decodeMsg.buildingItems) {
                 console.log(decodeMsg.buildingItems);
                 GameEvent.fire(GameNotificationKey.ReceiveLevelHomeItemPropUpdate, decodeMsg.buildingItems);
             }
@@ -784,13 +788,38 @@ cc.Class({
             });
         } else if (Global.shareType == ShareAction.BECOME_ARTIST) {
             let shareUid = Global.shareUid
-            FriendSystemApi.becomeArtist(shareUid, () => {
-                GameEvent.fire('refresh_friend_list');
+            // FriendSystemApi.becomeArtist(shareUid, () => {
+            //     GameEvent.fire('refresh_friend_list');
+
+            //     setTimeout(() => {
+            //         GameEvent.fire(GameNotificationKey.NoticeRoleOpt, shareUid, 11);
+            //     }, 2500)
+            // });
+            FriendSystemApi.becomeArtistPromise(shareUid)
+                .then(({ code, data }) => {
+                    console.log('becomeArtist: ', code);
+                    switch (code) {
+                        case 816://成为好友
+                            GameEvent.fire('refresh_friend_list');
+                            setTimeout(() => {
+                                GameEvent.fire(GameNotificationKey.NoticeRoleOpt, shareUid, 10);
+                            }, 2500);
+                            break;
+                        case 817: // 成为对方艺人
+                            GameEvent.fire('refresh_friend_list');
+                            setTimeout(() => {
+                                GameEvent.fire(GameNotificationKey.NoticeRoleOpt, shareUid, 11);
+                            }, 2500);
+                            break;
+                        case 0: //正常
+                            break;
+                        case 4002://异常
+                            break;
+                    }
+                })
+                .catch(() => {
 
-                setTimeout(() => {
-                    GameEvent.fire(GameNotificationKey.NoticeRoleOpt, shareUid, 10);
-                }, 2500)
-            });
+                });
         }
         Global.shareUid = -1;
         Global.shareType = ShareAction.None;
@@ -813,10 +842,14 @@ cc.Class({
     },
 
     toastNotification(message) {
-        this.toastScript.show(message);
+        if (this.node.active) {
+            this.toastScript.show(message);
+        }
     },
 
     showLevelHomeSpeedUpTips(name, type) {
-        this.levelHomeSpeedUpTips.show(name, type);
+        if (this.node.active) {
+            this.levelHomeSpeedUpTips.show(name, type);
+        }
     },
 });

+ 15 - 9
assets/scripts/net/Api.js

@@ -236,14 +236,14 @@ class Api {
                     if (res.data.code === ResponseStateCode.LOGIN_INVALIDATE) {
                         Global.needLogin = true;
                         cc.director.loadScene('login');
-                        reject(res.data);
+                        // reject(res.data);
                     }
+                    resolve(res.data);
+                    // if (res.data.code === ResponseStateCode.OK) {
 
-                    if (res.data.code === ResponseStateCode.OK) {
-                        resolve(res.data);
-                    } else {
-                        reject(res.data);
-                    }
+                    // } else {
+                    //     reject(res.data);
+                    // }
                 },
                 fail: (res) => {
                     reject({
@@ -288,14 +288,20 @@ class Api {
     static jsBaseRequestP(resolve, reject) {
         var xhr = new XMLHttpRequest();
         xhr.onreadystatechange = () => {
-            if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) {
-                // console.log('response:' + xhr.responseText);
+            if (xhr.readyState == 4) {
                 var response = JSON.parse(xhr.responseText);
-                if (response.code == ResponseStateCode.OK) {
+                if (xhr.status >= 200 && xhr.status < 400) {
                     resolve(response);
                 } else {
                     reject(response);
                 }
+                // console.log('response:' + xhr.responseText);
+                // var response = JSON.parse(xhr.responseText);
+                // if (response.code == ResponseStateCode.OK) {
+                // resolve(response);
+                // } else {
+                //     reject(response);
+                // }
             }
         };
         return xhr;

+ 4 - 0
assets/scripts/net/FriendSystemApi.js

@@ -145,6 +145,10 @@ class FriendSystemApi {
         Api.httpPost(requestBody);
     }
 
+    static becomeArtistPromise(uid) {
+        return Api.httpGetPromise('friend/beMyArtist.do', { fid: uid });
+    }
+
     static shareSuccessNotice() {
         Api.httpPostPromise('/friend/share.do').then(() => {
             console.log('调用好友分享奖励接口成功');