import { asyncComputed } from '@vueuse/core'
import api from '@/api'
import './style.scss'
import { UiDataSection } from '@/components/ui/data-section'
import { TabsRoot, UiTabsList, UiTabsTrigger } from '@/components/ui/tabs'
export default defineComponent({
name: 'SkillDetail',
props: {
skillId: {
type: String,
required: true,
},
level: {
type: Number,
default: 1,
},
},
setup(props) {
const currentSkill = computed(() => props.skillId)
const currentLevel = computed(() => props.level)
const skillInfo = asyncComputed(async () => {
if (!currentSkill.value && !currentLevel.value) return undefined
const res = await api.skillDetail(currentSkill.value, currentLevel.value)
return res
})
const curTab = ref(0)
const basic = computed(() =>
!skillInfo.value
? []
: [
{ label: '技能等级', value: skillInfo.value?.attribute?.level ?? props.level },
{ label: '学习等级', value: skillInfo.value?.requiredLevel },
{ label: '等级上限', value: skillInfo.value?.maxLevel },
{
label: '冷却时间',
value: skillInfo.value?.attribute?.coolTime
? `${skillInfo.value?.attribute?.coolTime.toFixed(1)}秒`
: undefined,
},
{
label: '施放时间',
value: !skillInfo.value?.attribute?.castingTime
? '瞬发'
: `${skillInfo.value?.attribute?.castingTime.toFixed(1)}秒`,
},
{ label: '魔法值', value: skillInfo.value?.attribute?.consumeMp },
{
label: '消耗无色小晶块',
value: skillInfo.value?.consumeItem?.value
? `${skillInfo.value?.consumeItem?.value}个`
: undefined,
},
],
)
const desc = computed(() => skillInfo.value?.descDetail.split('\n'))
const detail = computed(() => {
const items =
skillInfo.value?.attribute?.optionDesc?.split('\n').filter((item) => !!item) ?? []
const details = items?.map((a) => {
const beforeReplace = a.match(/^(.+?)\s*(\{value\d+\}.*)$/)
if (beforeReplace) {
a = `${beforeReplace[1]}${beforeReplace[2]}`
}
const matches = a.match(/{([^}]+)}/g)
if (matches) {
matches.forEach((match) => {
const key = match.replace(/[{}]/g, '')
// Only access if key matches the expected pattern
if (/^value.+/.test(key)) {
const value = skillInfo.value?.attribute?.optionValue[key as `value${string}`] ?? '-'
if (value) {
a = a.replace(match, `${value}`)
}
}
})
}
return a
})
return details || []
})
const renderSkillDetail = () => (
<>