mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-12 09:18:14 +08:00
✨ 完成天赋数据获取 & 数据合并
This commit is contained in:
@@ -5,11 +5,17 @@
|
|||||||
<div class="uc-top-title">
|
<div class="uc-top-title">
|
||||||
{{ user.nickname }} UID:{{ user.gameUid }} 更新于 {{ getUpdateTime() }}
|
{{ user.nickname }} UID:{{ user.gameUid }} 更新于 {{ getUpdateTime() }}
|
||||||
</div>
|
</div>
|
||||||
<v-btn variant="outlined" class="uc-top-btn" @click="refresh()">
|
<v-btn variant="outlined" class="uc-top-btn" @click="refreshRoles()">
|
||||||
<template #prepend>
|
<template #prepend>
|
||||||
<v-icon>mdi-refresh</v-icon>
|
<v-icon>mdi-refresh</v-icon>
|
||||||
</template>
|
</template>
|
||||||
更新数据
|
更新角色数据
|
||||||
|
</v-btn>
|
||||||
|
<v-btn variant="outlined" class="uc-top-btn" @click="refreshTalent()">
|
||||||
|
<template #prepend>
|
||||||
|
<v-icon>mdi-refresh</v-icon>
|
||||||
|
</template>
|
||||||
|
更新天赋数据
|
||||||
</v-btn>
|
</v-btn>
|
||||||
<v-btn variant="outlined" class="uc-top-btn" @click="shareRoles()">
|
<v-btn variant="outlined" class="uc-top-btn" @click="shareRoles()">
|
||||||
<template #prepend>
|
<template #prepend>
|
||||||
@@ -66,12 +72,12 @@ onMounted(async () => {
|
|||||||
loadingTitle.value = "正在获取角色数据";
|
loadingTitle.value = "正在获取角色数据";
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
await loadRole();
|
await loadRole();
|
||||||
resizeObserve.observe(document.querySelector(".uc-grid"));
|
resizeObserve.observe(<Element>document.querySelector(".uc-grid"));
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
function getGridGap() {
|
function getGridGap() {
|
||||||
const width = document.querySelector(".uc-grid")?.clientWidth - 20;
|
const width = <number>document.querySelector(".uc-grid")?.clientWidth - 20;
|
||||||
const count = Math.floor(width / 180);
|
const count = Math.floor(width / 180);
|
||||||
gridGap.value = `${(width - count * 180) / (count - 1)}px`;
|
gridGap.value = `${(width - count * 180) / (count - 1)}px`;
|
||||||
}
|
}
|
||||||
@@ -84,7 +90,7 @@ async function loadRole() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function refresh() {
|
async function refreshRoles() {
|
||||||
loadingTitle.value = "正在获取角色数据";
|
loadingTitle.value = "正在获取角色数据";
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
const res = await TGRequest.User.byLToken.getRoleList(roleCookie.value, user.value);
|
const res = await TGRequest.User.byLToken.getRoleList(roleCookie.value, user.value);
|
||||||
@@ -97,6 +103,38 @@ async function refresh() {
|
|||||||
loading.value = false;
|
loading.value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function refreshTalent() {
|
||||||
|
loadingTitle.value = "正在获取天赋数据";
|
||||||
|
loading.value = true;
|
||||||
|
await Promise.allSettled(
|
||||||
|
roleList.value.map(async (role) => {
|
||||||
|
const res = await TGRequest.User.calculate.getSyncAvatarDetail(
|
||||||
|
roleCookie.value,
|
||||||
|
user.value.gameUid,
|
||||||
|
role.cid,
|
||||||
|
);
|
||||||
|
if (!Object.hasOwnProperty("retcode")) {
|
||||||
|
const talent: TGApp.Sqlite.Character.RoleTalent[] = [];
|
||||||
|
const avatar = <TGApp.Game.Calculate.AvatarDetail>res;
|
||||||
|
avatar.skill_list.map((skill, index) => {
|
||||||
|
return talent.push({
|
||||||
|
id: skill.id,
|
||||||
|
pos: index,
|
||||||
|
level: skill.level_current,
|
||||||
|
max: skill.max_level,
|
||||||
|
name: skill.name,
|
||||||
|
icon: skill.icon,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return await TGSqlite.saveUserCharacterTalent(user.value.gameUid, role.cid, talent);
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
loadingTitle.value = "正在更新天赋数据";
|
||||||
|
await loadRole();
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
|
||||||
async function shareRoles() {
|
async function shareRoles() {
|
||||||
const rolesBox = document.querySelector(".uc-box") as HTMLElement;
|
const rolesBox = document.querySelector(".uc-box") as HTMLElement;
|
||||||
const fileName = `【角色列表】-${user.value.gameUid}`;
|
const fileName = `【角色列表】-${user.value.gameUid}`;
|
||||||
@@ -116,6 +154,7 @@ function getUpdateTime() {
|
|||||||
|
|
||||||
function selectRole(role: TGApp.Sqlite.Character.UserRole) {
|
function selectRole(role: TGApp.Sqlite.Character.UserRole) {
|
||||||
dataVal.value = role;
|
dataVal.value = role;
|
||||||
|
console.log(dataVal.value);
|
||||||
visible.value = true;
|
visible.value = true;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
* @file plugins Sqlite index.ts
|
* @file plugins Sqlite index.ts
|
||||||
* @description Sqlite 数据库操作类
|
* @description Sqlite 数据库操作类
|
||||||
* @author BTMuli<bt-muli@outlook.com>
|
* @author BTMuli<bt-muli@outlook.com>
|
||||||
* @since Alpha v0.2.0
|
* @since Alpha v0.2.1
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// tauri
|
// tauri
|
||||||
@@ -433,6 +433,27 @@ class Sqlite {
|
|||||||
await db.close();
|
await db.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 保存用户角色天赋数据
|
||||||
|
* @since Alpha v0.2.1
|
||||||
|
* @param {string} uid 用户 uid
|
||||||
|
* @param {number} cid 角色 ID
|
||||||
|
* @param {TGApp.Sqlite.Character.RoleTalent[]} data 角色天赋数据
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
public async saveUserCharacterTalent(
|
||||||
|
uid: string,
|
||||||
|
cid: number,
|
||||||
|
data: TGApp.Sqlite.Character.RoleTalent[],
|
||||||
|
): Promise<void> {
|
||||||
|
const db = await Database.load(this.dbPath);
|
||||||
|
const sql = `UPDATE UserCharacters
|
||||||
|
SET talent = '${JSON.stringify(data)}', updated = datetime('now', 'localtime')
|
||||||
|
WHERE uid = '${uid}' AND cid = ${cid}`;
|
||||||
|
await db.execute(sql);
|
||||||
|
await db.close();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description 获取用户角色数据
|
* @description 获取用户角色数据
|
||||||
* @since Alpha v0.2.0
|
* @since Alpha v0.2.0
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
* @file plugins Sqlite sql insertData.ts
|
* @file plugins Sqlite sql insertData.ts
|
||||||
* @description Sqlite 插入数据 sql 语句
|
* @description Sqlite 插入数据 sql 语句
|
||||||
* @author BTMuli <bt-muli@outlook.com>
|
* @author BTMuli <bt-muli@outlook.com>
|
||||||
* @since Alpha v0.2.0
|
* @since Alpha v0.2.1
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// utils
|
// utils
|
||||||
@@ -237,7 +237,7 @@ export function insertRecordData(data: TGApp.Game.Record.FullData, uid: string):
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @description 插入用户角色数据
|
* @description 插入用户角色数据
|
||||||
* @since Alpha v0.2.0
|
* @since Alpha v0.2.1
|
||||||
* @param {string} uid 用户 UID
|
* @param {string} uid 用户 UID
|
||||||
* @param {TGApp.User.Character.Item[]} data 角色数据
|
* @param {TGApp.User.Character.Item[]} data 角色数据
|
||||||
* @returns {string} sql
|
* @returns {string} sql
|
||||||
@@ -247,10 +247,10 @@ export function insertRoleData(uid: string, data: TGApp.Game.Character.ListItem[
|
|||||||
const role = transUserRoles(item);
|
const role = transUserRoles(item);
|
||||||
return `
|
return `
|
||||||
INSERT INTO UserCharacters (uid, cid, name, img, name, fetter, level, element, star, weapon, reliquary,
|
INSERT INTO UserCharacters (uid, cid, name, img, name, fetter, level, element, star, weapon, reliquary,
|
||||||
constellation, activeConstellation, costume, talent, updated)
|
constellation, activeConstellation, costume, updated)
|
||||||
VALUES (${uid}, ${role.cid}, '${role.name}', '${role.img}', '${role.name}', ${role.fetter}, ${role.level},
|
VALUES (${uid}, ${role.cid}, '${role.name}', '${role.img}', '${role.name}', ${role.fetter}, ${role.level},
|
||||||
'${role.element}', ${role.star}, '${role.weapon}', '${role.reliquary}', '${role.constellation}',
|
'${role.element}', ${role.star}, '${role.weapon}', '${role.reliquary}', '${role.constellation}',
|
||||||
${role.activeConstellation}, '${role.costume}', '${role.talent}', datetime('now', 'localtime'))
|
${role.activeConstellation}, '${role.costume}', datetime('now', 'localtime'))
|
||||||
ON CONFLICT(uid, cid) DO UPDATE
|
ON CONFLICT(uid, cid) DO UPDATE
|
||||||
SET name = '${role.name}',
|
SET name = '${role.name}',
|
||||||
img = '${role.img}',
|
img = '${role.img}',
|
||||||
@@ -264,7 +264,6 @@ export function insertRoleData(uid: string, data: TGApp.Game.Character.ListItem[
|
|||||||
constellation = '${role.constellation}',
|
constellation = '${role.constellation}',
|
||||||
activeConstellation = ${role.activeConstellation},
|
activeConstellation = ${role.activeConstellation},
|
||||||
costume = '${role.costume}',
|
costume = '${role.costume}',
|
||||||
talent = '${role.talent}',
|
|
||||||
updated = datetime('now', 'localtime');
|
updated = datetime('now', 'localtime');
|
||||||
`;
|
`;
|
||||||
});
|
});
|
||||||
|
|||||||
25
src/types/Sqlite/Character.d.ts
vendored
25
src/types/Sqlite/Character.d.ts
vendored
@@ -35,7 +35,7 @@ declare namespace TGApp.Sqlite.Character {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @description 用户角色列表的角色类型
|
* @description 用户角色列表的角色类型
|
||||||
* @since Alpha v0.2.0
|
* @since Alpha v0.2.1
|
||||||
* @interface UserRole
|
* @interface UserRole
|
||||||
* @property {number} uid- 用户 ID
|
* @property {number} uid- 用户 ID
|
||||||
* @property {number} cid - 角色 ID
|
* @property {number} cid - 角色 ID
|
||||||
@@ -50,7 +50,7 @@ declare namespace TGApp.Sqlite.Character {
|
|||||||
* @property {RoleConstellation[]} constellation - 角色命座 // 数据库中以字符串形式存储
|
* @property {RoleConstellation[]} constellation - 角色命座 // 数据库中以字符串形式存储
|
||||||
* @property {number} activeConstellation - 角色激活命座
|
* @property {number} activeConstellation - 角色激活命座
|
||||||
* @property {RoleCostume} costume - 角色时装 // 数据库中以字符串形式存储
|
* @property {RoleCostume} costume - 角色时装 // 数据库中以字符串形式存储
|
||||||
* @property {string} talent - 角色天赋 // TODO: 天赋数据缺失来源
|
* @property {RoleTalent[]} talent - 角色天赋 // 数据库中以字符串形式存储
|
||||||
* @property {string} updated - 数据更新时间
|
* @property {string} updated - 数据更新时间
|
||||||
* @return UserRole
|
* @return UserRole
|
||||||
*/
|
*/
|
||||||
@@ -167,4 +167,25 @@ declare namespace TGApp.Sqlite.Character {
|
|||||||
name: string;
|
name: string;
|
||||||
icon: string;
|
icon: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 角色列表的天赋数据类型
|
||||||
|
* @since Alpha v0.2.1
|
||||||
|
* @interface RoleTalent
|
||||||
|
* @property {number} id - 天赋 ID
|
||||||
|
* @property {number} pos - 天赋位置
|
||||||
|
* @property {string} name - 天赋名称
|
||||||
|
* @property {string} icon - 天赋图标
|
||||||
|
* @property {number} max - 天赋最大等级
|
||||||
|
* @property {number} level - 天赋等级
|
||||||
|
* @return RoleTalent
|
||||||
|
*/
|
||||||
|
export interface RoleTalent {
|
||||||
|
id: number;
|
||||||
|
pos: number;
|
||||||
|
name: string;
|
||||||
|
icon: string;
|
||||||
|
max: number;
|
||||||
|
level: number;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import TGUtils from "../utils/TGUtils";
|
|||||||
/**
|
/**
|
||||||
* @description 通过 Cookie 获取用户角色列表
|
* @description 通过 Cookie 获取用户角色列表
|
||||||
* @since Alpha v0.2.0
|
* @since Alpha v0.2.0
|
||||||
* @param {Record<string, string>} cookie Cookie
|
* @param {TGApp.BBS.Constant.CookieGroup4} cookie Cookie
|
||||||
* @param {TGApp.Sqlite.Account.Game} account 游戏账号
|
* @param {TGApp.Sqlite.Account.Game} account 游戏账号
|
||||||
* @returns {Promise<TGApp.Game.Character.ListItem[]|TGApp.BBS.Response.Base>} 用户角色列表
|
* @returns {Promise<TGApp.Game.Character.ListItem[]|TGApp.BBS.Response.Base>} 用户角色列表
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -15,26 +15,30 @@ import TGUtils from "../utils/TGUtils";
|
|||||||
/**
|
/**
|
||||||
* @description 获取同步角色详情
|
* @description 获取同步角色详情
|
||||||
* @since Alpha v0.2.1
|
* @since Alpha v0.2.1
|
||||||
* @param {Record<string, string>} cookie cookie
|
* @param {TGApp.BBS.Constant.CookieGroup2} cookie cookie
|
||||||
* @param {string} uid 用户 uid
|
* @param {string} uid 用户 uid
|
||||||
* @param {string} avatarId 角色 id
|
* @param {number} avatarId 角色 id
|
||||||
* @returns {Promise<TGApp.Game.Calculate.AvatarDetail|TGApp.BBS.Response.Base>}
|
* @returns {Promise<TGApp.Game.Calculate.AvatarDetail|TGApp.BBS.Response.Base>}
|
||||||
*/
|
*/
|
||||||
async function getSyncAvatarDetail(
|
async function getSyncAvatarDetail(
|
||||||
cookie: Record<string, string>,
|
cookie: TGApp.BBS.Constant.CookieGroup2,
|
||||||
uid: string,
|
uid: string,
|
||||||
avatarId: string,
|
avatarId: number,
|
||||||
): Promise<TGApp.Game.Calculate.AvatarDetail | TGApp.BBS.Response.Base> {
|
): Promise<TGApp.Game.Calculate.AvatarDetail | TGApp.BBS.Response.Base> {
|
||||||
const url = TGApi.GameData.calculate.getSyncAvatarDetail;
|
const url = TGApi.GameData.calculate.getSyncAvatarDetail;
|
||||||
const params = {
|
const params = {
|
||||||
uid,
|
uid,
|
||||||
region: TGUtils.Tools.getServerByUid(uid),
|
region: TGUtils.Tools.getServerByUid(uid),
|
||||||
avatar_id: avatarId,
|
avatar_id: avatarId.toString(),
|
||||||
|
};
|
||||||
|
const ck: Record<string, string> = {
|
||||||
|
account_id: cookie.account_id,
|
||||||
|
cookie_token: cookie.cookie_token,
|
||||||
};
|
};
|
||||||
const header = {
|
const header = {
|
||||||
"User-Agent": "Tauri.Genshin/0.2.1",
|
"User-Agent": "Tauri.Genshin/0.2.1",
|
||||||
Referer: "https://webstatic.mihoyo.com/",
|
Referer: "https://webstatic.mihoyo.com/",
|
||||||
Cookie: TGUtils.Tools.transCookie(cookie),
|
Cookie: TGUtils.Tools.transCookie(ck),
|
||||||
};
|
};
|
||||||
return await http
|
return await http
|
||||||
.fetch<TGApp.Game.Calculate.SyncAvatarDetailResponse | TGApp.BBS.Response.Base>(url, {
|
.fetch<TGApp.Game.Calculate.SyncAvatarDetailResponse | TGApp.BBS.Response.Base>(url, {
|
||||||
|
|||||||
Reference in New Issue
Block a user