init
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
import type { IConfig } from '@/stores'
|
||||
import { defineRequest } from '../common'
|
||||
import type { IResult } from './type'
|
||||
export default defineRequest((request) => {
|
||||
return {
|
||||
async calc(config: IConfig) {
|
||||
const res = await request.post<IResult>('/calc', config)
|
||||
return res.data
|
||||
},
|
||||
}
|
||||
})
|
||||
// Compare this snippet from frontend/src/api/common/index.ts:
|
||||
@@ -0,0 +1,56 @@
|
||||
export interface IResult {
|
||||
uuid: string
|
||||
skills: IResultSkill[]
|
||||
info: IResultUserInfo[]
|
||||
suits: {
|
||||
suit?: IResultSuit
|
||||
oath?: IResultSuit
|
||||
correction?: number
|
||||
}
|
||||
buffer: boolean
|
||||
}
|
||||
|
||||
export interface IResultSkill {
|
||||
name: string
|
||||
icon: string
|
||||
lv: number
|
||||
data: number
|
||||
ratio: number
|
||||
cd: number
|
||||
damage: number
|
||||
mode: string
|
||||
buff: number[]
|
||||
learnLv: number
|
||||
type: string
|
||||
}
|
||||
|
||||
export interface IResultUserInfo {
|
||||
id: number
|
||||
name: string
|
||||
value: string | number
|
||||
}
|
||||
|
||||
export interface IResultSuit {
|
||||
id: string
|
||||
count: number
|
||||
imageUrl: string
|
||||
level: number
|
||||
name: string
|
||||
point: number
|
||||
rarity: string
|
||||
value: string
|
||||
suitId: string
|
||||
skills: {
|
||||
id: string
|
||||
skillId: string
|
||||
name: string
|
||||
imageUrl: string
|
||||
enable: boolean
|
||||
}[]
|
||||
}
|
||||
|
||||
export interface IResultSkillCount {
|
||||
count: number
|
||||
mode: string
|
||||
name: string
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
import type { AxiosInstance, AxiosResponse } from 'axios'
|
||||
import axios from 'axios'
|
||||
import { h } from 'vue'
|
||||
import { ungzip } from 'pako'
|
||||
import { useInfoStore } from '@/stores'
|
||||
import { useDialog } from '@/components/hooks/dialog'
|
||||
// import { useAppStore, useConfigStore } from '@/store'
|
||||
// import { useDialog } from '@/components/hooks/dialog'
|
||||
|
||||
export interface HttpResponse<T = unknown> extends AxiosResponse {
|
||||
code?: number
|
||||
message: string
|
||||
data: T
|
||||
state?: number
|
||||
}
|
||||
|
||||
let instance: AxiosInstance | null = null
|
||||
|
||||
let baseURL = '/api'
|
||||
|
||||
// 避免远程开发的时候冲突
|
||||
if (process.env.NODE_ENV == 'development') {
|
||||
baseURL = '/api'
|
||||
}
|
||||
|
||||
if (import.meta.env.MODE == 'web' || import.meta.env.MODE == 'show') {
|
||||
baseURL = 'https://api.dnftools.com/'
|
||||
}
|
||||
|
||||
if (import.meta.env.MODE == 'test') {
|
||||
baseURL = 'https://testapi.dnftools.com/'
|
||||
}
|
||||
|
||||
// 解压
|
||||
function unzip(key: string) {
|
||||
// 将二进制字符串转换为字符数组
|
||||
|
||||
const charData = key.split('').map((x) => {
|
||||
return x?.charCodeAt(0)
|
||||
})
|
||||
|
||||
// 将数字数组转换成字节数组
|
||||
const binData = new Uint8Array(charData)
|
||||
|
||||
// 解压
|
||||
const data = ungzip(binData)
|
||||
|
||||
const decoder = new TextDecoder()
|
||||
const str = decoder.decode(data)
|
||||
|
||||
// unescape(str) --->解压后解码,防止中午乱码
|
||||
return str
|
||||
}
|
||||
|
||||
export function defineRequest<T>(fn: (ax: AxiosInstance) => T) {
|
||||
if (!instance) {
|
||||
instance = axios.create({
|
||||
baseURL,
|
||||
})
|
||||
|
||||
instance.interceptors.request.use(
|
||||
(request) => {
|
||||
// const configStore = useConfigStore()
|
||||
// const token = configStore.token
|
||||
// const uid = useAppStore().uid
|
||||
|
||||
const token = useInfoStore().alter_token
|
||||
|
||||
if (token) {
|
||||
request.headers['Alter-Token'] = token
|
||||
}
|
||||
|
||||
return request
|
||||
},
|
||||
(error) => {
|
||||
// do something
|
||||
return Promise.reject(error)
|
||||
},
|
||||
)
|
||||
|
||||
instance.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8'
|
||||
// instance.defaults.headers["Accept-Encoding"] = "gzip"
|
||||
// instance.defaults.headers["Content-Encoding"] = "gzip"
|
||||
// add response interceptors
|
||||
instance.interceptors.response.use(
|
||||
async (response: AxiosResponse<HttpResponse>) => {
|
||||
if (response.data.code === 500) {
|
||||
const { alert } = useDialog()
|
||||
await alert({
|
||||
content: () => {
|
||||
return h(
|
||||
'div',
|
||||
{
|
||||
class: 'justify-center text-#d4d6b6 text-center',
|
||||
style: 'white-space:pre-wrap;width:250px;margin:10px',
|
||||
},
|
||||
`出现错误,可加群反馈:183439472\n${response.data.message}`,
|
||||
)
|
||||
},
|
||||
})
|
||||
}
|
||||
// 解密数据
|
||||
if (typeof response.data.data == 'string') {
|
||||
try {
|
||||
const data = unzip(atob(response.data.data as string))
|
||||
response.data.data = JSON.parse(data)
|
||||
} catch {}
|
||||
}
|
||||
return response.data
|
||||
},
|
||||
async (error: Error) => {
|
||||
return Promise.reject(error)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
return fn(Object.create(instance))
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import info from './info'
|
||||
import calc from './calc'
|
||||
|
||||
export default { ...info, ...calc }
|
||||
@@ -0,0 +1,48 @@
|
||||
import { defineRequest } from '../common'
|
||||
import type { IAdventureInfo, IAlterInfo, ICharacterInfo, IHelperInfo, ISkillInfo } from './type'
|
||||
|
||||
export default defineRequest((request) => {
|
||||
return {
|
||||
async adventures() {
|
||||
const res = await request.get<IAdventureInfo[]>('/adventure')
|
||||
return res.data
|
||||
},
|
||||
async alterByName(name: string) {
|
||||
const res = await request.get<IAlterInfo>('/adventure', { params: { name } })
|
||||
return res.data
|
||||
},
|
||||
async createToken(alter: string, equVersion?: string) {
|
||||
const res = await request.get<string>(`/token/get/${alter}`, { params: { equVersion } })
|
||||
return res.data
|
||||
},
|
||||
async characterInfo() {
|
||||
const res = await request.get<ICharacterInfo>('/character')
|
||||
return res.data
|
||||
},
|
||||
async skillDetail(skillId: string, level: number) {
|
||||
const res = await request.get<ISkillInfo>(`/skill/${skillId}/${level}`)
|
||||
return res.data
|
||||
},
|
||||
async getConfigFromHelper(uid: string) {
|
||||
const res = await request.get(`/dnfhelper/${uid}/`)
|
||||
return res.data
|
||||
},
|
||||
async getConfigFromHelperAlter(uid: string, alter: string) {
|
||||
const res = await request.get(`/dnfhelper/${uid}/${alter}/`)
|
||||
return res.data
|
||||
},
|
||||
async getSkillFromCode(code: string) {
|
||||
const res = await request.post(`/skillTree/`, { code })
|
||||
return res.data
|
||||
},
|
||||
async getOathInfo(suitId: string, skillId: string, rarity: string, lv: number) {
|
||||
const res = await request.get(`/info/oath/${suitId}/${skillId}`, { params: { rarity, lv } })
|
||||
return res.data
|
||||
},
|
||||
async getHelperList(id: string) {
|
||||
const res = await request.get<IHelperInfo>(`/dnfhelper/${id}/list`)
|
||||
await new Promise((resolve) => setTimeout(resolve, 30000))
|
||||
return res.data
|
||||
},
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,232 @@
|
||||
export interface IAdventureInfo {
|
||||
title: string
|
||||
name: string
|
||||
children: IAlterInfo[]
|
||||
}
|
||||
export interface IAlterOption {
|
||||
name: string
|
||||
title: string
|
||||
value?: string
|
||||
}
|
||||
|
||||
export interface IAlterInfo {
|
||||
name: string
|
||||
url?: string
|
||||
title: string
|
||||
default_value: string
|
||||
options?: IAlterOption[]
|
||||
open?: boolean
|
||||
comment?: string
|
||||
value?: string
|
||||
}
|
||||
|
||||
export interface ICharacterInfo {
|
||||
role: string
|
||||
alter: string
|
||||
name: string
|
||||
buffer: boolean
|
||||
equVersion: string
|
||||
equips: IEquipment[]
|
||||
properties: string[]
|
||||
stones: IEquipment[]
|
||||
enchants: IEnchantingInfo[]
|
||||
emblems: IEmblemInfo[]
|
||||
oaths: IEquipment[]
|
||||
weapons: string[]
|
||||
subweapons: string[]
|
||||
skills: ISkill[]
|
||||
suits: ISuit[]
|
||||
avatar: Record<string, IAvatarInfo[]>
|
||||
jades: IJade[]
|
||||
sundry: Record<string, ISundry>
|
||||
options: { id: number; name: string; options: string[] }[]
|
||||
oaths_skills: Record<
|
||||
string,
|
||||
{
|
||||
suitInfo: {
|
||||
name: string
|
||||
rarity: string
|
||||
SkillAttack: number
|
||||
Buffer: number
|
||||
Attack: number
|
||||
}[]
|
||||
skills: { skillId: string; name: string; icon: string }[]
|
||||
}
|
||||
>
|
||||
}
|
||||
|
||||
export interface ISundry {
|
||||
id: number
|
||||
options: {
|
||||
name: string
|
||||
value: number
|
||||
}[]
|
||||
}
|
||||
|
||||
export interface IEquipment {
|
||||
id: string
|
||||
imageUrl: string
|
||||
itemType: string
|
||||
itemDetailType: string
|
||||
name: string
|
||||
categorize: string
|
||||
suit: string[]
|
||||
rarity: string
|
||||
max_adaptation: number
|
||||
STR: number[]
|
||||
INT: number[]
|
||||
Vitality: number[]
|
||||
Spirit: number[]
|
||||
AtkP: number[]
|
||||
AtkM: number[]
|
||||
AtkI: number[]
|
||||
SkillAttack: number[]
|
||||
Attack: number[]
|
||||
Buffer: number[]
|
||||
detail: string
|
||||
bufferDetail: string
|
||||
position: string[]
|
||||
wearUrl: string[]
|
||||
oathPos: string
|
||||
displayUrl?: string
|
||||
}
|
||||
|
||||
export interface ISkill {
|
||||
icon: string
|
||||
name: string
|
||||
id: number
|
||||
learnLv: number
|
||||
position: number
|
||||
line: number
|
||||
type: string
|
||||
maxLearnLv: number
|
||||
maxLv: number
|
||||
bind: boolean
|
||||
hasVP: boolean
|
||||
hasUP: boolean
|
||||
vps: {
|
||||
name: string
|
||||
desc: string
|
||||
}[]
|
||||
uuid: string
|
||||
upType: 'damage' | 'heal'
|
||||
}
|
||||
|
||||
export interface ISuit {
|
||||
id: number
|
||||
name: string
|
||||
imageUrl: string
|
||||
suitId: number
|
||||
suitName: string
|
||||
point: number
|
||||
rarity: string
|
||||
level: number
|
||||
SkillAttack: number
|
||||
Buffer: number
|
||||
value: string
|
||||
bufferValue: string
|
||||
}
|
||||
|
||||
export interface IEnchantingInfo {
|
||||
id: string | number
|
||||
fame: number | undefined
|
||||
position: string[]
|
||||
detail: string
|
||||
categorize: string[]
|
||||
rarity?: string
|
||||
type?: string
|
||||
}
|
||||
|
||||
export interface IEmblemInfo {
|
||||
fame: number
|
||||
id: string
|
||||
rarity: string
|
||||
type: string
|
||||
value: string
|
||||
}
|
||||
|
||||
export interface IAvatarInfo {
|
||||
id: number
|
||||
options: string[]
|
||||
part: string
|
||||
rarity: string
|
||||
suit?: string
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface IJade {
|
||||
name: string
|
||||
id: number
|
||||
max: number
|
||||
min: number
|
||||
pre: number
|
||||
unit: string
|
||||
}
|
||||
|
||||
export interface ISkillInfo {
|
||||
name: string
|
||||
type: string
|
||||
desc: string
|
||||
descDetail: string
|
||||
consumeItem: ConsumeItem
|
||||
descSpecial: string[]
|
||||
maxLevel: number
|
||||
requiredLevel: number
|
||||
requiredLevelRange: number
|
||||
preRequiredSkill: any
|
||||
jobId: string
|
||||
jobName: string
|
||||
jobGrowLevel: any[]
|
||||
evolution: Evolution[]
|
||||
enhancement: Enhancement[]
|
||||
attribute: Attribute
|
||||
}
|
||||
|
||||
export interface ConsumeItem {
|
||||
itemId: string
|
||||
itemName: string
|
||||
value: number
|
||||
}
|
||||
|
||||
export interface Evolution {
|
||||
type: number
|
||||
name: string
|
||||
desc: string
|
||||
descDetail: string
|
||||
skills?: string[]
|
||||
}
|
||||
|
||||
export interface Enhancement {
|
||||
type: number
|
||||
status: Status[]
|
||||
}
|
||||
|
||||
export interface Status {
|
||||
name: string
|
||||
value: string
|
||||
}
|
||||
|
||||
export interface Attribute {
|
||||
optionDesc: string
|
||||
level: number
|
||||
consumeMp: number
|
||||
coolTime: number
|
||||
castingTime?: number
|
||||
optionValue: Record<`value${string}`, string>
|
||||
detail: string
|
||||
}
|
||||
|
||||
export interface IHelperRoleInfo {
|
||||
roleId: string
|
||||
roleName: string
|
||||
roleJob: string
|
||||
avatarLink: string
|
||||
fame: number
|
||||
}
|
||||
|
||||
export interface IHelperInfo {
|
||||
id: string
|
||||
avatar: string
|
||||
name: string
|
||||
roleList: IHelperRoleInfo[]
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
export interface IDataType<T = any> {
|
||||
code?: number
|
||||
message: string
|
||||
data: T
|
||||
state?: number
|
||||
}
|
||||
Reference in New Issue
Block a user