fix: 钓到多条鱼提示修正

main
LyMysterious 1 year ago
parent 4073466f2c
commit eaac5c2338

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

Loading…
Cancel
Save