WechatWithdrawalViewComp.ts 3.8 KB

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