LoginHandler.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // LoginHandler.ts
  2. import { oops } from 'db://oops-framework/core/Oops';
  3. import { smc } from '../SingletonModuleComp';
  4. import { ServerHandler } from './ServerHandler';
  5. import { CocosHandler } from './CocosHandler';
  6. import { ProtocolEvent } from './ProtocolEvent';
  7. export class LoginHandler {
  8. private static _inst: LoginHandler;
  9. public static get inst(): LoginHandler {
  10. if (!this._inst) {
  11. this._inst = new LoginHandler();
  12. }
  13. return this._inst;
  14. }
  15. async getPrivacyStatus() {
  16. const data = { method: 'privacy.grant.get' };
  17. const result = await CocosHandler.inst.sendMessageToAndroid(data, '获取隐私授权状态');
  18. return JSON.parse(result);
  19. }
  20. async savePrivacyStatus(status: boolean) {
  21. const data = {
  22. method: 'privacy.grant.set',
  23. param: JSON.stringify({ granted: status })
  24. };
  25. const result = await CocosHandler.inst.sendMessageToAndroid(data, '保存隐私授权状态');
  26. return JSON.parse(result);
  27. }
  28. openAgreement() {
  29. const type = smc.game.GameModel.protocolType;
  30. const url = type === 1 ? oops.config.game.gamePrivacyUrl : oops.config.game.gameProtocolUrl;
  31. const data = {
  32. method: 'system.browser.open',
  33. param: JSON.stringify({ url })
  34. };
  35. CocosHandler.inst.sendMessageToAndroid(data, '打开协议链接');
  36. }
  37. async wechatLogin() {
  38. const param = {
  39. callback: {
  40. onSuccess: 'LoginHandler.inst.wechatLoginSuccess',
  41. onFaile: 'LoginHandler.inst.wechatLoginFail'
  42. }
  43. };
  44. const data = {
  45. method: 'auth.wechat',
  46. param: JSON.stringify(param)
  47. };
  48. await CocosHandler.inst.sendMessageToAndroid(data, '微信登录');
  49. }
  50. wechatLoginSuccess(str: string) {
  51. console.log('[微信] 登录成功', str);
  52. // this.wxLogin(str);
  53. //向服务器申请登录
  54. }
  55. wechatLoginFail(str: string) {
  56. console.log('[微信] 登录失败', str);
  57. oops.gui.toast('微信登录失败');
  58. }
  59. }
  60. window["LoginHandler"] = LoginHandler;