PushMsgM.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { Hall } from "../../prefab/hall/Hall";
  2. import { RewardLayer } from "../../prefab/layer/RewardLayer";
  3. import { TipsLayer } from "../../prefab/layer/TipsLayer";
  4. import UserM, { GoodInfo } from "../api/UserM";
  5. import WsM from "../api/WsM";
  6. import { WS, WsResponse } from "../net/WS";
  7. import Utils from "../utils/Utils";
  8. import EV, { EV_TYPE } from "./EV";
  9. import ItemsM from "./ItemsM";
  10. export class RewardGoods {
  11. changeList: GoodInfo[];
  12. goodList: GoodInfo[];
  13. }
  14. export default class PushMsgM {
  15. private static _ins: PushMsgM = null;
  16. public static get ins(): PushMsgM {
  17. return (PushMsgM._ins ??= new PushMsgM());
  18. }
  19. init() {
  20. WS.ins.on(10001, this.onRechargeSuccess, this);
  21. WS.ins.on(10003, this.onRefreshUserData, this);
  22. WS.ins.on(10004, this.onRewardGoods, this);
  23. WS.ins.on(10005, this.OnJoinFamilySuccess, this);
  24. WS.ins.on(10006, this.OnFamilyKickedMe, this);
  25. WS.ins.on(401, this.OnUserTokenError, this);
  26. }
  27. async OnJoinFamilySuccess(msg: WsResponse) {
  28. await UserM.ins.refreshInfo();
  29. await TipsLayer.showConfirm(
  30. "",
  31. Utils.setI18nLabel("Family.JoinFamilySuccess")
  32. );
  33. EV.ins.emit(EV_TYPE.FAMILY_STATUS_UPDATE);
  34. Hall.ins.switchPage(Hall.PageFamily);
  35. }
  36. async OnFamilyKickedMe(msg: WsResponse) {
  37. let result = await TipsLayer.showConfirm(
  38. "",
  39. Utils.setI18nLabel("Family.KickedMe")
  40. );
  41. await UserM.ins.refreshInfo();
  42. EV.ins.emit(EV_TYPE.FAMILY_STATUS_UPDATE);
  43. }
  44. OnUserTokenError(msg: WsResponse) {
  45. console.warn("OnUserTokenError", msg);
  46. window.location.reload();
  47. }
  48. onRefreshUserData(msg: WsResponse) {
  49. console.warn("onRefreshUserData", msg);
  50. UserM.ins.refreshData();
  51. }
  52. onRechargeSuccess(msg: WsResponse) {
  53. console.warn("onRechargeSuccess", msg);
  54. console.warn("changeList", msg.data.changeList);
  55. ItemsM.ins.itemChange(msg.data.changeList, msg.data.goodList);
  56. }
  57. onRewardGoods(msg: WsResponse) {
  58. console.warn("onRewardGoods", msg);
  59. let data = msg.data as RewardGoods;
  60. // UserM.ins.refreshGoods(data.goodList);
  61. // RewardLayer.show(data.changeList);
  62. ItemsM.ins.itemChange(data.changeList, data.goodList);
  63. }
  64. }