[add] get moment方式

This commit is contained in:
建喵 2022-04-19 14:35:53 +08:00
parent 844c15072b
commit b20cdb08a1
6 changed files with 73 additions and 292 deletions

13
package-lock.json generated
View File

@ -18,7 +18,6 @@
"vue-loading-overlay": "^5.0.3" "vue-loading-overlay": "^5.0.3"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^17.0.24",
"@vitejs/plugin-vue": "^2.3.0", "@vitejs/plugin-vue": "^2.3.0",
"typescript": "^4.5.4", "typescript": "^4.5.4",
"vite": "^2.9.0", "vite": "^2.9.0",
@ -158,12 +157,6 @@
"@types/lodash": "*" "@types/lodash": "*"
} }
}, },
"node_modules/@types/node": {
"version": "17.0.24",
"resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.24.tgz",
"integrity": "sha512-aveCYRQbgTH9Pssp1voEP7HiuWlD2jW2BO56w+bVrJn04i61yh6mRfoKO6hEYQD9vF+W8Chkwc6j1M36uPkx4g==",
"dev": true
},
"node_modules/@vitejs/plugin-vue": { "node_modules/@vitejs/plugin-vue": {
"version": "2.3.1", "version": "2.3.1",
"resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-2.3.1.tgz", "resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-2.3.1.tgz",
@ -1947,12 +1940,6 @@
"@types/lodash": "*" "@types/lodash": "*"
} }
}, },
"@types/node": {
"version": "17.0.24",
"resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.24.tgz",
"integrity": "sha512-aveCYRQbgTH9Pssp1voEP7HiuWlD2jW2BO56w+bVrJn04i61yh6mRfoKO6hEYQD9vF+W8Chkwc6j1M36uPkx4g==",
"dev": true
},
"@vitejs/plugin-vue": { "@vitejs/plugin-vue": {
"version": "2.3.1", "version": "2.3.1",
"resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-2.3.1.tgz", "resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-2.3.1.tgz",

View File

@ -3,7 +3,7 @@
"private": true, "private": true,
"version": "0.0.0", "version": "0.0.0",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite --host",
"build": "vite build", "build": "vite build",
"preview": "vite preview" "preview": "vite preview"
}, },

View File

@ -44,7 +44,7 @@ const handleClick = (tab: TabsPaneContext, event: Event) => {
} }
.el-tabs__item { .el-tabs__item {
font-size: 25px; font-size: 18px;
} }
#app { #app {

View File

@ -1,11 +1,15 @@
import '@popperjs/core'; // 引入bootstrap组件库
import 'bootstrap'; import "@popperjs/core";
import 'bootstrap/dist/css/bootstrap.min.css'; import "bootstrap";
import ElementPlus from 'element-plus'; import "bootstrap/dist/css/bootstrap.min.css";
import 'element-plus/dist/index.css'; // 引入Element-Plus组件库
import locale from 'element-plus/lib/locale/lang/zh-tw'; import ElementPlus from "element-plus";
import { createApp } from 'vue'; import "element-plus/dist/index.css";
import App from './App.vue'; import locale from "element-plus/lib/locale/lang/zh-tw";
import { createApp } from "vue";
import App from "./App.vue";
// // 引入弹窗组件v3popup
// import V3Popup from "@components/v3popup"
createApp(App).use(ElementPlus, { locale }).mount("#app");
createApp(App).use(ElementPlus, { locale }).mount('#app') // createApp(App).use(ElementPlus, { locale }).use(V3Popup).mount("#app");

View File

