完成角色列表数据获取

This commit is contained in:
BTMuli
2023-05-23 23:59:20 +08:00
parent b8f7b73f05
commit 52a6f87ab0
5 changed files with 311 additions and 2 deletions

View File

@@ -1,7 +1,49 @@
<template>
<h1>角色数据获取展示详情</h1>
<v-btn @click="getRoleList">
获取角色列表
</v-btn>
{{ roleList }}
</template>
<script lang="ts" setup>
// vue
import { onMounted, ref } from "vue";
// store
import { useUserStore } from "../../store/modules/user";
// request
import TGRequest from "../../web/request/TGRequest";
// utils
import TGSqlite from "../../utils/TGSqlite";
const userStore = useUserStore();
const roleList = ref([]);
// data
const characterCookie = ref({
cookie_token: "",
account_id: "",
ltoken: "",
ltuid: "",
});
const user = ref({} as TGApp.Sqlite.Account.Game);
onMounted(async () => {
const curUser = await TGSqlite.getCurAccount();
if (curUser) {
user.value = curUser;
}
characterCookie.value = {
cookie_token: userStore.getCookieItem("cookie_token"),
account_id: userStore.getCookieItem("account_id"),
ltoken: userStore.getCookieItem("ltoken"),
ltuid: userStore.getCookieItem("ltuid"),
};
});
async function getRoleList () {
const res = await TGRequest.User.byLToken.getRoleList(characterCookie.value, user.value);
console.log(res);
}
</script>
<style lang="css" scoped>
</style>

191
src/types/Game/Character.d.ts vendored Normal file
View File

@@ -0,0 +1,191 @@
/**
* @file types Game Character.d.ts
* @description 游戏角色相关类型定义文件
* @todo v0.1.5 不使用
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.2.0
*/
declare namespace TGApp.Game.Character {
/**
* @description 角色列表数据返回类型
* @interface ListResponse
* @since Alpha v0.2.0
* @see todo 请求也得重构一下
* @extends TGApp.BBS.Response.Base
* @property {ListItem[]} data.avatars - 角色列表
* @property {ListRole} data.role - 角色信息
* @return ListResponse
*/
export interface ListResponse extends TGApp.BBS.Response.Base {
data: {
avatars: ListItem[]
role: ListRole
}
}
/**
* @description 角色列表数据类型
* @interface ListItem
* @since Alpha v0.2.0
* @property {number} id - 角色 ID
* @property {string} image - 角色全身像
* @property {string} icon - 角色头像
* @property {string} name - 角色名称
* @property {TGApp.Game.Constant.EnumElementEn} element - 角色元素
* @property {number} fetter - 角色好感等级
* @property {number} level - 角色等级
* @property {number} rarity - 角色稀有度
* @property {LIWeapon} weapon - 角色武器
* @property {LIRelic[]} reliquaries - 角色圣遗物
* @property {LIConstellation[]} constellations - 角色命座
* @property {number} actived_constellation_num - 角色已激活命座数量
* @property {LICostume[]} costumes - 角色时装
* @property {number} constellation_level - 角色命座等级
* @property {unknown} external - todo未知
* @return ListItem
*/
export interface ListItem {
id: number
image: string
icon: string
name: string
element: TGApp.Game.Constant.EnumElementEn
fetter: number
level: number
rarity: number
weapon: LIWeapon
reliquaries: LIReliquary[]
constellations: LIConstellation[]
actived_constellation_num: number
costumes: LICostume[]
constellation_level: number
external: unknown
}
/**
* @description 角色信息
* @interface ListRole
* @since Alpha v0.2.0
* @property {string} AvatarUrl - 角色头像 // 大部分情况下是空的
* @property {string} nickname - 角色昵称
* @property {string} region - 角色所在地区
* @property {number} level - 角色等级
* @return ListRole
*/
export interface ListRole {
AvatarUrl: string
nickname: string
region: string
level: number
}
/**
* @description 角色武器数据类型
* @interface LIWeapon
* @since Alpha v0.2.0
* @property {number} id - 武器 ID
* @property {string} name - 武器名称
* @property {string} icon - 武器图标
* @property {number} type - 武器类型 // todo: 不同的武器类型对应的数值
* @property {number} rarity - 武器稀有度
* @property {number} level - 武器等级
* @property {number} promote_level - 武器等级对应的突破等级
* @property {string} type_name - 武器类型名称
* @property {string} desc - 武器描述
* @property {number} affix_level - 武器精炼等级
* @return LIWeapon
*/
export interface LIWeapon {
id: number
name: string
icon: string
type: number
rarity: number
level: number
promote_level: number
type_name: string
desc: string
affix_level: number
}
/**
* @description 角色圣遗物数据类型
* @interface LIRelic
* @since Alpha v0.2.0
* @property {number} id - 圣遗物 ID
* @property {string} name - 圣遗物名称
* @property {string} icon - 圣遗物图标
* @property {number} pos - 圣遗物位置
* @property {number} rarity - 圣遗物稀有度
* @property {number} level - 圣遗物等级
* @property {RelicSet} set - 圣遗物套装
* @property {TGApp.Game.Constant.EnumRelic} pos_name - 圣遗物位置名称
* @return LIRelic
*/
export interface LIRelic {
id: number
name: string
icon: string
pos: number
rarity: number
level: number
set: RelicSet
pos_name: TGApp.Game.Constant.EnumRelic
}
/**
* @description 圣遗物套装数据类型
* @interface RelicSet
* @since Alpha v0.2.0
* @property {number} id - 圣遗物套装 ID
* @property {string} name - 圣遗物套装名称
* @property {number} affixes[].activation_number - 圣遗物套装激活数量
* @property {string} affixes[].effect - 圣遗物套装效果
* @return RelicSet
*/
export interface RelicSet {
id: number
name: string
affixes: Array<{
activation_number: number
effect: string
}>
}
/**
* @description 角色命座数据类型
* @interface LIConstellation
* @since Alpha v0.2.0
* @property {number} id - 命座 ID
* @property {string} name - 命座名称
* @property {string} icon - 命座图标
* @property {string} effect - 命座效果
* @property {boolean} is_actived - 命座是否激活
* @property {number} pos - 命座位置
* @return LIConstellation
*/
export interface LIConstellation {
id: number
name: string
icon: string
effect: string
is_actived: boolean
pos: number
}
/**
* @description 角色时装数据类型
* @interface LICostume
* @since Alpha v0.2.0
* @property {number} id - 时装 ID
* @property {string} name - 时装名称
* @property {string} icon - 时装图标
* @return LICostume
*/
export interface LICostume {
id: number
name: string
icon: string
}
}

