PushMsgM.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { RewardLayer } from "../../prefab/layer/RewardLayer";
  2. import UserM, { GoodInfo } from "../api/UserM";
  3. import WsM from "../api/WsM";
  4. import { WS, WsResponse } from "../net/WS";
  5. import ItemsM from "./ItemsM";
  6. export class RewardGoods {
  7. changeList: GoodInfo[];
  8. goodList: GoodInfo[];
  9. }
  10. export default class PushMsgM {
  11. private static _ins: PushMsgM = null;
  12. public static get ins(): PushMsgM {
  13. return (PushMsgM._ins ??= new PushMsgM());
  14. }
  15. init() {
  16. WS.ins.on(10001, this.onRechargeSuccess, this);
  17. WS.ins.on(10003, this.onRefreshUserData, this);
  18. WS.ins.on(10004, this.onRewardGoods, this);
  19. WS.ins.on(401, this.OnUserTokenError, this);
  20. }
  21. OnUserTokenError(msg: WsResponse) {
  22. console.warn("OnUserTokenError", msg);
  23. window.location.reload();
  24. }
  25. onRefreshUserData(msg: WsResponse) {
  26. console.warn("onRefreshUserData", msg);
  27. UserM.ins.refreshData();
  28. }
  29. onRechargeSuccess(msg: WsResponse) {
  30. console.warn("onRechargeSuccess", msg);
  31. console.warn("changeList", msg.data.changeList);
  32. ItemsM.ins.itemChange(msg.data.changeList, msg.data.goodList);
  33. }
  34. onRewardGoods(msg: WsResponse) {
  35. console.warn("onRewardGoods", msg);
  36. let data = msg.data as RewardGoods;
  37. // UserM.ins.refreshGoods(data.goodList);
  38. // RewardLayer.show(data.changeList);
  39. ItemsM.ins.itemChange(data.changeList, data.goodList);
  40. }
  41. }