FqLogin.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import ViewObject from "../main/ViewObject";
  2. import { HttpStateType, ReveData } from "../util/CHttp";
  3. import { GameViewType } from "../main/ViewManage";
  4. /**
  5. * 凤起登陆
  6. */
  7. const {ccclass, property} = cc._decorator;
  8. interface FqLoginData{
  9. uid:string
  10. token:string
  11. }
  12. @ccclass
  13. export default class FqLogin extends ViewObject {
  14. start () {
  15. if(cc.sys.isNative){
  16. if (cc.sys.os === cc.sys.OS_ANDROID) {
  17. let className = "com/funqueue/android/xsdmx/MainActivity";
  18. let methodName = "login";
  19. let methodSignature = "(Ljava/lang/String;)V";
  20. jsb.reflection.callStaticMethod(className, methodName, methodSignature,'"this is a message from js"');
  21. let myself = this
  22. window._fqAndroidLoginCallback = (str)=>{
  23. console.log('window._fqAndroidLoginCallback' , str)
  24. myself.loginAndroid(JSON.parse(str));
  25. return '1'
  26. }
  27. } else if (cc.sys.os === cc.sys.OS_IOS) {
  28. jsb.reflection.callStaticMethod('AppController', 'showLogin');
  29. let myself = this
  30. window._fqIosLoginCallback = (str)=>{
  31. console.log('window._fqIosLoginCallback' , str)
  32. myself.loginIos(JSON.parse(str));
  33. return '1'
  34. }
  35. }
  36. /**
  37. *
  38. * @param str 切换账号回调
  39. * @returns
  40. */
  41. window._switchAccountCallback = ()=>{
  42. console.log('window._fqIosLoginCallback')
  43. cc.director.loadScene('hotUpdate')
  44. return '1'
  45. }
  46. }
  47. }
  48. public loginAndroid(data:FqLoginData){
  49. let http = this.main.loginHttp;
  50. let msg = {
  51. 'uid':data.uid,
  52. 'token':data.token
  53. }
  54. this.main.startLoad();
  55. http.sendForm('/fqLogin_android',msg,(state,reve:ReveData)=>{
  56. this.main.stopLoad();
  57. if(state == HttpStateType.SUCCESS){
  58. if(reve.retCode == 0){
  59. this.main.userData = reve.data;
  60. this.openArea();
  61. }else{
  62. this.main.showTips(reve.message);
  63. }
  64. }else{
  65. this.main.showTips('网络异常');
  66. }
  67. })
  68. }
  69. public loginIos(data:FqLoginData){
  70. let http = this.main.loginHttp;
  71. let msg = {
  72. 'uid':data.uid,
  73. 'token':data.token
  74. }
  75. this.main.startLoad();
  76. http.sendForm('/fqLogin_ios',msg,(state,reve:ReveData)=>{
  77. this.main.stopLoad();
  78. if(state == HttpStateType.SUCCESS){
  79. if(reve.retCode == 0){
  80. this.main.userData = reve.data;
  81. this.openArea();
  82. }else{
  83. this.main.showTips(reve.message);
  84. }
  85. }else{
  86. this.main.showTips('网络异常');
  87. }
  88. })
  89. }
  90. /**
  91. * 打开选区界面
  92. */
  93. public openArea(){
  94. let main = this.main;
  95. main.startLoad()
  96. main.viewManage.loadFunc(GameViewType.area,(viewObject:ViewObject)=>{
  97. main.stopLoad()
  98. viewObject.show();
  99. });
  100. this.node.destroy()
  101. }
  102. /**
  103. * 提交数据到友盟
  104. * @param id
  105. * @param key
  106. * @param value
  107. */
  108. public static commitEvent(id:string,key:string,value:string){
  109. let msg = {
  110. id:id,
  111. key:key,
  112. value:value
  113. }
  114. let jsonstr = JSON.stringify(msg);
  115. console.log("====打点统计=====", jsonstr);
  116. if (cc.sys.os === cc.sys.OS_ANDROID) {
  117. let className = "com/funqueue/android/xsdmx/MainActivity";
  118. let methodSignature = "(Ljava/lang/String;)V";
  119. jsb.reflection.callStaticMethod(className, 'commitEvent', methodSignature,JSON.stringify(msg));
  120. } else if (cc.sys.os === cc.sys.OS_IOS) {
  121. jsb.reflection.callStaticMethod('AppController', 'commitEvent:',JSON.stringify(msg));
  122. }
  123. }
  124. }