fix: 钓到多条鱼提示修正

main
LyMysterious 1 year ago
parent 4073466f2c
commit eaac5c2338

@ -7,32 +7,15 @@
<div class="ripple"></div> <div class="ripple"></div>
</div> </div>
<div class="result" v-if="resultMessage || nextPullTime"> <div class="result" v-if="resultMessage || nextPullTime">
<el-alert <el-alert v-if="resultMessage" :title="resultMessage" :type="currentCatch.length>0 ? 'success' : 'info'"
v-if="resultMessage" :closable="false" show-icon />
:title="resultMessage" <el-alert v-if="nextPullTime" :title="`下次可钓鱼时间:${nextPullTime}`" type="warning" :closable="false" show-icon />
:type="currentCatch ? 'success' : 'info'"
:closable="false"
show-icon
/>
<el-alert
v-if="nextPullTime"
:title="`下次可钓鱼时间:${nextPullTime}`"
type="warning"
:closable="false"
show-icon
/>
</div> </div>
</div> </div>
<div class="log-area"> <div class="log-area">
<FishingLog :logs="fishingLogs" /> <FishingLog :logs="fishingLogs" />
<div class="back-button"> <div class="back-button">
<el-button <el-button @click="goHome" size="small" type="default" icon="ArrowLeft">返回</el-button>
@click="goHome"
size="small"
type="default"
icon="ArrowLeft"
>返回</el-button
>
</div> </div>
</div> </div>
</div> </div>
@ -50,7 +33,7 @@ const router = useRouter();
const resultMessage = ref(""); const resultMessage = ref("");
const nextPullTime = ref(""); const nextPullTime = ref("");
const isFishing = ref(false); const isFishing = ref(false);
const currentCatch = ref(null); const currentCatch = ref([]); //
const fishingLogs = ref([]); const fishingLogs = ref([]);
// localStorage // localStorage
@ -66,12 +49,10 @@ const saveLogs = () => {
localStorage.setItem("fishingLogs", JSON.stringify(fishingLogs.value)); localStorage.setItem("fishingLogs", JSON.stringify(fishingLogs.value));
}; };
//
onMounted(() => { onMounted(() => {
loadCachedLogs(); loadCachedLogs();
}); });
//
onBeforeUnmount(() => { onBeforeUnmount(() => {
localStorage.removeItem("fishingLogs"); localStorage.removeItem("fishingLogs");
}); });
@ -80,7 +61,7 @@ const handleFish = async () => {
if (isFishing.value) return; if (isFishing.value) return;
isFishing.value = true; isFishing.value = true;
currentCatch.value = null; currentCatch.value = [];
resultMessage.value = "正在钓鱼中..."; resultMessage.value = "正在钓鱼中...";
try { try {
@ -92,20 +73,23 @@ const handleFish = async () => {
} }
if (items.length > 0) { if (items.length > 0) {
const fish = items[0]; currentCatch.value = items;
currentCatch.value = fish;
resultMessage.value = `你钓到了一条${fish.isRare ? "稀有的" : ""}${ //
fish.fishName const messageList = items.map(fish =>
}重量 ${fish.weight}`; `${fish.isRare ? "稀有的" : ""}${fish.fishName}」,重量 ${fish.weight}`
);
resultMessage.value = `你钓到了:\n${messageList.join("\n")}`;
ElMessage.success("钓鱼成功!🎣"); ElMessage.success("钓鱼成功!🎣");
// localStorage //
fishingLogs.value.unshift({ const newLogs = items.map(fish => ({
time: new Date(), time: new Date(),
fishName: fish.fishName, fishName: fish.fishName,
weight: fish.weight, weight: fish.weight,
isRare: fish.isRare, isRare: fish.isRare,
}); }));
fishingLogs.value.unshift(...newLogs);
saveLogs(); saveLogs();
} else { } else {
resultMessage.value = "什么也没钓到,下次好运 🍀"; resultMessage.value = "什么也没钓到,下次好运 🍀";
@ -130,6 +114,7 @@ const handleFish = async () => {
const goHome = () => { const goHome = () => {
router.push("/"); router.push("/");
}; };
</script> </script>
<style scoped> <style scoped>

Loading…
Cancel
Save