| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- /*
- * @Author: mojunshou 1637302775@qq.com
- * @Date: 2025-02-27 16:33:37
- * @LastEditors: mojunshou 1637302775@qq.com
- * @LastEditTime: 2025-03-06 15:49:28
- * @FilePath: \Cocos_android\assets\script\game\start\StartViewComp.ts
- * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%A“”
- */
- import { native } from "cc";
- import { _decorator } from "cc";
- import { oops } from "db://oops-framework/core/Oops";
- import { DeviceUtil } from "db://oops-framework/core/utils/DeviceUtil";
- import { ecs } from "db://oops-framework/libs/ecs/ECS";
- import { CCComp } from "db://oops-framework/module/common/CCComp";
- const { ccclass, property } = _decorator;
- /** 视图层对象 */
- @ccclass('StartViewComp')
- @ecs.register('StartView', false)
- export class StartViewComp extends CCComp {
- private lang: boolean = false;
- /** 视图层逻辑代码分离演示 */
- start() {
- // const entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
- console.log("这是登录场景");
- }
- //显示手机声音状态
- showVolumeState() {
- if (this.lang == false) {
- this.lang = true;
- oops.log.logView("切换中文")
- oops.language.setLanguage("zh", () => { });
- }
- else {
- this.lang = false;
- oops.log.logView("切换英文")
- oops.language.setLanguage("en", () => { });
- }
- this.login("admin", "123456");
- }
- //回调安卓传Json数据,需要从Json解析成字符串,再传过去
- async callAndroidWithJson(args: Object) {
- if (DeviceUtil.isAndroid && DeviceUtil.isNative) {
- let jsonStr = JSON.stringify(args);
- console.log("js传给安卓的数据打印>>>>>>>>>>>>>>>>>>>>", jsonStr);
- let result = await native.reflection.callStaticMethod("com/cocos/game/AndroidHandler", "onCocosMessage", "(Ljava/lang/String;)Ljava/lang/String;", jsonStr);
- //等待上边安卓返回数据,再执行下边代码
- if (result) {
- let android_result = JSON.parse(result);
- console.log("安卓返回数据打印>>>>>>>>>>>>>>>>>>>>", android_result);
- return android_result;
- }
- }
- //返回全部用字符串Json格式,然后在js解析,然后做相应处理,但是需要区分Json 后的字符串和普通字符串,需要做对用的标记
- }
- async login(username: string, password: string) {
- //区分普通登录,微信登录,游客登录
- let obj = {
- method: "login",
- callback: "StartViewComp.androidCallJs", //安卓完成业务的回调JS函数
- data: {
- username: username,
- password: password,
- type: 1 //登录类型
- }
- }
- let result = await this.callAndroidWithJson(obj);
- return result;
- }
- //用户注册
- async user_register(username: string, password: string) {
- let obj = {
- method: "user_register",
- callback: "",
- data: {
- username: username,
- password: password
- }
- }
- let result = await this.callAndroidWithJson(obj);
- return result;
- }
- //微信登录
- async wechat_login() {
- let obj = {
- method: "wechat_login",
- callback: "",
- data: {
- }
- }
- let result = await this.callAndroidWithJson(obj);
- return result;
- }
- //用户提现
- async user_withdrawal(user_id: string) {
- let obj = {
- method: "user_withdrawal",
- callback: "",
- data: {
- }
- }
- let result = await this.callAndroidWithJson(obj);
- return result;
- }
- //获取提现记录
- async get_withdrawal_record(user_id: string) {
- let obj = {
- method: "get_withdrawal_record",
- callback: "",
- data: {
- }
- }
- let result = await this.callAndroidWithJson(obj);
- return result;
- }
- //获取用户信息
- async get_user_info(user_id: string) {
- let obj = {
- method: "get_user_info",
- callback: "",
- data: {
- user_id: user_id
- }
- }
- let result = await this.callAndroidWithJson(obj);
- return result;
- }
- //现金提现
- async cash_withdrawal(user_id: string, amount: string) {
- let obj = {
- method: "cash_withdrawal",
- callback: "",
- data: {
- user_id: user_id,
- amount: amount
- }
- }
- let result = await this.callAndroidWithJson(obj);
- return result;
- }
- //红包提现
- async red_packet_withdrawal(user_id: string, amount: string) {
- let obj = {
- method: "red_packet_withdrawal",
- callback: "",
- data: {
- user_id: user_id,
- amount: amount
- }
- }
- let result = await this.callAndroidWithJson(obj);
- return result;
- }
- //复制文字
- async copy_text(text: string) {
- let obj = {
- method: "copy_text",
- callback: "",
- data: {
- text: text
- }
- }
- let result = await this.callAndroidWithJson(obj);
- return result;
- }
- //获取隐私协议
- //获取用户协议
- //关于我们
- //安卓直接回调js函数
- public static androidCallJs(name: string, password: string) {
- console.log("安卓回调数据???????????????", name, password);
- }
- /** 视图对象通过 ecs.Entity.remove(StartViewComp) 删除组件是触发组件处理自定义释放逻辑 */
- reset() {
- this.node.destroy();
- }
- }
- window.StartViewComp = StartViewComp;
|