2023-01-15 05:22:30 +00:00
|
|
|
<template>
|
|
|
|
<div
|
|
|
|
class="hitokoto cards"
|
|
|
|
v-show="!store.musicOpenState"
|
|
|
|
@mouseenter="openMusicShow = true"
|
|
|
|
@mouseleave="openMusicShow = false"
|
|
|
|
@click.stop
|
|
|
|
>
|
|
|
|
<!-- 打开音乐面板 -->
|
2023-06-12 03:39:06 +00:00
|
|
|
<Transition name="el-fade-in-linear">
|
2023-01-15 05:22:30 +00:00
|
|
|
<div
|
|
|
|
class="open-music"
|
|
|
|
v-show="openMusicShow && store.musicIsOk"
|
|
|
|
@click="store.musicOpenState = true"
|
|
|
|
>
|
|
|
|
<music-menu theme="filled" size="18" fill="#efefef" />
|
|
|
|
<span>打开音乐播放器</span>
|
|
|
|
</div>
|
|
|
|
</Transition>
|
|
|
|
<!-- 一言内容 -->
|
2023-11-03 01:23:06 +00:00
|
|
|
<Transition name="el-fade-in-linear" mode="out-in">
|
|
|
|
<div :key="hitokotoData.text" class="content" @click="updateHitokoto">
|
|
|
|
<span class="text">{{ hitokotoData.text }}</span>
|
|
|
|
<span class="from">-「 {{ hitokotoData.from }} 」</span>
|
|
|
|
</div>
|
|
|
|
</Transition>
|
2023-01-15 05:22:30 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup>
|
2023-08-26 08:03:07 +00:00
|
|
|
import { MusicMenu, Error } from "@icon-park/vue-next";
|
|
|
|
import { getHitokoto } from "@/api";
|
|
|
|
import { mainStore } from "@/store";
|
|
|
|
import debounce from "@/utils/debounce.js";
|
2023-08-16 10:24:10 +00:00
|
|
|
|
2023-01-15 05:22:30 +00:00
|
|
|
const store = mainStore();
|
|
|
|
|
|
|
|
// 开启音乐面板按钮显隐
|
2023-04-21 08:37:08 +00:00
|
|
|
const openMusicShow = ref(false);
|
2023-01-15 05:22:30 +00:00
|
|
|
|
|
|
|
// 一言数据
|
2023-04-21 08:37:08 +00:00
|
|
|
const hitokotoData = reactive({
|
2023-08-26 08:03:07 +00:00
|
|
|
text: "这里应该显示一句话",
|
|
|
|
from: "無名",
|
2023-01-15 05:22:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// 获取一言数据
|
2023-12-11 08:11:22 +00:00
|
|
|
const getHitokotoData = async () => {
|
|
|
|
try {
|
|
|
|
const result = await getHitokoto();
|
|
|
|
hitokotoData.text = result.hitokoto;
|
|
|
|
hitokotoData.from = result.from;
|
|
|
|
} catch (error) {
|
|
|
|
ElMessage({
|
|
|
|
message: "一言获取失败",
|
|
|
|
icon: h(Error, {
|
|
|
|
theme: "filled",
|
|
|
|
fill: "#efefef",
|
|
|
|
}),
|
2023-01-15 05:22:30 +00:00
|
|
|
});
|
2023-12-11 08:11:22 +00:00
|
|
|
hitokotoData.text = "这里应该显示一句话";
|
|
|
|
hitokotoData.from = "無名";
|
|
|
|
}
|
2023-01-15 05:22:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// 更新一言数据
|
|
|
|
const updateHitokoto = () => {
|
|
|
|
// 防抖
|
|
|
|
debounce(() => {
|
|
|
|
getHitokotoData();
|
|
|
|
}, 500);
|
|
|
|
};
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
getHitokotoData();
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.hitokoto {
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
padding: 20px;
|
2023-08-16 10:24:10 +00:00
|
|
|
animation: fade 0.5s;
|
2023-01-15 05:22:30 +00:00
|
|
|
.open-music {
|
|
|
|
width: 100%;
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
background: #00000026;
|
|
|
|
padding: 4px 0;
|
|
|
|
border-radius: 8px 8px 0 0;
|
|
|
|
.i-icon {
|
|
|
|
width: 18px;
|
|
|
|
height: 18px;
|
|
|
|
display: block;
|
|
|
|
margin-right: 8px;
|
|
|
|
}
|
|
|
|
span {
|
|
|
|
font-size: 0.95rem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.content {
|
|
|
|
height: 100%;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
justify-content: space-evenly;
|
|
|
|
.text {
|
|
|
|
font-size: 1.1rem;
|
|
|
|
word-break: break-all;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
overflow: hidden;
|
|
|
|
display: -webkit-box;
|
|
|
|
-webkit-line-clamp: 3;
|
|
|
|
-webkit-box-orient: vertical;
|
|
|
|
}
|
|
|
|
.from {
|
|
|
|
margin-top: 10px;
|
|
|
|
font-weight: bold;
|
|
|
|
align-self: flex-end;
|
|
|
|
font-size: 1.1rem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-08-23 05:38:17 +00:00
|
|
|
</style>
|