Skip to content

Commit 6986349

Browse files
committed
Merge branch 'dev'
# Conflicts: # package.json
2 parents 43a78ae + 4562c75 commit 6986349

File tree

7 files changed

+74
-40
lines changed

7 files changed

+74
-40
lines changed

electron/lcu/lcuRequest.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,16 @@ import { memoize } from "lodash";
2121
import { LRUCache } from "lru-cache";
2222
import { RankSummary } from "../types/rankType";
2323

24-
const httpRequest = async <T>(option: HttpRequestOptions<any>) => {
24+
const httpRequest = async <T>(option: HttpRequestOptions<any>, errMsg?: string) => {
2525
const response = await createHttp1Request(option, getCredentials());
2626
if (response.ok) {
2727
return (response.text() ? (response.json() as T) : null) as T;
2828
} else {
29-
throw new Error((response.json() as RPC).message);
29+
if (errMsg) {
30+
throw new Error(errMsg);
31+
} else {
32+
throw new Error((response.json() as RPC).message);
33+
}
3034
}
3135
};
3236

@@ -49,7 +53,7 @@ export async function getSummonerByName(nickname: string) {
4953
);
5054
if (response.ok) {
5155
return response.json() as SummonerInfo;
52-
} else if (response.status === 404) {
56+
} else if (response.status === 404 || response.status === 422) {
5357
throw new Error("找不到该召唤师: " + nickname);
5458
} else {
5559
throw new Error((response.json() as RPC).message);
@@ -238,18 +242,18 @@ export const getOPGGRunes = async (champId: number, gameMode: GameMode, position
238242

239243
//接收对局
240244
export const acceptGame = async () => {
241-
return await httpRequest<void>({
242-
method: "POST",
243-
url: `/lol-matchmaking/v1/ready-check/accept`
244-
});
245+
return await httpRequest<void>({
246+
method: "POST",
247+
url: `/lol-matchmaking/v1/ready-check/accept`
248+
});
245249
};
246250

247251
//查询对局接收状态
248252
export const getReadyCheckStatus = async () => {
249-
return await httpRequest<{playerResponse: string}>({
250-
method: "GET",
251-
url: `/lol-matchmaking/v1/ready-check`
252-
});
253+
return await httpRequest<{ playerResponse: string }>({
254+
method: "GET",
255+
url: `/lol-matchmaking/v1/ready-check`
256+
});
253257
};
254258

255259
//再来一局(回到大厅)
@@ -292,8 +296,8 @@ export const getRankSummary = async (puuid: string) => {
292296

293297
//重启界面
294298
export const restartUX = async () => {
295-
return await httpRequest<void>({
296-
method: "POST",
297-
url: "/riotclient/kill-and-restart-ux"
298-
});
299+
return await httpRequest<void>({
300+
method: "POST",
301+
url: "/riotclient/kill-and-restart-ux"
302+
});
299303
};

electron/util/util.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import logger from "../lib/logger";
44
import { RequestOptions } from "http";
55
import { URL } from "node:url";
66
import http from "node:http";
7+
import { exec } from "node:child_process";
78

89
export function showMainWindow(route?: string | { name: string }) {
910
// 获取当前的窗口 目前程序只做一个窗口
@@ -35,15 +36,24 @@ export function getPath(unpackPath: boolean = false) {
3536

3637
export function executeCommand(cmd: string): Promise<string> {
3738
return new Promise((resolve, reject) => {
38-
sudo.exec(cmd, { name: "joi" }, (err, stdout, stderr) => {
39+
exec(cmd, (err, stdout, stderr) => {
3940
if (err) {
4041
reject(err);
41-
} else if (stderr) {
42+
}
43+
if (stderr) {
4244
reject(stderr);
43-
} else {
44-
resolve(stdout?.toString() || "");
4545
}
46+
resolve(stdout);
4647
});
48+
// sudo.exec(cmd, { name: "joi" }, (err, stdout, stderr) => {
49+
// if (err) {
50+
// reject(err);
51+
// } else if (stderr) {
52+
// reject(stderr);
53+
// } else {
54+
// resolve(stdout?.toString() || "");
55+
// }
56+
// });
4757
});
4858
}
4959

@@ -85,7 +95,7 @@ export function makeRequest<T>(options: RequestOptions | string | URL) {
8595
const req = http.request(options, (res) => {
8696
// 检查响应头中的 Content-Type
8797
const contentType = res.headers["content-type"];
88-
const charsetMatch = contentType?.match(/charset=([a-zA-Z0-9-]+)/);
98+
const charsetMatch = contentType?.match(/charset=([a-zA-Z0-9-]+)/);
8999

90100
// 默认编码为 UTF-8
91101
let encoding = "utf-8";

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "joi",
3-
"version": "0.6.2",
3+
"version": "0.6.3",
44
"main": "dist-electron/main.js",
55
"repository": {
66
"type": "git",

src/components/PlayerGameInfo.vue

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import SpellImg from "@/components/img/spellImg.vue";
66
import ItemImg from "@/components/img/itemImg.vue";
77
import { DocumentCopy16Regular } from "@vicons/fluent";
88
import Perks from "@/components/img/Perks.vue";
9+
import { getNameAndTagLine } from "@/utils/util";
910
1011
const props = defineProps<{
1112
info: Participant;
@@ -15,7 +16,8 @@ const { info } = toRefs(props);
1516
1617
const message = useMessage();
1718
18-
function copyName(name: string) {
19+
function copyName(playInfo: Player) {
20+
const name = getNameAndTagLine(playInfo);
1921
navigator.clipboard.writeText(name).then(() => message.success(`昵称[${name}]已复制`));
2022
}
2123
@@ -32,10 +34,7 @@ const emit = defineEmits<{ jumpSummoner: [player: Player] }>();
3234
:level="info?.stats.champLevel"
3335
:champion-id="info?.championId"></champion-img>
3436
</div>
35-
<div
36-
class="relative inline-flex cursor-pointer"
37-
style="width: 8em"
38-
@click="() => copyName(playInfo.player.summonerName)">
37+
<div class="relative inline-flex cursor-pointer" style="width: 8em" @click="() => copyName(playInfo.player)">
3938
<div
4039
style="width: 8em; font-size: 0.8em"
4140
:title="playInfo.player.summonerName"

src/page/HistoryMatch.vue

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { AngleLeft, AngleRight } from "@vicons/fa";
1313
import EpicLoading from "@/components/EpicLoading.vue";
1414
import { PlayerNote } from "@@/types/type";
1515
import playerNotesApi from "@/api/playerNotesApi";
16+
import { getNameAndTagLine } from "@/utils/util";
1617
1718
interface SummonerGameHistoryResult {
1819
summonerInfo: SummonerInfo;
@@ -136,17 +137,23 @@ const fetchData = async ({
136137
console.log("fetchData", { summonerName, puuid });
137138
summonerQueryLoading.value = true;
138139
try {
140+
let summoner: SummonerInfo;
141+
//如果只通过名称查询,就先通过名称判断是否有该召唤师
142+
if (summonerName && !puuid) {
143+
try {
144+
summoner = await lcuApi.getSummonerByName(summonerName!);
145+
puuid = summoner.puuid;
146+
} catch (e) {
147+
console.log(e);
148+
return;
149+
}
150+
}
139151
//判断是否已存在tab
140-
const existIndex = summonerQueryList.value.findIndex(
141-
(s) => s.summonerInfo.displayName === summonerName || s.summonerInfo.puuid === puuid
142-
);
152+
const existIndex = summonerQueryList.value.findIndex((s) => s.summonerInfo.puuid === puuid);
143153
//不存在就查询
144154
if (existIndex === -1) {
145-
let summoner: SummonerInfo;
146155
if (!puuid && !summonerName) {
147156
summoner = await lcuStore.getCurrentSummoner();
148-
} else if (summonerName) {
149-
summoner = await lcuApi.getSummonerByName(summonerName!);
150157
} else {
151158
summoner = await lcuApi.getSummonerByPuuid(puuid!);
152159
}
@@ -240,7 +247,7 @@ watch(
240247
const handleNameOptionsSelect = (key: string) => {
241248
switch (key) {
242249
case "copyName":
243-
copy(currentTabSummoner.value?.displayName, "昵称");
250+
copy(getNameAndTagLine(currentTabSummoner.value), "昵称");
244251
break;
245252
case "copyPuuid":
246253
copy(currentTabSummoner.value?.puuid, "puuid");
@@ -286,14 +293,14 @@ const handleNameOptionsSelect = (key: string) => {
286293
<div class="flex flex-row flex-nowrap items-center gap-[10px] min-h-[50px]">
287294
<div class="flex flex-row items-center" v-if="currentTabSummoner?.displayName">
288295
<div v-if="summonerQueryList[tabIndex]?.playerNote?.tags">
289-
<n-ellipsis style="max-width: 200px" :tooltip="{width:400}">
296+
<n-ellipsis style="max-width: 200px" :tooltip="{ width: 400 }">
290297
<n-tag
291298
:bordered="false"
292299
type="warning"
293300
v-for="tag in summonerQueryList[tabIndex]?.playerNote?.tags"
294301
class="m-1"
295-
>{{ tag }}</n-tag
296-
>
302+
>{{ tag }}
303+
</n-tag>
297304
</n-ellipsis>
298305
</div>
299306

@@ -302,7 +309,7 @@ const handleNameOptionsSelect = (key: string) => {
302309
</n-tag>
303310
<profile-img round class="m-2 shrink-0" :profile-icon-id="currentTabSummoner.profileIconId"></profile-img>
304311
<n-dropdown trigger="click" :options="playerDropDownOptions" @select="handleNameOptionsSelect">
305-
<n-button text class="truncate cursor-pointer" :title="currentTabSummoner.displayName">
312+
<n-button text class="truncate cursor-pointer" :title="getNameAndTagLine(currentTabSummoner)">
306313
{{ currentTabSummoner?.displayName }}
307314
</n-button>
308315
</n-dropdown>

src/utils/gameAnalysis.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export async function analysisTeamUpInfo(teams: TeamMemberInfo[]) {
3838
if (!member.gameDetail?.[0].gameId) {
3939
continue;
4040
}
41-
//按上局游戏id和队伍id进行分组,分组数大于1说明这组玩家可能是组队
41+
//按上局游戏id和队伍id进行分组,分组数大于1说明这组玩家可能是组队
4242
const key = member.gameDetail[0].gameId + "_" + member.gameDetail[0].participants[0].teamId;
4343
if (gameIdMap.has(key)) {
4444
gameIdMap.get(key)!.push(member);
@@ -60,10 +60,13 @@ export function computeScore(gameDetail?: GameDetail[]) {
6060
// KDA->(击杀*1.2+助攻*0.8)/(死亡*1.2) 辅助助攻系数为1.2
6161
// 输赢->赢+1 输-1
6262
const filterResults = gameDetail.filter((detail) => {
63-
//只统计 匹配,单排,大乱斗,组排 还排除重开局
63+
//统计 匹配,单排,大乱斗,组排 排除重开局
6464
return [430, 420, 450, 440].includes(detail.queueId) && detail.gameDuration > 3 * 60;
6565
});
66-
66+
//有效局小于5局不评分
67+
if (filterResults.length < 5) {
68+
return 0;
69+
}
6770
return (
6871
filterResults.reduce((previousValue, detail) => {
6972
const info = detail.participants[0];

src/utils/util.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { isPromise } from "@vue/shared";
22
import { random } from "lodash";
3+
import { Player, SummonerInfo } from "@@/types/lcuType";
34

45
/**
56
* 错误重试包装器
@@ -59,3 +60,13 @@ export const randomTimout = function <T>(
5960
);
6061
});
6162
};
63+
64+
export const getNameAndTagLine = (summoner: SummonerInfo | Player) => {
65+
let name;
66+
if ("summonerName" in summoner) {
67+
name = summoner.gameName || summoner.summonerName;
68+
} else {
69+
name = summoner.gameName || summoner.displayName;
70+
}
71+
return name + (summoner.tagLine ? " #" + summoner.tagLine : "");
72+
};

0 commit comments

Comments
 (0)