View File

@@ -28,6 +28,28 @@ declare namespace TGApp.Game.Constant {
dendro = "草元素",
}
/**
* @description 七元素-英文
* @since Alpha v0.2.0
* @enum {string}
* @property {string} pyro - 火元素
* @property {string} hydro - 水元素
* @property {string} anemo - 风元素
* @property {string} electro - 雷元素
* @property {string} cryo - 冰元素
* @property {string} geo - 岩元素
* @property {string} dendro - 草元素
*/
export enum EnumElementEn {
pyro = "Pyro",
hydro = "Hydro",
anemo = "Anemo",
electro = "Electro",
cryo = "Cryo",
geo = "Geo",
dendro = "Dendro",
}
/**
* @description 武器类型
* @since Alpha v0.1.5
@@ -45,6 +67,24 @@ declare namespace TGApp.Game.Constant {
bow = "弓",
catalyst = "法器",
}
/**
* @description 圣遗物位置
* @since Alpha v0.2.0
* @enum {string}
* @property {string} flower - 生之花
* @property {string} feather - 死之羽
* @property {string} sands - 时之沙
* @property {string} goblet - 空之杯
* @property {string} circlet - 理之冠
*/
export enum EnumRelic {
flower = "生之花",
feather = "死之羽",
sands = "时之沙",
goblet = "空之杯",
circlet = "理之冠",
}
}
// /**

View File

@@ -2,7 +2,7 @@
* @file web request TGRequest.ts
* @description 应用用到的请求函数
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.2.0
* @since Alpha v0.1.5
*/
import { getAbyss } from "./getAbyss";
@@ -11,7 +11,7 @@ import { getCookieTokenBySToken } from "./getCookieToken";
// import * from "./getEnkaData.ts";
import { getGameAccountsBySToken, getGameAccountsByCookie } from "./getGameAccounts";
import { getLTokenBySToken } from "./getLToken";
// import * from "./getRoleList.ts";
import { getGameRoleListByLToken } from "./getRoleList";
// import * from "./getTickets.ts";
import { getTokensByLoginTicket } from "./getTokens";
import { getUserInfoByCookie } from "./getUserInfo";
@@ -36,6 +36,7 @@ const TGRequest = {
},
byLToken: {
verify: verifyLToken,
getRoleList: getGameRoleListByLToken,
},
bySToken: {
getAccounts: getGameAccountsBySToken,

View File

@@ -0,0 +1,35 @@
/**
* @file web request getRoleList.ts
* @description 获取游戏角色列表的请求方法
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.2.0
*/
// tauri
import { http } from "@tauri-apps/api";
// utils
import TGApi from "../api/TGApi";
import TGUtils from "../utils/TGUtils";
/**
* @description 通过 Cookie 获取用户角色列表
* @since Alpha v0.2.0
* @param {Record<string, string>} cookie Cookie
* @param {TGApp.Sqlite.Account.Game} account 游戏账号
* @returns {Promise<TGApp.Game.Character.ListItem[]|TGApp.BBS.Response.Base>} 用户角色列表
*/
export async function getGameRoleListByLToken (cookie: Record<string, string>, account: TGApp.Sqlite.Account.Game): Promise<TGApp.Game.Character.ListItem[] | TGApp.BBS.Response.Base> {
const url = TGApi.GameData.byCookie.getCharacter;
const uid = account.gameUid;
// eslint-disable-next-line camelcase
const data = { role_id: uid, server: TGUtils.Tools.getServerByUid(uid) };
const header = TGUtils.User.getHeader(cookie, "POST", JSON.stringify(data), "common");
return await http.fetch<TGApp.Game.Character.ListResponse>(url, {
method: "POST",
headers: header,
body: http.Body.json(data),
}).then((res) => {
if (res.data.retcode !== 0) return res.data;
return res.data.data.avatars;
});
}