WechatWithdrawalViewComp.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * @Author: mojunshou 1637302775@qq.com
  3. * @Date: 2025-03-20 17:00:12
  4. * @LastEditors: mojunshou 1637302775@qq.com
  5. * @LastEditTime: 2025-04-10 15:09:55
  6. * @Description: 微信提现页面
  7. */
  8. import { _decorator, Node, RichText, tween, Vec3 } from "cc";
  9. import { oops } from "db://oops-framework/core/Oops";
  10. import { DeviceUtil } from "db://oops-framework/core/utils/DeviceUtil";
  11. import { ecs } from "db://oops-framework/libs/ecs/ECS";
  12. import { CCComp } from "db://oops-framework/module/common/CCComp";
  13. import { GameEvent } from "../common/config/GameEvent";
  14. import { UIID } from "../common/config/GameUIConfig";
  15. import { CocosHandler } from "../common/manager/CocosHandler";
  16. const { ccclass, property } = _decorator;
  17. /** 视图层对象 */
  18. @ccclass('WechatWithdrawalViewComp')
  19. @ecs.register('WechatWithdrawalView', false)
  20. export class WechatWithdrawalViewComp extends CCComp {
  21. data: any = {
  22. nickName: "",
  23. money: 0,
  24. channel: "微信零钱"
  25. }
  26. @property(RichText)
  27. private richText: RichText = null!;
  28. @property(Node)
  29. private node_notice: Node = null!;
  30. /** 视图层逻辑代码分离演示 */
  31. start() {
  32. // const entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
  33. this.setButton();
  34. this.updateNotice();
  35. this.addEvent();
  36. }
  37. addEvent() {
  38. oops.message.on(GameEvent.openRecordView, this.openRecordView, this);
  39. }
  40. /** 视图对象通过 ecs.Entity.remove(WechatWithdrawalViewComp) 删除组件是触发组件处理自定义释放逻辑 */
  41. reset() {
  42. this.node.destroy();
  43. }
  44. private btn_back() {
  45. oops.gui.remove(UIID.WechatWithdraw);
  46. }
  47. private btn_record() {
  48. if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
  49. CocosHandler.inst.getRecordList();
  50. } else {
  51. oops.gui.open(UIID.WithdrawRecord);
  52. }
  53. }
  54. private openRecordView() {
  55. oops.gui.open(UIID.WithdrawRecord);
  56. }
  57. //更新滚动公告
  58. updateNotice() {
  59. this.node_notice.active = true;
  60. const num = oops.random.getRandomInt(1, 20)
  61. //随机1-500的数,有小数保留两位
  62. const randomNum = Math.random() * 500;
  63. const numStr = randomNum.toFixed(2);
  64. let name = this.getRandomChineseName();
  65. let str = "恭喜<color=#bcdc36>$y</color>收集<color=#bcdc36>$n</color>金砖,到账<color=#bcdc36>$m元</color>";
  66. //正则替换str里边的$y,$n,$m
  67. let str1 = str.replace(/\$y/g, name);
  68. str1 = str1.replace(/\$n/g, num + "块");
  69. str1 = str1.replace(/\$m/g, numStr);
  70. this.richText.string = str1;
  71. this.node_notice.setPosition(new Vec3(0, -40, 0));
  72. tween(this.node_notice)
  73. .to(4, { position: new Vec3(0, 40, 0) })
  74. .call(() => {
  75. this.updateNotice();
  76. })
  77. .start();
  78. }
  79. getRandomChineseName(): string {
  80. const surnames = ["王", "李", "张", "刘", "陈", "杨", "黄", "赵", "周", "吴", "徐", "孙", "胡", "朱", "高", "林", "何", "郭", "马", "罗"];
  81. const characters = "的一是了不在人有我他这中大来上国个到说们时用地为子就那和要出也得于里后自以会着对生能而多小学同见天去好她所然家前开";
  82. // 随机获取姓
  83. const surname = surnames[Math.floor(Math.random() * surnames.length)];
  84. // 生成 1 到 3 个字的名字
  85. const nameLength = Math.floor(Math.random() * 3) + 1;
  86. let givenName = "";
  87. for (let i = 0; i < nameLength; i++) {
  88. givenName += characters[Math.floor(Math.random() * characters.length)];
  89. }
  90. return surname + givenName;
  91. }
  92. }