141 lines
3.6 KiB
TypeScript
141 lines
3.6 KiB
TypeScript
import {
|
|
_decorator,
|
|
Component,
|
|
Node,
|
|
director,
|
|
Prefab,
|
|
NodeEventType,
|
|
} from "cc";
|
|
import { rachageModel } from "./rachageModel";
|
|
import { rechargeNum } from "./RechageNum";
|
|
import dwebAjax from "./ajax";
|
|
import TBG from "./tgb";
|
|
import Abi from "./abi/abi";
|
|
import { tanchuan } from "./TanChuang";
|
|
import { WithdrawalView } from "./Withdrawal/WithdrawalView";
|
|
import { WhView } from "./Withdrawal/WhView";
|
|
const { ccclass, property } = _decorator;
|
|
const ETH_CONTRACT = "0x3865194cD048f7b14b465a96907fB6546B888216";
|
|
|
|
@ccclass("NewComponent")
|
|
export class NewComponent extends Component {
|
|
username = null;
|
|
@property(Prefab)
|
|
itemPrefab: Prefab | null = null;
|
|
@property(rachageModel)
|
|
model: rachageModel = null;
|
|
@property(rechargeNum)
|
|
rechargenum: rechargeNum = null;
|
|
@property(tanchuan)
|
|
Tanchuan: tanchuan = null;
|
|
@property(WithdrawalView)
|
|
WithdrawalView: WithdrawalView = null;
|
|
@property(WhView)
|
|
WhView: WhView = null;
|
|
start() {
|
|
const tbg = new TBG({});
|
|
tbg.on("accountChange", () => {
|
|
console.log("用户切换");
|
|
director.loadScene("login");
|
|
});
|
|
}
|
|
//获取充值比例
|
|
async takeWhData() {
|
|
let data = {};
|
|
dwebAjax.sendAjax("/api/v1/withdrawal/get", data, "POST", async (res) => {
|
|
if (res.code == "200") {
|
|
console.log("提现记录为", res.data);
|
|
} else if (res.code == "10001") {
|
|
console.log("登录失效");
|
|
director.loadScene("login");
|
|
} else {
|
|
console.log(res);
|
|
return;
|
|
}
|
|
});
|
|
}
|
|
OpWhView() {
|
|
this.WhView.node.active = true;
|
|
}
|
|
onload() {}
|
|
async createNft() {
|
|
const tbg = new TBG({});
|
|
const account = await tbg.login();
|
|
const res2 = await tbg.createNft({
|
|
nftAbi: Abi,
|
|
contract: ETH_CONTRACT,
|
|
toAddress: account,
|
|
});
|
|
console.log(res2);
|
|
}
|
|
//充值
|
|
recharge() {
|
|
this.model.node.active = true;
|
|
}
|
|
rechargeNum() {
|
|
if ((this.rechargenum.node.active = true)) {
|
|
this.rechargenum.node.active = false;
|
|
} else {
|
|
this.rechargenum.node.active = true;
|
|
}
|
|
}
|
|
setTanChuang() {
|
|
if ((this.Tanchuan.node.active = true)) {
|
|
this.Tanchuan.node.active = false;
|
|
} else {
|
|
this.Tanchuan.node.active = true;
|
|
}
|
|
}
|
|
//获取充值记录
|
|
async getRechargeNew() {
|
|
let data = {};
|
|
this.WithdrawalView.node.active = true;
|
|
await dwebAjax.sendAjax("/api/v1/recharge", data, "POST", async (res) => {
|
|
if (res.code == "200") {
|
|
console.log("充值记录为", res.data);
|
|
} else if (res.code == "10001") {
|
|
console.log("登录失效");
|
|
director.loadScene("login");
|
|
} else {
|
|
console.log(res);
|
|
return;
|
|
}
|
|
});
|
|
}
|
|
//登录
|
|
async login() {
|
|
const tbg = new TBG({});
|
|
let data = {};
|
|
let hash = null;
|
|
await dwebAjax.sendAjax("/api/v1/get/sign", data, "GET", async (res) => {
|
|
if (res.code == "200") {
|
|
console.log(res);
|
|
hash = res.data;
|
|
data["hash"] = hash;
|
|
const account = await tbg.login();
|
|
const res2 = await tbg.sign(hash);
|
|
let SignData = TBG.sign;
|
|
console.log(res2);
|
|
data["sign"] = res2.sign;
|
|
await dwebAjax.sendAjax("/api/v1/user/login", data, "POST", (res) => {
|
|
if (res.code == "200") {
|
|
director.loadScene("main");
|
|
let token = res.data.token;
|
|
let adder = res.data.adder;
|
|
localStorage.setItem("token", token);
|
|
localStorage.setItem("adder", adder);
|
|
} else {
|
|
console.log(res);
|
|
return;
|
|
}
|
|
});
|
|
} else {
|
|
console.log(res);
|
|
return;
|
|
}
|
|
});
|
|
}
|
|
|
|
update(deltaTime: number) {}
|
|
}
|