MouseListItem.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import { TimeUtils } from "../../../SubGamePublic/PG_Public/Script/lib/utils/TimeUtils";
  2. import { MouseConst } from "./MouseConst";
  3. import { IHistoryData } from "./MouseHistory";
  4. const { ccclass, property } = cc._decorator;
  5. namespace MouseHistoryItemSpace {
  6. export const Colors = {
  7. oushuNormal: '#353541', //偶数item
  8. jishuNormal: '#30303d',//奇数item
  9. Hover: '#282834',
  10. Pressed: '#353541',
  11. winColor: '#ffffff', // 赢钱的颜色
  12. lostColor: '#A6A4A9', // 输钱的颜色
  13. };
  14. }
  15. @ccclass
  16. export default class MouseListItem extends cc.Component {
  17. @property({ type: cc.Label, tooltip: "时间" })
  18. dateLabel: cc.Label = null;
  19. @property({ type: cc.Label, tooltip: "交易id" })
  20. tradeIdLabel: cc.Label = null;
  21. @property({ type: cc.Label, tooltip: "bet" })
  22. betLabel: cc.Label = null;
  23. @property({ type: cc.Label, tooltip: "score" })
  24. scoreLabel: cc.Label = null;
  25. public index: number;
  26. public dataChanged(data: IHistoryData, index: number = null) {
  27. this.dateLabel.string = this.formatGmtDate(data.createTime);
  28. this.tradeIdLabel.string = this.createOrderId(data);
  29. this.betLabel.string = MouseConst.toFixedString(data.bet);
  30. this.scoreLabel.string = MouseConst.toFixedString(data.win);
  31. this.scoreLabel.node.color = this.getColor(data.win > 0 ? MouseHistoryItemSpace.Colors.winColor : MouseHistoryItemSpace.Colors.lostColor);
  32. if (index != null) {
  33. console.log("MouseListItem==>>", index);
  34. this.index = index;
  35. this.setItemColor(index);
  36. }
  37. }
  38. setItemColor(index: number) {
  39. let buttonNode = this.node.getComponent(cc.Button);
  40. buttonNode.transition = cc.Button.Transition.COLOR;
  41. let normalColor = MouseHistoryItemSpace.Colors.jishuNormal;
  42. if (index % 2 == 0) {
  43. normalColor = MouseHistoryItemSpace.Colors.oushuNormal;
  44. }
  45. this.node.color = this.getColor(normalColor);
  46. buttonNode.normalColor = this.getColor(normalColor);
  47. buttonNode.hoverColor = this.getColor(MouseHistoryItemSpace.Colors.Hover);
  48. buttonNode.pressedColor = this.getColor(MouseHistoryItemSpace.Colors.Pressed);
  49. buttonNode.disabledColor = this.getColor(normalColor);
  50. }
  51. /**@description 读取十六进制颜色值 */
  52. private getColor(hex: string) {
  53. return (new cc.Color()).fromHEX(hex);
  54. }
  55. /**
  56. * 根据当前时区 格式化时间
  57. * @param dateStr
  58. * @returns
  59. */
  60. formatGmtDate(dateStr: string): string {
  61. let currentTimeZone = (0 - new Date().getTimezoneOffset() / 60);
  62. let diffTimeZone = currentTimeZone - (Global.getInstance().serverTimeZone);
  63. let addTime = diffTimeZone * 60 * 60 * 1000;
  64. let currentZoneTime = Number(new Date(dateStr)) + addTime;
  65. let timeStr = TimeUtils.format(currentZoneTime, 'hh:mm:ss MM/dd');
  66. let timeArray = timeStr.split(' ');
  67. return timeArray[0] + "\n" + timeArray[1];
  68. }
  69. /**
  70. * 生成19位的id
  71. * @param data
  72. * @returns
  73. */
  74. createOrderId(data: IHistoryData): string {
  75. let createTimeMill = Number(new Date(data.createTime));
  76. let idStr2 = data.gameId + "" + data.userId + "" + data.id;
  77. let finalStr = "";
  78. let idStr3 = idStr2;
  79. if (idStr2.length <= 14) { // 至少前5位为时间戳
  80. let length1 = 14 - idStr2.length;
  81. let createTimeMillStr = createTimeMill.toString();
  82. let length2 = length1 - createTimeMillStr.length;
  83. let idStr1 = createTimeMill.toString();
  84. if (length2 > 0) {
  85. idStr1 = idStr1 + Math.random().toString(36).substring(0, length2);
  86. } else {
  87. idStr1 = createTimeMill.toString().substring(0, length1);
  88. }
  89. idStr3 = idStr1 + idStr2;
  90. } else {
  91. idStr3 = idStr2.substring(idStr2.length - 14, idStr2.length);
  92. }
  93. let idStr1 = createTimeMill.toString().substring(0, 5);
  94. finalStr = idStr1 + idStr3;
  95. finalStr = finalStr.substring(0, 9) + "\n" + finalStr.substring(9, finalStr.length);
  96. return finalStr;
  97. }
  98. }