diff --git a/src/plugin/mark.ts b/src/plugin/mark.ts index 4254d83..41a20b8 100644 --- a/src/plugin/mark.ts +++ b/src/plugin/mark.ts @@ -1,5 +1,5 @@ import { reactive, ref } from 'vue'; -import { message } from 'ant-design-vue'; +import { tip } from './utils'; const markedEnemy = reactive([]); @@ -61,10 +61,7 @@ export function getMarkInfo(id: EnemyIds, noMessage: boolean = false) { const info = markInfo[id]!; if (core.status.hero.atk >= info.nextCritical) { if (!reached[info.nextCritical] && !noMessage) { - message.success({ - content: `踩到了${core.material.enemys[id].name}的临界!`, - class: 'antdv-message' - }); + tip('success', `踩到了${core.material.enemys[id].name}的临界!`); } reached[info.nextCritical] = true; const n = core.nextCriticals(id, 1)[0]?.[0]; @@ -85,39 +82,25 @@ export function checkMarkedEnemy(noMessage: boolean = false) { if (damage === -1) return; const info = enemyDamageInfo[v]!; const name = core.material.enemys[v].name; - if (damage < 0) { - if (!noMessage) { - message.success({ - content: `${name}已经负伤了!`, - class: 'antdv-message' - }); - } + if (damage <= 0) { + if (!noMessage) tip('success', `${name}已经零伤了!`); } else if (damage < hp / 3) { if (!info[3] && !noMessage) { - message.success({ - content: `${name}的伤害已降至勇士生命值的1/3!`, - class: 'antdv-message' - }); + tip('success', `${name}的伤害已降至勇士生命值的1/3!`); } info[1] = true; info[2] = true; info[3] = true; } else if (damage < (hp / 3) * 2) { if (!info[2] && !noMessage) { - message.success({ - content: `${name}的伤害已降至勇士生命值的2/3!`, - class: 'antdv-message' - }); + tip('success', `${name}的伤害已降至勇士生命值的2/3!`); } info[1] = true; info[2] = true; info[3] = false; } else if (damage < hp) { if (!info[1] && !noMessage) { - message.success({ - content: `你已经能打过${name}了!`, - class: 'antdv-message' - }); + tip('success', `你已经能打过${name}了!`); } info[1] = true; info[2] = false; diff --git a/src/plugin/utils.ts b/src/plugin/utils.ts index edd96dd..4876571 100644 --- a/src/plugin/utils.ts +++ b/src/plugin/utils.ts @@ -1,3 +1,5 @@ +import { message } from 'ant-design-vue'; +import { MessageApi } from 'ant-design-vue/lib/message'; import { isNil } from 'lodash'; import { Animation, TimingFn } from 'mutate-animate'; import { ComputedRef, ref } from 'vue'; @@ -121,3 +123,13 @@ export function type( return content; } + +export function tip( + type: Exclude, + text: string +) { + message[type]({ + content: text, + class: 'antdv-message' + }); +} diff --git a/src/ui/equipbox.vue b/src/ui/equipbox.vue index 1ba3335..9b9edd5 100644 --- a/src/ui/equipbox.vue +++ b/src/ui/equipbox.vue @@ -183,10 +183,9 @@ import { computed, onMounted, onUnmounted, reactive, ref, watch } from 'vue'; import Scroll from '../components/scroll.vue'; import { getAddStatus, getEquips, getNowStatus } from '../plugin/ui/equipbox'; import BoxAnimate from '../components/boxAnimate.vue'; -import { has, type } from '../plugin/utils'; +import { has, tip, type } from '../plugin/utils'; import { cancelGlobalDrag, isMobile, useDrag } from '../plugin/use'; import { hyper, sleep } from 'mutate-animate'; -import { message } from 'ant-design-vue'; const equips = ref(getEquips()); const col = ref('all'); @@ -310,10 +309,7 @@ function clickList(i: number) { if (i === selected.value && listClicked.value) { const id = toShow.value[selected.value]?.[0]; if (!core.canEquip(id)) { - message.warn({ - content: '无法装备!', - class: 'antdv-message' - }); + tip('warn', '无法装备!'); return; } core.loadEquip(id); @@ -359,10 +355,7 @@ function loadEquip() { const num = toEquipType.value; if (num < 0) return; if (!canDragin(num)) { - message.warn({ - content: '无法装备!', - class: 'antdv-message' - }); + tip('warn', '无法装备!'); return; } const now = equiped.value[num];