diff --git a/package-lock.json b/package-lock.json
index a4984ad..80d673a 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -11,6 +11,7 @@
"@ant-design/icons-vue": "^6.1.0",
"axios": "^0.26.1",
"bootstrap": "^5.1.3",
+ "moment": "^2.29.2",
"vue": "^3.2.25"
},
"devDependencies": {
@@ -1061,6 +1062,14 @@
"sourcemap-codec": "^1.4.8"
}
},
+ "node_modules/moment": {
+ "version": "2.29.2",
+ "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.2.tgz",
+ "integrity": "sha512-UgzG4rvxYpN15jgCmVJwac49h9ly9NurikMWGPdVxm8GZD6XjkKPxDTjQQ43gtGgnV3X0cAyWDdP2Wexoquifg==",
+ "engines": {
+ "node": "*"
+ }
+ },
"node_modules/nanoid": {
"version": "3.3.2",
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.2.tgz",
@@ -2348,6 +2357,11 @@
"sourcemap-codec": "^1.4.8"
}
},
+ "moment": {
+ "version": "2.29.2",
+ "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.2.tgz",
+ "integrity": "sha512-UgzG4rvxYpN15jgCmVJwac49h9ly9NurikMWGPdVxm8GZD6XjkKPxDTjQQ43gtGgnV3X0cAyWDdP2Wexoquifg=="
+ },
"nanoid": {
"version": "3.3.2",
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.2.tgz",
diff --git a/package.json b/package.json
index eb660d7..5123786 100644
--- a/package.json
+++ b/package.json
@@ -11,6 +11,7 @@
"@ant-design/icons-vue": "^6.1.0",
"axios": "^0.26.1",
"bootstrap": "^5.1.3",
+ "moment": "^2.29.2",
"vue": "^3.2.25"
},
"devDependencies": {
diff --git a/src/App.vue b/src/App.vue
index e3b5bdb..80d3af0 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -17,7 +17,7 @@ import BJ_Casino_Rank from './components/BJ_Casino_Rank.vue';
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
- margin-top: 60px;
+ margin-top: 0px;
font-family: 'Zen Maru Gothic', sans-serif;
}
diff --git a/src/components/BJ_Casino_Rank.vue b/src/components/BJ_Casino_Rank.vue
index 9e4a832..e1dacb6 100644
--- a/src/components/BJ_Casino_Rank.vue
+++ b/src/components/BJ_Casino_Rank.vue
@@ -6,7 +6,8 @@ import { BJ_Casino_Rank } from "../script/BJ_Casino_Rank";
let Title = ref("BJ_Casino_Rank");
let RankData = ref([]);
const self = {
- RankData: RankData
+ Title: Title,
+ RankData: RankData,
}
const Script = new BJ_Casino_Rank(self);
@@ -23,6 +24,7 @@ const Script = new BJ_Casino_Rank(self);
倍率 |
機台 |
桌號 |
+ 日期 |
@@ -43,8 +45,12 @@ const Script = new BJ_Casino_Rank(self);
{{ item[3][1] }}
|
+
+ {{ item[4] }}
+ |
-
+
+
\ No newline at end of file
diff --git a/src/script/BJ_Casino_Rank.ts b/src/script/BJ_Casino_Rank.ts
index 3fa076f..66b5e52 100644
--- a/src/script/BJ_Casino_Rank.ts
+++ b/src/script/BJ_Casino_Rank.ts
@@ -1,12 +1,36 @@
+import moment from 'moment';
+
export class BJ_Casino_Rank {
+ //#region public
+
+ public ContestData: string[] = ["4/7~4/13", "4/14~4/20", "4/21~4/27"];
+
+ //#endregion
+
//#region private
private _client: any;
private _ws: any;
- private _rankdata: any = null;
+ private _rankdata: any[] = [];
+
+ private _nowSearchContestID: number = 0;
+
+ private _nowContestIndex: number = 0;
+
+ private _nowContestStartIndex: number = 0;
+
+ private _nowContestEndIndex: number = 0;
+
+ private _nowContestID: number = 0;
+
+ private _nowContestDate: string = "";
+
+ private _nowContestStart: string = "";
+
+ private _nowContestEnd: string = "";
//#endregion
@@ -109,7 +133,12 @@ export class BJ_Casino_Rank {
}
case "rank.info": {
- this.SetRankData(Data);
+ this.RankDataCallBack(Data);
+ break;
+ }
+
+ case "rank.history": {
+ this.ParseRankData(Data);
this._ws.close();
break;
}
@@ -119,13 +148,139 @@ export class BJ_Casino_Rank {
}
}
- public SetRankData(data: any) {
- let rankdata = data["rank"];
+ public RankDataCallBack(data: any) {
+ let id = +data["id"];
+ this._nowSearchContestID = id;
+ this._nowContestID = id;
+ this._nowContestDate = moment().format("MM/DD");
+ for (let i = 0; i < this.ContestData.length; i++) {
+ const contest: string = this.ContestData[i];
+ let str = contest.split("~");
+ let my = moment(this._nowContestDate);
+ let start = moment(str[0]);
+ let end = moment(str[1]);
+ let diff: number = my.diff(end, "days");
+ if (diff < 0) {
+ this._nowContestIndex = i;
+ this._nowContestStart = moment(start).format("MM/DD");
+ this._nowContestEnd = moment(end).format("MM/DD");
+ this._nowContestStartIndex = this._contestIDFormDate(this._nowContestStart);
+ this._nowContestEndIndex = this._contestIDFormDate(this._nowContestEnd);
+ break;
+ }
+ }
+ this._client.Title.value = `${this._nowContestStart}~${this._nowContestEnd}`;
+ this.ParseRankData(data);
+ }
+
+ public ParseRankData(data: any) {
+ let id = this._nowSearchContestID;
+ this.RankDataAddDate(id, data["rank"]);
+ this._rankdata = this._rankdata.concat(data["rank"]);
+ if (id !== this._nowContestStartIndex) {
+ this._nowSearchContestID = id - 1;
+ this.SendData("rank.history", { "id": this._nowSearchContestID, "t": 12, "p": 2 });
+ } else {
+ this.OrganizeRankData(this._rankdata);
+ this.SetRankData(this._rankdata);
+ }
+ }
+
+ public RankDataAddDate(id: number, rankdata: any) {
+ let date: string = this._contestDateFormID(id);
+ for (let i = 0; i < rankdata.length; i++) {
+ rankdata[i].push(date);
+ }
+ return rankdata;
+ }
+
+ public OrganizeRankData(rankdata: any) {
+ rankdata.sort((a: any, b: any) => {
+ return b[1] - a[1];
+ });
+ rankdata = rankdata.filter((rankdata: any, index: any, arr: any) => {
+ return arr.findIndex((s: any) => rankdata[2][1] === s[2][1]) === index;
+ });
+ for (let i = 0; i < rankdata.length; i++) {
+ rankdata[i][0] = i + 1;
+ }
+ this._rankdata = rankdata;
+ }
+
+ public SetRankData(rankdata: any) {
this._client.RankData.value = rankdata;
}
//#endregion
+ //#region Get
+
+ private _contestIDFormDate(date: string): number {
+ let my = moment(this._nowContestDate);
+ let target = moment(date);
+ let diffday: number = my.diff(target, "days");
+ let id = this._nowContestID - diffday;
+ if (id < 0) {
+ return 0;
+ } else {
+ return id;
+ }
+ };
+
+ private _contestDateFormID(id: number): string {
+ let my: number = this._nowContestID;
+ let target: number = id;
+ let diffid: number = my - target;
+ if (diffid < 0) {
+ diffid = 0;
+ }
+ let date: string = moment().subtract(diffid, "days").format("MM/DD");
+ return date;
+ };
+
+ //#endregion
+
+ //#region Tools Function
+
+ /**
+ * 陣列排序,asc&key陣列長度請一樣
+ * PS. boolean 帶false是先true在false
+ * @link JavaScript Object 排序 http://www.eion.com.tw/Blogger/?Pid=1170#:~:text=JavaScript%20Object%20排序
+ * @param Arr 需排序陣列
+ * @param asc 是否升序排列(小到大)
+ * @param key 需排序的key(優先順序左到右)(沒有就放空)
+ */
+ public ObjectSort(Arr: any[], asc: boolean[] = [true], key?: string[]): any[] {
+ if (!key || key.length === 0 || Arr.length === 0 || Arr[0][key[0]] === undefined) {
+ console.error(`ObjectSort key error`);
+ return Arr;
+ } else if (asc.length !== key.length) {
+ console.error(`ObjectSort key asc error asc.length: ${asc.length}, key.length: ${key.length}`);
+ return Arr;
+ }
+ let count: number = key ? key.length : 1;
+ for (let i: number = count - 1; i >= 0; i--) {
+ Arr = Arr.sort(function (a: any, b: any): 1 | -1 {
+ let mya: any = a;
+ let myb: any = b;
+ if (key) {
+ mya = a[key[i]];
+ myb = b[key[i]];
+ }
+
+ // 加個等於數字相同不要再去排序到
+ if (asc[i]) {
+ return mya >= myb ? 1 : -1;
+ } else {
+ return mya <= myb ? 1 : -1;
+ }
+ });
+ }
+ return Arr;
+ }
+
+ //#endregion
+
//#region WebSocke
public OnWebSocketMessage(e: any) {