Files

125 lines
3.3 KiB
JavaScript
Raw Permalink Normal View History

2026-05-24 10:21:26 +08:00
"use strict";
cc._RF.push(module, 'b12f53uOLtGG6y32DjC8ko9', 'cmp.login.user');
// Scripts/mod/login/cmp/cmp.login.user.js
"use strict";
/******************************************************************
*
*
*
******************************************************************/
var WndLogin = require("scene.login");
var LoginMod = require("login.mod");
var BridgeComponent = require("bridge.component");
var FFSDK = require("ff_sdk");
cc.Class({
"extends": BridgeComponent,
properties: {
wndLogin: {
"default": null,
type: WndLogin
},
edtAccount: {
"default": null,
type: cc.EditBox
},
edtPassword: {
"default": null,
type: cc.EditBox
}
},
// 载入
onLoad: function onLoad() {
nx.gui.setActive(this, "panel", false);
this.vbind([["curAccount", this.onCurAccountChanged.bind(this)]]);
},
// 展示
onEnable: function onEnable() {
// 测试登录
if (!FFSDK.getInstance().isEnableSDK()) {
nx.gui.setActive(this, "panel", true);
nx.gui.setActive(this, "sdk", false);
return;
}
// SDK登录
this.showSDK();
},
// =======================================================
// 测试登录相关
// =======================================================
// 账号同步
onCurAccountChanged: function onCurAccountChanged(_info) {
if (nx.dt.objEmpty(_info)) {
this.edtAccount.string = "";
this.edtPassword.string = "";
return;
}
this.edtAccount.string = _info.account;
this.edtPassword.string = _info.password;
},
// 注册
touchRegist: function touchRegist() {
// 重新注册,随机账户
var random = {
account: Utils.randomStr(6, 12),
password: Utils.randomStr(6)
};
nx.bridge.vset("curAccount", random);
nx.storage.setObject("TKAccount", random);
this.wndLogin.changeSubPanel(2);
this.wndLogin.simAccountDone();
},
// 登入
touchLogIn: function touchLogIn() {
if (this.edtAccount.string == "") {
nx.tbox(nx.text.getKey("lab_inputUser"));
return;
}
if (this.edtPassword.string == "") {
nx.tbox(nx.text.getKey("lab_inputPw"));
return;
}
var random = {
account: this.edtAccount.string,
password: this.edtPassword.string
};
nx.bridge.vset("curAccount", random);
nx.storage.setObject("TKAccount", random);
this.wndLogin.changeSubPanel(2);
this.wndLogin.simAccountDone();
},
// =======================================================
// SDK登录相关
// =======================================================
// SDK登录
showSDK: function showSDK() {
var _this = this;
nx.gui.setActive(this, "panel", false);
nx.gui.setActive(this, "sdk", true);
var self = this;
LoginMod.getInstance().reqSDKLogin(function (_ret, _data) {
if (!_ret || !_data || nx.dt.strEmpty(_data.openId)) {
nx.mbox("SDK登录失败", ['retry'], function (_key, _box) {
_box.close();
self.showSDK();
}, "SDKLogin");
return;
}
var args = {
account: _data.openId,
password: "sdk"
};
nx.bridge.vset("curAccount", args);
nx.storage.setObject("TKAccount", args);
_this.wndLogin.changeSubPanel(2);
_this.wndLogin.simAccountDone();
}, !!this.node.params.swap);
}
});
cc._RF.pop();