Skip to content

Commit

Permalink
🎨 一些优化
Browse files Browse the repository at this point in the history
* 优化公告解析逻辑
* 咨讯页loading显示版块名称
* 移除无用文件
  • Loading branch information
BTMuli committed Nov 16, 2024
1 parent 2f60e12 commit 680a54a
Show file tree
Hide file tree
Showing 23 changed files with 62 additions and 139 deletions.
5 changes: 1 addition & 4 deletions eslint/vueEslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ const tsConfigRules = {
"@typescript-eslint/no-import-type-side-effects": "error",
"@typescript-eslint/strict-boolean-expressions": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-expressions": [
"error",
{ allowShortCircuit: false },
],
"@typescript-eslint/no-unused-expressions": ["error", { allowShortCircuit: false }],
"import/order": [
"error",
{
Expand Down
4 changes: 2 additions & 2 deletions src/pages/common/Announcements.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ import { useAppStore } from "../../store/modules/app.js";
import TGLogger from "../../utils/TGLogger.js";
import { AnnoLang, AnnoServer } from "../../web/request/getAnno.js";
import TGRequest from "../../web/request/TGRequest.js";
import TGUtils from "../../web/utils/TGUtils.js";
import { getAnnoCard } from "../../web/utils/getAnnoCard.js";
import { decodeRegExp } from "../../web/utils/tools.js";
type AnnoSelect = { text: string; value: string };
Expand Down Expand Up @@ -145,7 +145,7 @@ async function loadData(): Promise<void> {
`服务器:${getRegionName(curRegion.value)},语言:${getLangName(curLang.value)}`,
);
const annoData = await TGRequest.Anno.getList(curRegion.value, curLang.value);
const listCards = TGUtils.Anno.getCard(annoData);
const listCards = getAnnoCard(annoData);
await Promise.all(
listCards.map(async (item) => {
if (item.typeLabel === AnnoType.game) return;
Expand Down
8 changes: 5 additions & 3 deletions src/pages/common/News.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import Mys from "../../plugins/Mys/index.js";
import { useAppStore } from "../../store/modules/app.js";
import TGLogger from "../../utils/TGLogger.js";
import { createPost } from "../../utils/TGWindow.js";
import { getGameName } from "../../web/utils/tools.js";
// 类型定义
enum NewsType {
Expand All @@ -92,6 +93,7 @@ type RawData = {
// 路由
const router = useRouter();
const gid = <string>useRoute().params.gid;
const gameName = getGameName(Number(gid));
// loading
const loading = ref<boolean>(false);
Expand Down Expand Up @@ -146,12 +148,12 @@ async function firstLoad(key: NewsKey, refresh: boolean = false): Promise<void>
postData.value[key] = [];
rawData.value[key].lastId = 0;
}
showLoading.start(`正在获取${rawData.value[key].name}数据...`);
showLoading.start(`正在获取${gameName}${rawData.value[key].name}数据...`);
const getData = await Mys.Painter.getNewsList(gid, NewsType[key]);
rawData.value[key].isLast = getData.is_last;
rawData.value[key].lastId = getData.list.length;
postData.value[key] = getData.list;
showLoading.update(`正在渲染${rawData.value[key].name}数据...`);
showLoading.update(`正在渲染${gameName}${rawData.value[key].name}数据...`);
await nextTick(() => showLoading.end());
await TGLogger.Info(`[News][${gid}][firstLoad] 获取${rawData.value[key].name}数据成功`);
}
Expand All @@ -169,7 +171,7 @@ async function loadMore(key: NewsKey): Promise<void> {
loading.value = false;
return;
}
showLoading.start(`正在获取${rawData.value[key].name}数据...`);
showLoading.start(`正在获取${gameName}${rawData.value[key].name}数据...`);
const getData = await Mys.Painter.getNewsList(gid, NewsType[key], 20, rawData.value[key].lastId);
rawData.value[key].lastId = rawData.value[key].lastId + getData.list.length;
rawData.value[key].isLast = getData.is_last;
Expand Down
3 changes: 2 additions & 1 deletion src/pages/common/PostForum.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import ToPostSearch from "../../components/post/to-postSearch.vue";
import Mys from "../../plugins/Mys/index.js";
import TGLogger from "../../utils/TGLogger.js";
import { createPost } from "../../utils/TGWindow.js";
import { getGameName } from "../../web/utils/tools.js";
type SortSelect = {
text: string;
Expand Down Expand Up @@ -184,9 +185,9 @@ const search = ref<string>("");
const showSearch = ref<boolean>(false);
onMounted(async () => {
showLoading.start("正在获取帖子数据...");
if (gid && typeof gid === "string") curGid.value = Number(gid);
if (forum && typeof forum === "string") curForum.value = Number(forum);
showLoading.start(`正在获取${getGameName(curGid.value)}帖子数据...`);
const gameLabel = getGameLabel(curGid.value);
const forumLabel = getForumLabel(curGid.value, curForum.value);
await TGLogger.Info(`[Posts][${gameLabel}][onMounted][${forumLabel}] 打开帖子列表`);
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/Mys/request/doCaptchaLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export async function getCaptcha(
"user-agent": TGConstant.BBS.UA_MOBILE,
"content-type": "application/json",
referer: "https://user.miyoushe.com/",
"x-rpc-game_biz": TGConstant.Utils.GAME_BIZ,
"x-rpc-game_biz": TGConstant.GAME_BIZ,
};
const resp = await TGHttp<
TGApp.Plugins.Mys.CaptchaLogin.CaptchaResponse | TGApp.BBS.Response.Base
Expand Down
10 changes: 5 additions & 5 deletions src/views/t-anno-json.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</div>
</template>
<script lang="ts" setup>
import { onMounted, reactive } from "vue";
import { onMounted, ref } from "vue";
import JsonViewer from "vue-json-viewer";
import { useRoute } from "vue-router";
Expand All @@ -22,8 +22,8 @@ const route = useRoute();
const annoId = Number(route.params.anno_id);
const region = <AnnoServer>route.params.region;
const lang = <AnnoLang>route.params.lang;
let jsonList = reactive({});
let jsonContent = reactive({});
const jsonList = ref<TGApp.BBS.Announcement.AnnoSingle>();
const jsonContent = ref<TGApp.BBS.Announcement.ContentItem>();
onMounted(async () => {
showLoading.start("正在获取公告数据...");
Expand All @@ -35,10 +35,10 @@ onMounted(async () => {
const listData = await TGRequest.Anno.getList();
listData.list.map((item: TGApp.BBS.Announcement.ListItem) => {
return item.list.map((single: TGApp.BBS.Announcement.AnnoSingle) => {
return single.ann_id === annoId ? (jsonList = single) : null;
return single.ann_id === annoId ? (jsonList.value = single) : null;
});
});
jsonContent = await TGRequest.Anno.getContent(annoId, region, lang);
jsonContent.value = await TGRequest.Anno.getContent(annoId, region, lang);
showLoading.end();
});
</script>
Expand Down
8 changes: 2 additions & 6 deletions src/web/constant/TGConstant.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @file web/constant/TGConstant.ts
* @description 常量
* @since Beta v0.5.1
* @since Beta v0.6.3
*/

import {
Expand All @@ -12,7 +12,6 @@ import {
BBS_VERSION,
CHANNEL_LIST,
} from "./bbs.js";
import SERVER from "./server.js";
import { GAME_BIZ } from "./utils.js";

const TGConstant = {
Expand All @@ -24,10 +23,7 @@ const TGConstant = {
CHANNELS: CHANNEL_LIST,
},
Salt: BBS_SALT,
Server: SERVER,
Utils: {
GAME_BIZ,
},
GAME_BIZ,
};

export default TGConstant;
32 changes: 0 additions & 32 deletions src/web/constant/server.ts

This file was deleted.

8 changes: 4 additions & 4 deletions src/web/request/genAuthkey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import TGHttp from "../../utils/TGHttp.js";
import TGConstant from "../constant/TGConstant.js";
import TGUtils from "../utils/TGUtils.js";
import { getRequestHeader } from "../utils/getRequestHeader.js";

/**
* @description 生成 authkey
Expand All @@ -23,11 +23,11 @@ export async function genAuthkey(
const ck = { stoken: cookie.stoken, mid: cookie.mid };
const data = {
auth_appid: "webview_gacha",
game_biz: TGConstant.Utils.GAME_BIZ,
game_biz: TGConstant.GAME_BIZ,
game_uid: account.gameUid,
region: account.region,
};
const header = TGUtils.User.getHeader(ck, "POST", JSON.stringify(data), "lk2", true);
const header = getRequestHeader(ck, "POST", JSON.stringify(data), "lk2", true);
const resp = await TGHttp<TGApp.Game.Gacha.AuthkeyResponse | TGApp.BBS.Response.Base>(url, {
method: "POST",
headers: header,
Expand All @@ -49,7 +49,7 @@ export async function genAuthkey2(
payload: Record<string, string>,
): Promise<TGApp.BBS.Response.Base> {
const url = "https://api-takumi.mihoyo.com/binding/api/genAuthKey";
const header = TGUtils.User.getHeader(cookie, "POST", JSON.stringify(payload), "lk2", true);
const header = getRequestHeader(cookie, "POST", JSON.stringify(payload), "lk2", true);
return await TGHttp<TGApp.BBS.Response.Base>(url, {
method: "POST",
headers: header,
Expand Down
4 changes: 2 additions & 2 deletions src/web/request/getAbyss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import TGHttp from "../../utils/TGHttp.js";
import TGApi from "../api/TGApi.js";
import TGUtils from "../utils/TGUtils.js";
import { getRequestHeader } from "../utils/getRequestHeader.js";

/**
* @description 获取深渊信息
Expand All @@ -29,7 +29,7 @@ export async function getAbyss(
ltoken: cookie.ltoken,
ltuid: cookie.ltuid,
};
const header = TGUtils.User.getHeader(ck, "GET", params, "common");
const header = getRequestHeader(ck, "GET", params, "common");
const resp = await TGHttp<TGApp.Game.Abyss.Response | TGApp.BBS.Response.Base>(url, {
method: "GET",
headers: header,
Expand Down
4 changes: 2 additions & 2 deletions src/web/request/getActionTicket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import TGHttp from "../../utils/TGHttp.js";
import TGUtils from "../utils/TGUtils.js";
import { getRequestHeader } from "../utils/getRequestHeader.js";

/**
* @description 通过 stoken 获取 ActionTicket
Expand All @@ -25,7 +25,7 @@ export async function getActionTicketBySToken(
const url = "https://api-takumi.mihoyo.com/auth/api/getActionTicketBySToken";
const params = { action_type: ActionType, stoken: SToken, uid: UID };
const cookie = { mid: MID, stoken: SToken };
const header = TGUtils.User.getHeader(cookie, "GET", params, "k2");
const header = getRequestHeader(cookie, "GET", params, "k2");
return await TGHttp<TGApp.BBS.Response.getActionTicketBySToken>(url, {
method: "GET",
headers: header,
Expand Down
8 changes: 4 additions & 4 deletions src/web/request/getAvatarDetail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import TGHttp from "../../utils/TGHttp.js";
import TGApi from "../api/TGApi.js";
import TGUtils from "../utils/TGUtils.js";
import { getRequestHeader } from "../utils/getRequestHeader.js";

/**
* @description 手动刷新角色数据
Expand All @@ -22,7 +22,7 @@ export async function getAvatarIndex(
const url = TGApi.GameData.getUserBase;
const params = { avatar_list_type: 1, role_id: user.gameUid, server: user.region };
const ck = { cookie_token: cookie.cookie_token, account_id: cookie.account_id };
const header = TGUtils.User.getHeader(ck, "GET", params, "common");
const header = getRequestHeader(ck, "GET", params, "common");
return await TGHttp<TGApp.BBS.Response.Base>(url, {
method: "GET",
headers: header,
Expand All @@ -44,7 +44,7 @@ export async function getAvatarList(
const url = TGApi.GameData.byCookie.getAvatarList;
const data = { role_id: user.gameUid, server: user.region };
const ck = { cookie_token: cookie.cookie_token, account_id: cookie.account_id };
const header = TGUtils.User.getHeader(ck, "POST", data, "common");
const header = getRequestHeader(ck, "POST", data, "common");
const resp = await TGHttp<TGApp.Game.Avatar.ListResponse | TGApp.BBS.Response.Base>(url, {
method: "POST",
body: JSON.stringify(data),
Expand All @@ -70,7 +70,7 @@ export async function getAvatarDetail(
const url = TGApi.GameData.byCookie.getAvatarDetail;
const data = { role_id: user.gameUid, server: user.region, character_ids: avatarIds };
const ck = { cookie_token: cookie.cookie_token, account_id: cookie.account_id };
const header = TGUtils.User.getHeader(ck, "POST", data, "common");
const header = getRequestHeader(ck, "POST", data, "common");
const resp = await TGHttp<TGApp.Game.Avatar.DetailResponse | TGApp.BBS.Response.Base>(url, {
method: "POST",
body: JSON.stringify(data),
Expand Down
4 changes: 2 additions & 2 deletions src/web/request/getCookieToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import TGHttp from "../../utils/TGHttp.js";
import TGApi from "../api/TGApi.js";
import TGUtils from "../utils/TGUtils.js";
import { getRequestHeader } from "../utils/getRequestHeader.js";

/**
* @description 根据 stoken 获取 cookie_token
Expand All @@ -22,7 +22,7 @@ export async function getCookieTokenBySToken(
const url = TGApi.GameTokens.getCookieToken;
const cookie = { mid: Mid, stoken: Stoken };
const params = { stoken: Stoken };
const header = TGUtils.User.getHeader(cookie, "GET", params, "common");
const header = getRequestHeader(cookie, "GET", params, "common");
const resp = await TGHttp<TGApp.BBS.Response.getCookieTokenBySToken | TGApp.BBS.Response.Base>(
url,
{
Expand Down
8 changes: 4 additions & 4 deletions src/web/request/getGameAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import TGHttp from "../../utils/TGHttp.js";
import TGApi from "../api/TGApi.js";
import TGConstant from "../constant/TGConstant.js";
import TGUtils from "../utils/TGUtils.js";
import { getRequestHeader } from "../utils/getRequestHeader.js";

/**
* @description 通过 stoken 获取游戏账号
Expand All @@ -22,7 +22,7 @@ export async function getGameAccountsBySToken(
): Promise<TGApp.BBS.Account.GameAccount[] | TGApp.BBS.Response.Base> {
const url = TGApi.GameData.bySToken.getAccounts;
const cookie = { stuid, stoken };
const params = { stoken, stuid, game_biz: TGConstant.Utils.GAME_BIZ };
const params = { stoken, stuid, game_biz: TGConstant.GAME_BIZ };
return await getGameAccounts(url, cookie, params);
}

Expand All @@ -39,7 +39,7 @@ export async function getGameAccountsByCookie(
): Promise<TGApp.BBS.Account.GameAccount[] | TGApp.BBS.Response.Base> {
const url = TGApi.GameData.byCookie.getAccounts;
const cookie = { account_id, cookie_token };
const params = { game_biz: TGConstant.Utils.GAME_BIZ };
const params = { game_biz: TGConstant.GAME_BIZ };
return await getGameAccounts(url, cookie, params);
}

Expand All @@ -56,7 +56,7 @@ async function getGameAccounts(
cookie: Record<string, string>,
params: Record<string, string>,
): Promise<TGApp.BBS.Response.Base | TGApp.BBS.Account.GameAccount[]> {
const header = TGUtils.User.getHeader(cookie, "GET", params, "common");
const header = getRequestHeader(cookie, "GET", params, "common");
const resp = await TGHttp<TGApp.BBS.Response.getGameAccounts | TGApp.BBS.Response.Base>(url, {
method: "GET",
headers: header,
Expand Down
4 changes: 2 additions & 2 deletions src/web/request/getGameRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import TGHttp from "../../utils/TGHttp.js";
import TGApi from "../api/TGApi.js";
import TGUtils from "../utils/TGUtils.js";
import { getRequestHeader } from "../utils/getRequestHeader.js";

/**
* @description 获取用户游戏数据
Expand All @@ -23,7 +23,7 @@ export async function getGameRecord(
): Promise<TGApp.Game.Record.FullData | TGApp.BBS.Response.Base> {
const url = TGApi.GameData.getUserBase;
const params = { role_id: user.gameUid, server: user.region };
const header = TGUtils.User.getHeader(cookie, "GET", params, "common");
const header = getRequestHeader(cookie, "GET", params, "common");
const resp = await TGHttp<TGApp.Game.Record.Response | TGApp.BBS.Response.Base>(url, {
method: "GET",
headers: header,
Expand Down
4 changes: 2 additions & 2 deletions src/web/request/getLToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import TGHttp from "../../utils/TGHttp.js";
import TGApi from "../api/TGApi.js";
import TGUtils from "../utils/TGUtils.js";
import { getRequestHeader } from "../utils/getRequestHeader.js";

/**
* @description 根据 stoken_v2 获取 ltoken
Expand All @@ -22,7 +22,7 @@ export async function getLTokenBySToken(
const url = TGApi.GameTokens.getLToken;
const cookie = { mid: Mid, stoken: Stoken };
const params = { stoken: Stoken };
const header = TGUtils.User.getHeader(cookie, "GET", params, "common");
const header = getRequestHeader(cookie, "GET", params, "common");
const resp = await TGHttp<TGApp.BBS.Response.getLTokenBySToken | TGApp.BBS.Response.Base>(url, {
method: "GET",
headers: header,
Expand Down
Loading

0 comments on commit 680a54a

Please sign in to comment.