| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- /*
- * @Author: mojunshou 1637302775@qq.com
- * @Date: 2025-03-20 17:00:12
- * @LastEditors: mojunshou 1637302775@qq.com
- * @LastEditTime: 2025-04-10 15:09:55
- * @Description: 微信提现页面
- */
- import { _decorator, Node, RichText, tween, Vec3 } 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";
- import { GameEvent } from "../common/config/GameEvent";
- import { UIID } from "../common/config/GameUIConfig";
- import { CocosHandler } from "../common/manager/CocosHandler";
- import { ServerHandler } from "../common/manager/ServerHandler";
- const { ccclass, property } = _decorator;
- /** 视图层对象 */
- @ccclass('WechatWithdrawalViewComp')
- @ecs.register('WechatWithdrawalView', false)
- export class WechatWithdrawalViewComp extends CCComp {
- data: any = {
- nickName: "",
- money: 0,
- channel: "微信零钱"
- }
- @property(RichText)
- private richText: RichText = null!;
- @property(Node)
- private node_notice: Node = null!;
- /** 视图层逻辑代码分离演示 */
- start() {
- // const entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
- this.setButton();
- this.updateNotice();
- this.addEvent();
- }
- addEvent() {
- oops.message.on(GameEvent.openRecordView, this.openRecordView, this);
- }
- /** 视图对象通过 ecs.Entity.remove(WechatWithdrawalViewComp) 删除组件是触发组件处理自定义释放逻辑 */
- reset() {
- this.node.destroy();
- }
- private btn_back() {
- oops.gui.remove(UIID.WechatWithdraw);
- }
- private btn_record() {
- if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
- ServerHandler.inst.getRecordList();
- } else {
- oops.gui.open(UIID.WithdrawRecord);
- }
- }
- private openRecordView() {
- oops.gui.open(UIID.WithdrawRecord);
- }
- //更新滚动公告
- updateNotice() {
- this.node_notice.active = true;
- const num = oops.random.getRandomInt(1, 20)
- //随机1-500的数,有小数保留两位
- const randomNum = Math.random() * 500;
- const numStr = randomNum.toFixed(2);
- let name = this.getRandomChineseName();
- let str = "恭喜<color=#bcdc36>$y</color>收集<color=#bcdc36>$n</color>金砖,到账<color=#bcdc36>$m元</color>";
- //正则替换str里边的$y,$n,$m
- let str1 = str.replace(/\$y/g, name);
- str1 = str1.replace(/\$n/g, num + "块");
- str1 = str1.replace(/\$m/g, numStr);
- this.richText.string = str1;
- this.node_notice.setPosition(new Vec3(0, -40, 0));
- tween(this.node_notice)
- .to(4, { position: new Vec3(0, 40, 0) })
- .call(() => {
- this.updateNotice();
- })
- .start();
- }
- getRandomChineseName(): string {
- const surnames = ["王", "李", "张", "刘", "陈", "杨", "黄", "赵", "周", "吴", "徐", "孙", "胡", "朱", "高", "林", "何", "郭", "马", "罗"];
- const characters = "的一是了不在人有我他这中大来上国个到说们时用地为子就那和要出也得于里后自以会着对生能而多小学同见天去好她所然家前开";
- // 随机获取姓
- const surname = surnames[Math.floor(Math.random() * surnames.length)];
- // 生成 1 到 3 个字的名字
- const nameLength = Math.floor(Math.random() * 3) + 1;
- let givenName = "";
- for (let i = 0; i < nameLength; i++) {
- givenName += characters[Math.floor(Math.random() * characters.length)];
- }
- return surname + givenName;
- }
- }
|