123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- import { TimeUtils } from "../../../SubGamePublic/PG_Public/Script/lib/utils/TimeUtils";
- import { MouseConst } from "./MouseConst";
- import { IHistoryData } from "./MouseHistory";
- const { ccclass, property } = cc._decorator;
- namespace MouseHistoryItemSpace {
- export const Colors = {
- oushuNormal: '#353541', //偶数item
- jishuNormal: '#30303d',//奇数item
- Hover: '#282834',
- Pressed: '#353541',
- winColor: '#ffffff', // 赢钱的颜色
- lostColor: '#A6A4A9', // 输钱的颜色
- };
- }
- @ccclass
- export default class MouseListItem extends cc.Component {
- @property({ type: cc.Label, tooltip: "时间" })
- dateLabel: cc.Label = null;
- @property({ type: cc.Label, tooltip: "交易id" })
- tradeIdLabel: cc.Label = null;
- @property({ type: cc.Label, tooltip: "bet" })
- betLabel: cc.Label = null;
- @property({ type: cc.Label, tooltip: "score" })
- scoreLabel: cc.Label = null;
- public index: number;
- public dataChanged(data: IHistoryData, index: number = null) {
- this.dateLabel.string = this.formatGmtDate(data.createTime);
- this.tradeIdLabel.string = this.createOrderId(data);
- this.betLabel.string = MouseConst.toFixedString(data.bet);
- this.scoreLabel.string = MouseConst.toFixedString(data.win);
- this.scoreLabel.node.color = this.getColor(data.win > 0 ? MouseHistoryItemSpace.Colors.winColor : MouseHistoryItemSpace.Colors.lostColor);
- if (index != null) {
- console.log("MouseListItem==>>", index);
- this.index = index;
- this.setItemColor(index);
- }
- }
- setItemColor(index: number) {
- let buttonNode = this.node.getComponent(cc.Button);
- buttonNode.transition = cc.Button.Transition.COLOR;
- let normalColor = MouseHistoryItemSpace.Colors.jishuNormal;
- if (index % 2 == 0) {
- normalColor = MouseHistoryItemSpace.Colors.oushuNormal;
- }
- this.node.color = this.getColor(normalColor);
- buttonNode.normalColor = this.getColor(normalColor);
- buttonNode.hoverColor = this.getColor(MouseHistoryItemSpace.Colors.Hover);
- buttonNode.pressedColor = this.getColor(MouseHistoryItemSpace.Colors.Pressed);
- buttonNode.disabledColor = this.getColor(normalColor);
- }
- /**@description 读取十六进制颜色值 */
- private getColor(hex: string) {
- return (new cc.Color()).fromHEX(hex);
- }
- /**
- * 根据当前时区 格式化时间
- * @param dateStr
- * @returns
- */
- formatGmtDate(dateStr: string): string {
- let currentTimeZone = (0 - new Date().getTimezoneOffset() / 60);
- let diffTimeZone = currentTimeZone - (Global.getInstance().serverTimeZone);
- let addTime = diffTimeZone * 60 * 60 * 1000;
- let currentZoneTime = Number(new Date(dateStr)) + addTime;
- let timeStr = TimeUtils.format(currentZoneTime, 'hh:mm:ss MM/dd');
- let timeArray = timeStr.split(' ');
- return timeArray[0] + "\n" + timeArray[1];
- }
- /**
- * 生成19位的id
- * @param data
- * @returns
- */
- createOrderId(data: IHistoryData): string {
- let createTimeMill = Number(new Date(data.createTime));
- let idStr2 = data.gameId + "" + data.userId + "" + data.id;
- let finalStr = "";
- let idStr3 = idStr2;
- if (idStr2.length <= 14) { // 至少前5位为时间戳
- let length1 = 14 - idStr2.length;
- let createTimeMillStr = createTimeMill.toString();
- let length2 = length1 - createTimeMillStr.length;
- let idStr1 = createTimeMill.toString();
- if (length2 > 0) {
- idStr1 = idStr1 + Math.random().toString(36).substring(0, length2);
- } else {
- idStr1 = createTimeMill.toString().substring(0, length1);
- }
- idStr3 = idStr1 + idStr2;
- } else {
- idStr3 = idStr2.substring(idStr2.length - 14, idStr2.length);
- }
- let idStr1 = createTimeMill.toString().substring(0, 5);
- finalStr = idStr1 + idStr3;
- finalStr = finalStr.substring(0, 9) + "\n" + finalStr.substring(9, finalStr.length);
- return finalStr;
- }
- }
|