[add] 上下周功能

This commit is contained in:
建喵 2022-04-20 11:17:33 +08:00
parent ac42de2c6c
commit 1a6d52211a
6 changed files with 242 additions and 71 deletions

View File

@ -5,7 +5,7 @@ import { BJ_Casino_Magnification } from "../script/BJ_Casino_Magnification";
const props = defineProps<{ BJ_Casino: BJ_Casino_Data }>() const props = defineProps<{ BJ_Casino: BJ_Casino_Data }>()
let Title = ref(""); let Title = ref("我4標題");
let RankData = ref([]); let RankData = ref([]);
const self = { const self = {
Title: Title, Title: Title,
@ -17,7 +17,13 @@ const Script = new BJ_Casino_Magnification(self);
</script> </script>
<template> <template>
<h1>{{ Title }}</h1> <h1>
<el-button type="primary" @click.native="() => { BJ_Casino.PrevWeek() }" size="large" round>&lt;&lt;上一周
</el-button>
{{ Title }}
<el-button type="success" @click.native="() => { BJ_Casino.NextWeek() }" size="large" round>下一周&gt;&gt;
</el-button>
</h1>
<div class="d-flex justify-content-center"> <div class="d-flex justify-content-center">
<table class="table table-striped table-info table-hover"> <table class="table table-striped table-info table-hover">
<thead> <thead>

View File

@ -5,7 +5,7 @@ import { BJ_Casino_WinMoney } from "../script/BJ_Casino_WinMoney";
const props = defineProps<{ BJ_Casino: BJ_Casino_Data }>() const props = defineProps<{ BJ_Casino: BJ_Casino_Data }>()
let Title = ref(""); let Title = ref("我4標題");
let RankData = ref([]); let RankData = ref([]);
const self = { const self = {
Title: Title, Title: Title,
@ -17,7 +17,13 @@ const Script = new BJ_Casino_WinMoney(self);
</script> </script>
<template> <template>
<h1>{{ Title }}</h1> <h1>
<el-button type="primary" @click.native="() => { BJ_Casino.PrevWeek() }" size="large" round>&lt;&lt;上一周
</el-button>
{{ Title }}
<el-button type="success" @click.native="() => { BJ_Casino.NextWeek() }" size="large" round>下一周&gt;&gt;
</el-button>
</h1>
<div class="d-flex justify-content-center"> <div class="d-flex justify-content-center">
<table class="table table-striped table-info table-hover"> <table class="table table-striped table-info table-hover">
<thead> <thead>

View File

@ -18,6 +18,8 @@ export class BJ_Casino_Data {
public Client: any; public Client: any;
public Current: any[] = [];
//#endregion //#endregion
//#region private //#region private
@ -46,6 +48,8 @@ export class BJ_Casino_Data {
private _nowContestEnd: string = ""; private _nowContestEnd: string = "";
private _isIDupup: boolean = false;
/** /**
* 0 _rankMagnificationData * 0 _rankMagnificationData
* 1 _rankWinMoneyData * 1 _rankWinMoneyData
@ -73,8 +77,20 @@ export class BJ_Casino_Data {
} }
public async onLoad(): Promise<void> { public async onLoad(): Promise<void> {
// CoroutineV2.Single(this.aaa()).Start(); await this.ConnectServer();
let self: this = this; await this.SendRankData();
}
public SetCurrent(current: any): void {
this.Current.push(current);
}
//#endregion
//#region 網路相關
/** 連線 */
public async ConnectServer(): Promise<void> {
const URL: string = "https://game.online-bj.com"; const URL: string = "https://game.online-bj.com";
const Port: string = "9005"; const Port: string = "9005";
await this.ConnectAsync(URL, +Port); await this.ConnectAsync(URL, +Port);
@ -86,15 +102,7 @@ export class BJ_Casino_Data {
CSMessage.NetError(resp.Method, resp.Status, "Login Account Error!"); CSMessage.NetError(resp.Method, resp.Status, "Login Account Error!");
return; return;
} }
await this.SendRankData();
} }
public *aaa(): IterableIterator<any> {
console.log("aaa");
}
//#endregion
//#region 網路相關
/** 連線(目前沒有重連機制) */ /** 連線(目前沒有重連機制) */
public async ConnectAsync(host: string, port: number): Promise<void> { public async ConnectAsync(host: string, port: number): Promise<void> {
@ -150,12 +158,15 @@ export class BJ_Casino_Data {
if (!resp.IsValid) { if (!resp.IsValid) {
if (resp.Status === 11) { if (resp.Status === 11) {
CSMessage.NetError(resp.Method, resp.Status, "Rank 無資料"); CSMessage.NetError(resp.Method, resp.Status, "Rank 無資料");
this.OrganizeRankMagnificationData(this._rankMagnificationData);
this.SetRankMagnificationDataOK();
} else { } else {
CSMessage.NetError(resp.Method, resp.Status, "Get RankInfo Fail"); CSMessage.NetError(resp.Method, resp.Status, "Get RankInfo Fail");
} }
return; return;
} }
await this.RankMagnificationDataCallBack(resp.Data); this.SetRankMagnificationSearchData(resp.Data);
this.ParseRankMagnificationData(resp.Data);
} }
public async SendRankWinMoneyData(): Promise<void> { public async SendRankWinMoneyData(): Promise<void> {
@ -166,15 +177,18 @@ export class BJ_Casino_Data {
if (!resp.IsValid) { if (!resp.IsValid) {
if (resp.Status === 11) { if (resp.Status === 11) {
CSMessage.NetError(resp.Method, resp.Status, "Rank 無資料"); CSMessage.NetError(resp.Method, resp.Status, "Rank 無資料");
this.OrganizeRankMagnificationData(this._rankMagnificationData);
this.SetRankMagnificationDataOK();
} else { } else {
CSMessage.NetError(resp.Method, resp.Status, "Get RankInfo Fail"); CSMessage.NetError(resp.Method, resp.Status, "Get RankInfo Fail");
} }
return; return;
} }
await this.RankWinMoneyDataCallBack(resp.Data); this.SetRankWinMoneySearchData(resp.Data);
this.ParseRankWinMoneyData(resp.Data);
} }
public async RankMagnificationDataCallBack(data: any) { public SetRankMagnificationSearchData(data: any): void {
let id: number = +data["id"]; let id: number = +data["id"];
this._nowSearchMagnificationID = id; this._nowSearchMagnificationID = id;
this._nowContestID = id; this._nowContestID = id;
@ -196,23 +210,30 @@ export class BJ_Casino_Data {
} }
} }
this.Title = `${this._nowContestStart}~${this._nowContestEnd}`; this.Title = `${this._nowContestStart}~${this._nowContestEnd}`;
this.ParseRankMagnificationData(data);
} }
public async ParseRankMagnificationData(data: any) { public async ParseRankMagnificationData(data: any = null): Promise<void> {
let id = this._nowSearchMagnificationID; let id: number = this._nowSearchMagnificationID;
if (data) {
this.RankDataAddDate(id, data["rank"]); this.RankDataAddDate(id, data["rank"]);
this._rankMagnificationData = this._rankMagnificationData.concat(data["rank"]); this._rankMagnificationData = this._rankMagnificationData.concat(data["rank"]);
if (id !== this._nowContestStartIndex) { }
let targetIndex: number = this._nowContestStartIndex;
if (this._isIDupup) {
targetIndex = this._nowContestEndIndex;
}
if (id !== targetIndex) {
if (this._isIDupup) {
this._nowSearchMagnificationID = id + 1;
} else {
this._nowSearchMagnificationID = id - 1; this._nowSearchMagnificationID = id - 1;
// this.SendData("rank.history", { "id": this._nowSearchContestID, "t": 12, "p": 2 }); }
let req: any = null; let req: any = await this.GetRankData(12, this._nowSearchMagnificationID);
req = new AppRankHistory(12, 2, this._nowSearchMagnificationID);
await req.SendAsync(true);
let resp: INetResponse<any> = req.Result; let resp: INetResponse<any> = req.Result;
if (!resp.IsValid) { if (!resp.IsValid) {
if (resp.Status == 11) { if (resp.Status === 11) {
CSMessage.NetError(resp.Method, resp.Status, "Rank 無資料"); CSMessage.NetError(resp.Method, resp.Status, "Rank 無資料");
this.ParseRankMagnificationData(resp.Data);
} else { } else {
CSMessage.NetError(resp.Method, resp.Status, "Get RankInfo Fail"); CSMessage.NetError(resp.Method, resp.Status, "Get RankInfo Fail");
} }
@ -222,47 +243,65 @@ export class BJ_Casino_Data {
return; return;
} else { } else {
this.OrganizeRankMagnificationData(this._rankMagnificationData); this.OrganizeRankMagnificationData(this._rankMagnificationData);
this.SetRankMagnificationData(this._rankMagnificationData); this.SetRankMagnificationDataOK();
} }
} }
public OrganizeRankMagnificationData(rankdata: any) { public async GetRankData(type: number, dayIdid: number): Promise<any> {
let req: any = null;
req = new AppRankHistory(type, 2, dayIdid);
if (dayIdid === this._nowContestID) {
req = new AppRankInfo(type, 2);
}
await req.SendAsync(true);
return req;
}
public OrganizeRankMagnificationData(rankdata: any): void {
rankdata.sort((a: any, b: any) => { rankdata.sort((a: any, b: any) => {
return b[1] - a[1]; return b[1] - a[1];
}); });
rankdata = rankdata.filter((rankdata: any, index: any, arr: any) => { rankdata = rankdata.filter((rankdata: any, index: any, arr: any) => {
return arr.findIndex((s: any) => rankdata[2][1] === s[2][1]) === index; return arr.findIndex((s: any) => rankdata[2][1] === s[2][1]) === index;
}); });
for (let i = 0; i < rankdata.length; i++) { for (let i: number = 0; i < rankdata.length; i++) {
rankdata[i][0] = i + 1; rankdata[i][0] = i + 1;
} }
this._rankMagnificationData = rankdata; this._rankMagnificationData = rankdata;
} }
public SetRankMagnificationData(rankdata: any) { public SetRankMagnificationDataOK(): void {
this._isOK[0] = true; this._isOK[0] = true;
this._checkOK(); this._checkOK();
} }
public async RankWinMoneyDataCallBack(data: any) { public SetRankWinMoneySearchData(data: any): void {
let id = +data["id"]; let id: number = +data["id"];
this._nowSearchWinMoneyID = id; this._nowSearchWinMoneyID = id;
this.ParseRankWinMoneyData(data);
} }
public async ParseRankWinMoneyData(data: any) { public async ParseRankWinMoneyData(data: any = null): Promise<void> {
let id = this._nowSearchWinMoneyID; let id: number = this._nowSearchWinMoneyID;
if (data) {
this.RankDataAddDate(id, data["rank"]); this.RankDataAddDate(id, data["rank"]);
this._rankWinMoneyData = this._rankWinMoneyData.concat(data["rank"]); this._rankWinMoneyData = this._rankWinMoneyData.concat(data["rank"]);
if (id !== this._nowContestStartIndex) { }
let targetIndex: number = this._nowContestStartIndex;
if (this._isIDupup) {
targetIndex = this._nowContestEndIndex;
}
if (id !== targetIndex) {
if (this._isIDupup) {
this._nowSearchWinMoneyID = id + 1;
} else {
this._nowSearchWinMoneyID = id - 1; this._nowSearchWinMoneyID = id - 1;
let req: any = null; }
req = new AppRankHistory(11, 2, this._nowSearchWinMoneyID); let req: any = await this.GetRankData(11, this._nowSearchWinMoneyID);
await req.SendAsync(true);
let resp: INetResponse<any> = req.Result; let resp: INetResponse<any> = req.Result;
if (!resp.IsValid) { if (!resp.IsValid) {
if (resp.Status == 11) { if (resp.Status === 11) {
CSMessage.NetError(resp.Method, resp.Status, "Rank 無資料"); CSMessage.NetError(resp.Method, resp.Status, "Rank 無資料");
this.ParseRankWinMoneyData();
} else { } else {
CSMessage.NetError(resp.Method, resp.Status, "Get RankInfo Fail"); CSMessage.NetError(resp.Method, resp.Status, "Get RankInfo Fail");
} }
@ -272,53 +311,171 @@ export class BJ_Casino_Data {
return; return;
} else { } else {
this.OrganizeRankWinMoneyData(this._rankWinMoneyData); this.OrganizeRankWinMoneyData(this._rankWinMoneyData);
this.SetRankWinMoneyData(this._rankWinMoneyData); this.SetRankWinMoneyDataOK();
} }
} }
public OrganizeRankWinMoneyData(rankdata: any) { public OrganizeRankWinMoneyData(rankdata: any): void {
rankdata.sort((a: any, b: any) => { rankdata.sort((a: any, b: any) => {
return b[1] - a[1]; return b[1] - a[1];
}); });
rankdata = rankdata.filter((rankdata: any, index: any, arr: any) => { rankdata = rankdata.filter((rankdata: any, index: any, arr: any) => {
return arr.findIndex((s: any) => rankdata[2][1] === s[2][1]) === index; return arr.findIndex((s: any) => rankdata[2][1] === s[2][1]) === index;
}); });
for (let i = 0; i < rankdata.length; i++) { for (let i: number = 0; i < rankdata.length; i++) {
rankdata[i][0] = i + 1; rankdata[i][0] = i + 1;
} }
this._rankWinMoneyData = rankdata; this._rankWinMoneyData = rankdata;
} }
public SetRankWinMoneyData(rankdata: any) { public SetRankWinMoneyDataOK(): void {
this._isOK[1] = true; this._isOK[1] = true;
this._checkOK(); this._checkOK();
} }
public RankDataAddDate(id: number, rankdata: any) { public RankDataAddDate(id: number, rankdata: any): any {
let date: string = this._contestDateFormID(id); let date: string = this._contestDateFormID(id);
for (let i = 0; i < rankdata.length; i++) { for (let i: number = 0; i < rankdata.length; i++) {
rankdata[i].push(date); rankdata[i].push(date);
} }
return rankdata; return rankdata;
} }
private _checkOK() { private _checkOK(): void {
if (this._isOK.includes(false)) { if (this._isOK.includes(false)) {
return; return;
} }
NetManager.Disconnect(); NetManager.Disconnect();
for (let i: number = 0; i < this.Current.length; i++) {
const current: any = this.Current[i];
current.SetInit();
}
this.Client.isLoading.value = false; this.Client.isLoading.value = false;
} }
public async PrevWeek(): Promise<void> {
let nowContestIndex: number = this._nowContestIndex;
if (nowContestIndex - 1 >= 0) {
nowContestIndex--;
} else {
alert(`到底了`);
return;
}
this._isIDupup = false;
await this.RunSetWeek(nowContestIndex);
// const contest: string = this.ContestData[nowContestIndex];
// let str: string[] = contest.split("~");
// let my: moment.Moment = this._getMomentFormString(this._nowContestDate);
// let start: moment.Moment = this._getMomentFormString(str[0]);
// let end: moment.Moment = this._getMomentFormString(str[1]);
// let diff: number = my.diff(start, "day");
// if (diff < 0) {
// alert(`還沒開放`);
// return;
// }
// this.Client.isLoading.value = true;
// this._isOK[0] = false;
// this._isOK[1] = false;
// this._nowContestStart = moment(start).format("MM/DD");
// this._nowContestEnd = moment(end).format("MM/DD");
// this._nowContestStartIndex = this._contestIDFormDate(this._nowContestStart);
// this._nowContestEndIndex = this._nowSearchMagnificationID = this._contestIDFormDate(this._nowContestEnd);
// this.Title = `${this._nowContestStart}~${this._nowContestEnd}`;
// await this.ConnectServer();
// this.RunRankMagnificationWeek();
// this.RunRankWinMoneyWeek();
}
public async NextWeek(): Promise<void> {
let nowContestIndex: number = this._nowContestIndex;
if (nowContestIndex + 1 < this.ContestData.length) {
nowContestIndex++;
} else {
alert(`到底了`);
return;
}
this._isIDupup = true;
await this.RunSetWeek(nowContestIndex);
}
public async RunSetWeek(nowContestIndex: number): Promise<void> {
const contest: string = this.ContestData[nowContestIndex];
let str: string[] = contest.split("~");
let my: moment.Moment = this._getMomentFormString(this._nowContestDate);
let start: moment.Moment = this._getMomentFormString(str[0]);
let end: moment.Moment = this._getMomentFormString(str[1]);
let diff: number = my.diff(start, "day");
if (diff < 0) {
alert(`還沒開放`);
return;
}
this._nowContestIndex = nowContestIndex;
this.Client.isLoading.value = true;
this._isOK[0] = false;
this._isOK[1] = false;
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);
if (this._isIDupup) {
this._nowSearchMagnificationID = this._nowSearchWinMoneyID = this._contestIDFormDate(this._nowContestStart);
} else {
this._nowSearchMagnificationID = this._nowSearchWinMoneyID = this._contestIDFormDate(this._nowContestEnd);
}
this.Title = `${this._nowContestStart}~${this._nowContestEnd}`;
await this.ConnectServer();
this.RunRankMagnificationWeek();
this.RunRankWinMoneyWeek();
}
public async RunRankMagnificationWeek(): Promise<void> {
this._rankMagnificationData = [];
let req: any = await this.GetRankData(12, this._nowSearchMagnificationID);
let resp: INetResponse<any> = req.Result;
if (!resp.IsValid) {
if (resp.Status === 11) {
CSMessage.NetError(resp.Method, resp.Status, "Rank 無資料");
this.OrganizeRankMagnificationData(this._rankMagnificationData);
this.SetRankMagnificationDataOK();
} else {
CSMessage.NetError(resp.Method, resp.Status, "Get RankInfo Fail");
}
return;
}
this.ParseRankMagnificationData(resp.Data);
}
public async RunRankWinMoneyWeek(): Promise<void> {
this._rankWinMoneyData = [];
let req: any = await this.GetRankData(11, this._nowSearchWinMoneyID);
let resp: INetResponse<any> = req.Result;
if (!resp.IsValid) {
if (resp.Status === 11) {
CSMessage.NetError(resp.Method, resp.Status, "Rank 無資料");
this.OrganizeRankWinMoneyData(this._rankWinMoneyData);
this.SetRankWinMoneyDataOK();
} else {
CSMessage.NetError(resp.Method, resp.Status, "Get RankInfo Fail");
}
return;
}
this.ParseRankWinMoneyData(resp.Data);
}
//#endregion //#endregion
//#region Get //#region Get
private _contestIDFormDate(date: string): number { private _contestIDFormDate(date: string): number {
let my = this._getMomentFormString(this._nowContestDate); let my: moment.Moment = this._getMomentFormString(this._nowContestDate);
let target = this._getMomentFormString(date); let target: moment.Moment = this._getMomentFormString(date);
let diffday: number = my.diff(target, "day"); let diffday: number = my.diff(target, "day");
let id = this._nowContestID - diffday; let id: number = this._nowContestID - diffday;
if (id < 0) { if (id < 0) {
return 0; return 0;
} else { } else {
@ -389,11 +546,11 @@ export class BJ_Casino_Data {
return Arr; return Arr;
} }
public Sleep(ms: number) { public Sleep(ms: number): Promise<any> {
return new Promise(resolve => setTimeout(resolve, ms)); return new Promise(resolve => setTimeout(resolve, ms));
} }
public AddLog(log: any) { public AddLog(log: any): void {
console.log(log); console.log(log);
// var textarea = document.getElementById("Log"); // var textarea = document.getElementById("Log");
// textarea.value += log + "\n"; // textarea.value += log + "\n";

View File

@ -22,26 +22,27 @@ export class BJ_Casino_Magnification {
constructor(client: any) { constructor(client: any) {
this._client = client; this._client = client;
this.BJ_Casino = client.BJ_Casino; this.BJ_Casino = client.BJ_Casino;
this.BJ_Casino?.SetCurrent(this);
this.onLoad(); this.onLoad();
} }
public async onLoad() { public async onLoad(): Promise<void> {
await this.SetInit(); await this.SetInit();
}; }
public async SetInit() { public async SetInit(): Promise<void> {
while (this.BJ_Casino?.Client.isLoading.value) { while (this.BJ_Casino?.Client.isLoading.value) {
await Tools.Sleep(50); await Tools.Sleep(50);
} }
this._client.Title.value = this.BJ_Casino?.Title; this._client.Title.value = this.BJ_Casino?.Title;
this.SendData(); this.SendData();
}; }
//#endregion //#endregion
//#region Custom //#region Custom
public SendData() { public SendData(): void {
this._client.RankData.value = this.BJ_Casino?.RankMagnificationData; this._client.RankData.value = this.BJ_Casino?.RankMagnificationData;
} }

View File

@ -22,26 +22,27 @@ export class BJ_Casino_WinMoney {
constructor(client: any) { constructor(client: any) {
this._client = client; this._client = client;
this.BJ_Casino = client.BJ_Casino; this.BJ_Casino = client.BJ_Casino;
this.BJ_Casino?.SetCurrent(this);
this.onLoad(); this.onLoad();
} }
public async onLoad() { public async onLoad(): Promise<void> {
await this.SetInit(); await this.SetInit();
}; }
public async SetInit() { public async SetInit(): Promise<void> {
while (this.BJ_Casino?.Client.isLoading.value) { while (this.BJ_Casino?.Client.isLoading.value) {
await Tools.Sleep(50); await Tools.Sleep(50);
} }
this._client.Title.value = this.BJ_Casino?.Title; this._client.Title.value = this.BJ_Casino?.Title;
this.SendData(); this.SendData();
}; }
//#endregion //#endregion
//#region Custom //#region Custom
public SendData() { public SendData(): void {
this._client.RankData.value = this.BJ_Casino?.RankWinMoneyData; this._client.RankData.value = this.BJ_Casino?.RankWinMoneyData;
} }

View File

@ -1,8 +1,8 @@
/**訊息框相關 */ /** 訊息框相關 */
export default class CSMessage { export default class CSMessage {
/**網路錯誤訊息 */ /** 網路錯誤訊息 */
public static NetError(method: string, state: number, str: string = ""): void { public static NetError(method: string, state: number, str: string = ""): void {
let error = String.Format("[{0}] state:{1} {2}", method, state, str); let error: string = String.Format("[{0}] state:{1} {2}", method, state, str);
console.warn("網路錯誤訊息: ", error); console.warn("網路錯誤訊息: ", error);
} }
} }