@ -1,12 +1,12 @@
import moment from 'moment'; import moment from "moment";
import CSMessage from './Base/CSMessage'; import CSMessage from "./Base/CSMessage";
import { AccountLoginRequest } from './Base/Request/AccountRequest'; import { AccountLoginRequest } from "./Base/Request/AccountRequest";
import { AppRankHistory, AppRankInfo } from './Base/Request/RankRequest'; import { AppRankHistory, AppRankInfo } from "./Base/Request/RankRequest";
import './Engine/CatanEngine/CSharp/String'; import "./Engine/CatanEngine/CSharp/String";
import { INetResponse } from './Engine/CatanEngine/NetManagerV2/Core/INetResponse'; import { INetResponse } from "./Engine/CatanEngine/NetManagerV2/Core/INetResponse";
import { NetConnector } from './Engine/CatanEngine/NetManagerV2/NetConnector'; import { NetConnector } from "./Engine/CatanEngine/NetManagerV2/NetConnector";
import { NetManager } from './Engine/CatanEngine/NetManagerV2/NetManager'; import { NetManager } from "./Engine/CatanEngine/NetManagerV2/NetManager";
import { Tools } from './Tools'; import { Tools } from "./Tools";
export class BJ_Casino_Data { export class BJ_Casino_Data {
@ -56,9 +56,9 @@ export class BJ_Casino_Data {
//#region get set //#region get set
public get RankMagnificationData(): any[] { return this._rankMagnificationData }; public get RankMagnificationData(): any[] { return this._rankMagnificationData; }
public get RankWinMoneyData(): any[] { return this._rankWinMoneyData }; public get RankWinMoneyData(): any[] { return this._rankWinMoneyData; }
//#endregion //#endregion
@ -72,11 +72,11 @@ export class BJ_Casino_Data {
this.onLoad(); this.onLoad();
} }
public async onLoad() { public async onLoad(): Promise<void> {
// CoroutineV2.Single(this.aaa()).Start(); // CoroutineV2.Single(this.aaa()).Start();
let self: this = this; let self: this = this;
const URL = "https://game.online-bj.com"; const URL: string = "https://game.online-bj.com";
const Port = "9005"; const Port: string = "9005";
await this.ConnectAsync(URL, +Port); await this.ConnectAsync(URL, +Port);
// 取得帳號資料 // 取得帳號資料
let req: AccountLoginRequest = new AccountLoginRequest("ct00000691", "4lsAyoalajm7"); let req: AccountLoginRequest = new AccountLoginRequest("ct00000691", "4lsAyoalajm7");
@ -87,51 +87,7 @@ export class BJ_Casino_Data {
return; return;
} }
await this.SendRankData(); await this.SendRankData();
return;
try {
// const URL = document.getElementById("URL").value;
// const Port = document.getElementById("Port").value;
// const URL = "wss://game.online-bj.com";
// const Port = "9005";
const Account = { "p": 0, "device_info": ["Windows", "Windows"], "fcm_token": "", "a": "ct00000691", "pw": "4lsAyoalajm7", "ver": "1.3.0" };
// const URL = "ws://192.168.5.12";
// const Port = "9487";
// const URL = "ws://220.134.195.1";
// const Port = "19005";
// const Account = { "p": 0, "device_info": ["Windows", "Windows"], "fcm_token": "", "a": "ct00002242", "pw": "n0tfHlVuEhpO", "ver": "1.3.0" };
if (this._ws) {
this.AddLog("中斷上一個連線");
this._ws.close();
} }
this._ws = new WebSocket(`${URL}:${Port}`);//连接服务器
//连接websocket
this._ws.onopen = function (event: any, AlarmMessage: any) {
self.AddLog("已經與服務器建立了連接,當前連接狀態:" + this.readyState);
self.SendData("account.login", Account);
};
//websocket传输数据
this._ws.onmessage = this.OnWebSocketMessage.bind(this);
//websocket关闭连接
this._ws.onclose = function (event: any) {
self.AddLog("已經與服務器斷開連接,當前連接狀態:" + this.readyState);
};
//websocket连接异常
this._ws.onerror = function (event: any) {
// alert("WebSocket异常");
self.AddLog("WebSocket異常");
};
} catch (ex) {
// alert(ex.message);
this.AddLog(ex);
}
};
public *aaa(): IterableIterator<any> { public *aaa(): IterableIterator<any> {
console.log("aaa"); console.log("aaa");
} }
@ -141,19 +97,19 @@ export class BJ_Casino_Data {
//#region 網路相關 //#region 網路相關
/** 連線(目前沒有重連機制) */ /** 連線(目前沒有重連機制) */
public async ConnectAsync(host: string, port: number) { public async ConnectAsync(host: string, port: number): Promise<void> {
var url = "https://api.ipify.org/?format=json"; var url: string = "https://api.ipify.org/?format=json";
var xhr = new XMLHttpRequest(); var xhr: XMLHttpRequest = new XMLHttpRequest();
let ip: string = ""; let ip: string = "";
xhr.onreadystatechange = function () { xhr.onreadystatechange = function (): void {
if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) { if (xhr.readyState === 4 && (xhr.status >= 200 && xhr.status < 400)) {
ip = JSON.parse(xhr.responseText)["ip"]; ip = JSON.parse(xhr.responseText)["ip"];
} }
}; };
xhr.open("GET", url, true); xhr.open("GET", url, true);
xhr.send(); xhr.send();
console.log("[事件]準備連線..."); console.log("[事件]準備連線...");
while (ip == "") { while (ip === "") {
await Tools.Sleep(1); await Tools.Sleep(1);
} }
this._conn = new NetConnector(host, port, ip); this._conn = new NetConnector(host, port, ip);
@ -166,13 +122,13 @@ export class BJ_Casino_Data {
console.log(String.Format("[事件]連線狀態: {0}", NetManager.IsConnected)); console.log(String.Format("[事件]連線狀態: {0}", NetManager.IsConnected));
} }
private _onNetDisconnected() { private _onNetDisconnected(): void {
console.log("[事件] 收到連線中斷事件"); console.log("[事件] 收到連線中斷事件");
this._conn.OnDataReceived.RemoveAllCallbacks(); this._conn.OnDataReceived.RemoveAllCallbacks();
// MainControl.DataReceivedEvent.DispatchCallback([MainControl.DataType.NetDisconnected]); // MainControl.DataReceivedEvent.DispatchCallback([MainControl.DataType.NetDisconnected]);
} }
private _onNetDataReceived(resp: INetResponse<any>) { private _onNetDataReceived(resp: INetResponse<any>): void {
console.log(`[事件] 收到server呼叫: ${resp.Method}(${JSON.stringify(resp.Data)}), 狀態: ${resp.Status}`); console.log(`[事件] 收到server呼叫: ${resp.Method}(${JSON.stringify(resp.Data)}), 狀態: ${resp.Status}`);
// MainControl.DataReceivedEvent.DispatchCallback([MainControl.DataType.ServerData, resp]); // MainControl.DataReceivedEvent.DispatchCallback([MainControl.DataType.ServerData, resp]);
} }
@ -181,18 +137,18 @@ export class BJ_Casino_Data {
//#region Custom //#region Custom
public async SendRankData() { public async SendRankData(): Promise<void> {
this.SendRankMagnificationData(); this.SendRankMagnificationData();
this.SendRankWinMoneyData(); this.SendRankWinMoneyData();
} }
public async SendRankMagnificationData() { public async SendRankMagnificationData(): Promise<void> {
let req: any = null; let req: any = null;
req = new AppRankInfo(12, 2); req = new AppRankInfo(12, 2);
await req.SendAsync(true); 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 無資料");
} else { } else {
CSMessage.NetError(resp.Method, resp.Status, "Get RankInfo Fail"); CSMessage.NetError(resp.Method, resp.Status, "Get RankInfo Fail");
@ -202,13 +158,13 @@ export class BJ_Casino_Data {
await this.RankMagnificationDataCallBack(resp.Data); await this.RankMagnificationDataCallBack(resp.Data);
} }
public async SendRankWinMoneyData() { public async SendRankWinMoneyData(): Promise<void> {
let req: any = null; let req: any = null;
req = new AppRankInfo(11, 2); req = new AppRankInfo(11, 2);
await req.SendAsync(true); 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 無資料");
} else { } else {
CSMessage.NetError(resp.Method, resp.Status, "Get RankInfo Fail"); CSMessage.NetError(resp.Method, resp.Status, "Get RankInfo Fail");
@ -218,68 +174,18 @@ export class BJ_Casino_Data {
await this.RankWinMoneyDataCallBack(resp.Data); await this.RankWinMoneyDataCallBack(resp.Data);
} }
public SendData(Method: string, Data: any) {
let json = [Method];
if (Data != null && Data != undefined) {
json[1] = Data;
}
let str = JSON.stringify(json);
if (str.length > 65535) {
this.AddLog("要傳的資料太大囉");
throw new Error('要傳的資料太大囉');
}
if (Data != null && Data != undefined) {
this.AddLog(`[RPC] 傳送server資料: ${Method}(${JSON.stringify(Data).replace(/\\/g, "")})`);
} else {
this.AddLog(`[RPC] 傳送server資料: ${Method}()`);
}
let strary = this.GetBytes(str);
let buffer = new Uint8Array(4 + strary.byteLength);
let u16ary = new Uint16Array(buffer.buffer, 0, 3);
u16ary[0] = strary.byteLength;
buffer[3] = 0x01;
buffer.set(strary, 4);
this._ws.send(buffer);
}
public ResData(Status: any, Method: any, Data: any = null) {
// let document = parent ? parent.document : document;
switch (Method) {
case "account.login": {
this.SendData("rank.info", { "t": 12, "p": 2 });
break;
}
case "rank.info": {
this.RankMagnificationDataCallBack(Data);
break;
}
case "rank.history": {
this.ParseRankMagnificationData(Data);
break;
}
default:
break;
}
}
public async RankMagnificationDataCallBack(data: any) { public async RankMagnificationDataCallBack(data: any) {
let id = +data["id"]; let id: number = +data["id"];
this._nowSearchMagnificationID = id; this._nowSearchMagnificationID = id;
this._nowContestID = id; this._nowContestID = id;
this._nowContestDate = moment().format("MM/DD"); this._nowContestDate = moment().format("MM/DD");
for (let i = 0; i < this.ContestData.length; i++) { for (let i: number = 0; i < this.ContestData.length; i++) {
const contest: string = this.ContestData[i]; const contest: string = this.ContestData[i];
let str = contest.split("~"); let str: string[] = contest.split("~");
let my = moment(this._nowContestDate); let my: moment.Moment = this._getMomentFormString(this._nowContestDate);
let start = moment(str[0]); let start: moment.Moment = this._getMomentFormString(str[0]);
let end = moment(str[1]); let end: moment.Moment = this._getMomentFormString(str[1]);
let diff: number = my.diff(end, "days"); let diff: number = my.diff(end, "day");
if (diff < 0) { if (diff < 0) {
this._nowContestIndex = i; this._nowContestIndex = i;
this._nowContestStart = moment(start).format("MM/DD"); this._nowContestStart = moment(start).format("MM/DD");
@ -409,16 +315,16 @@ export class BJ_Casino_Data {
//#region Get //#region Get
private _contestIDFormDate(date: string): number { private _contestIDFormDate(date: string): number {
let my = moment(this._nowContestDate); let my = this._getMomentFormString(this._nowContestDate);
let target = moment(date); let target = this._getMomentFormString(date);
let diffday: number = my.diff(target, "days"); let diffday: number = my.diff(target, "day");
let id = this._nowContestID - diffday; let id = this._nowContestID - diffday;
if (id < 0) { if (id < 0) {
return 0; return 0;
} else { } else {
return id; return id;
} }
}; }
private _contestDateFormID(id: number): string { private _contestDateFormID(id: number): string {
let my: number = this._nowContestID; let my: number = this._nowContestID;
@ -427,9 +333,20 @@ export class BJ_Casino_Data {
if (diffid < 0) { if (diffid < 0) {
diffid = 0; diffid = 0;
} }
let date: string = moment().subtract(diffid, "days").format("MM/DD"); let date: string = moment().subtract(diffid, "day").format("MM/DD");
return date; return date;
}; }
private _getMomentFormString(str: string): moment.Moment {
let data: string[] = str.split("/");
let m: number = +data[0] - 1;
let d: number = +data[1];
let date: Date = new Date();
date.setMonth(m);
date.setDate(d);
let mymoment: moment.Moment = moment(date);
return mymoment;
}
//#endregion //#endregion
@ -472,68 +389,6 @@ export class BJ_Casino_Data {
return Arr; return Arr;
} }
//#endregion
//#region WebSocke
public OnWebSocketMessage(e: any) {
let self: this = this;
if (e.data instanceof ArrayBuffer) {
this.ParseRpcMessage(e.data);
} else if (e.data instanceof Blob) {
let reader = new FileReader();
reader.onload = (e) => {
self.ParseRpcMessage(reader.result); reader.onload = null;
}
reader.readAsArrayBuffer(e.data);
} else {
this.AddLog(`未知的OnWebSocketMessage(e.data)類型: ${e.data}`);
throw new Error(`未知的OnWebSocketMessage(e.data)類型: ${e.data}`);
}
}
public ParseRpcMessage(buffer: any) {
let startIndex = 0, byteLength = buffer.byteLength;
while (startIndex + 4 < byteLength) {
let strlen = new DataView(buffer, startIndex, 3).getUint16(0, true);
let str = this.GetString(new Uint8Array(buffer, startIndex + 4, strlen));
startIndex += strlen + 4;
try {
let json = JSON.parse(str);
let method = json[0];
let status = json[1][0];
let data = json[1][1];
let resp = {
Method: method,
Status: status,
Data: data,
IsValid: method && status === 0
};
if (data) {
this.AddLog(`[RPC] 收到server呼叫:(${resp.Status}): ${resp.Method}(${JSON.stringify(resp.Data)})`);
this.ResData(resp.Status, resp.Method, resp.Data);
} else {
this.AddLog(`[RPC] 收到server呼叫:(${resp.Status}): ${resp.Method}()`);
this.ResData(resp.Status, resp.Method);
}
}
catch
{
this.AddLog(`[RPC] 無法解析Server回應: ${str}`);
throw new Error(`[RPC] 無法解析Server回應: ${str}`);
}
}
}
public seestate() {
// alert(ws.readyState);
this.AddLog(this._ws.readyState);
}
public Sleep(ms: number) { public Sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms)); return new Promise(resolve => setTimeout(resolve, ms));
} }
@ -545,70 +400,5 @@ export class BJ_Casino_Data {
// textarea.scrollTop = textarea.scrollHeight; // textarea.scrollTop = textarea.scrollHeight;
} }
public GetBytes(str: any) {
let len = str.length, resPos = -1;
let resArr = new Uint8Array(len * 3);
for (let point = 0, nextcode = 0, i = 0; i !== len;) {
point = str.charCodeAt(i), i += 1;
if (point >= 0xD800 && point <= 0xDBFF) {
if (i === len) {
resArr[resPos += 1] = 0xef;
resArr[resPos += 1] = 0xbf;
resArr[resPos += 1] = 0xbd;
break;
}
nextcode = str.charCodeAt(i);
if (nextcode >= 0xDC00 && nextcode <= 0xDFFF) {
point = (point - 0xD800) * 0x400 + nextcode - 0xDC00 + 0x10000;
i += 1;
if (point > 0xffff) {
resArr[resPos += 1] = (0x1e << 3) | (point >>> 18);
resArr[resPos += 1] = (0x2 << 6) | ((point >>> 12) & 0x3f);
resArr[resPos += 1] = (0x2 << 6) | ((point >>> 6) & 0x3f);
resArr[resPos += 1] = (0x2 << 6) | (point & 0x3f);
continue;
}
} else {
resArr[resPos += 1] = 0xef;
resArr[resPos += 1] = 0xbf;
resArr[resPos += 1] = 0xbd;
continue;
}
}
if (point <= 0x007f) {
resArr[resPos += 1] = (0x0 << 7) | point;
} else if (point <= 0x07ff) {
resArr[resPos += 1] = (0x6 << 5) | (point >>> 6);
resArr[resPos += 1] = (0x2 << 6) | (point & 0x3f);
} else {
resArr[resPos += 1] = (0xe << 4) | (point >>> 12);
resArr[resPos += 1] = (0x2 << 6) | ((point >>> 6) & 0x3f);
resArr[resPos += 1] = (0x2 << 6) | (point & 0x3f);
}
}
return resArr.subarray(0, resPos + 1);
}
public GetString(array: any) {
let str = "";
let i = 0, len = array.length;
while (i < len) {
let c = array[i++];
switch (c >> 4) {
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
str += String.fromCharCode(c);
break;
case 12: case 13:
str += String.fromCharCode(((c & 0x1F) << 6) | (array[i++] & 0x3F));
break;
case 14:
str += String.fromCharCode(((c & 0x0F) << 12) | ((array[i++] & 0x3F) << 6) | ((array[i++] & 0x3F) << 0));
break;
}
}
return str;
}
//#endregion //#endregion
} }