perf: 优化部分变量 & feat: 新增一个设置项 #124

This commit is contained in:
imsyy 2023-04-21 16:37:08 +08:00
parent db0d3b92ae
commit acc8f54ef9
18 changed files with 145 additions and 125 deletions

2
.env
View File

@ -24,7 +24,7 @@ VITE_DESC_TEXT_OTHER = "哎呀,这都被你发现了( 再点击一次可关
# 天气 Key
## 请前往高德开放平台注册 Web服务 Key免费的
## 请各位大佬行行好,别再让我超量了
VITE_WEATHER_KEY = "57eaea5833ff1616cfd1ff2c4cf9b58a"
VITE_WEATHER_KEY = "6c13af6fc30868bee488faf2cc652ab4"
# 建站日期
## 请按照 YYYY-MM-DD 格式填写

View File

@ -65,7 +65,7 @@ onMounted(() => {
//
document.getElementsByTagName("body")[0].className = "";
//
let loadingBox = document.getElementById("loading-box");
const loadingBox = document.getElementById("loading-box");
loadingBox.classList.add("loaded");
});

View File

@ -20,7 +20,7 @@ import { SuccessPicture } from "@icon-park/vue-next";
import { mainStore } from "@/store";
const store = mainStore();
let bgUrl = ref(null); //
const bgUrl = ref(null); //
const changeBg = (type) => {
if (type == 0) {

View File

@ -35,7 +35,7 @@ import { mainStore } from "@/store";
import config from "@/../package.json";
const store = mainStore();
let fullYear = new Date().getFullYear();
const fullYear = new Date().getFullYear();
</script>
<style lang="scss" scoped>

View File

@ -34,17 +34,14 @@ import { mainStore } from "@/store";
const store = mainStore();
//
let openMusicShow = ref(false);
const openMusicShow = ref(false);
//
let hitokotoData = reactive({
const hitokotoData = reactive({
text: "这里应该显示一句话",
from: "無名",
});
//
const openMusic = () => {};
//
const getHitokotoData = () => {
getHitokoto()

View File

@ -11,7 +11,7 @@
:span="8"
v-for="(item, index) in linksData"
:key="item"
@click="jumpLink(item.link)"
@click="jumpLink(item)"
>
<div
class="item cards"
@ -28,7 +28,6 @@
</template>
<script setup>
import { ref } from "vue";
import { Icon } from "@vicons/utils";
import {
Link,
@ -39,10 +38,12 @@ import {
Book,
Fire,
} from "@vicons/fa";
import { mainStore } from "@/store";
const store = mainStore();
//
// 6
let linksData = [
const linksData = [
{
icon: Blog,
name: "博客",
@ -76,8 +77,12 @@ let linksData = [
];
//
const jumpLink = (url) => {
window.open(url, "_blank");
const jumpLink = (data) => {
if (data.name === "音乐" && store.musicClick) {
if ($openList) $openList();
} else {
window.open(data.link, "_blank");
}
};
</script>
@ -112,6 +117,11 @@ const jumpLink = (url) => {
background: rgb(0 0 0 / 40%);
transition: 0.3s;
}
&:active {
transform: scale(1);
}
.name {
font-size: 1.1rem;
margin-left: 8px;
@ -135,4 +145,4 @@ const jumpLink = (url) => {
}
}
}
</style>
</style>

View File

@ -36,12 +36,12 @@ import { mainStore } from "@/store";
const store = mainStore();
// logo
let siteLogo = import.meta.env.VITE_SITE_LOGO;
const siteLogo = import.meta.env.VITE_SITE_LOGO;
//
let siteUrl = import.meta.env.VITE_SITE_URL.split(".");
const siteUrl = import.meta.env.VITE_SITE_URL.split(".");
//
let descriptionText = reactive({
const descriptionText = reactive({
hello: import.meta.env.VITE_DESC_HELLO,
text: import.meta.env.VITE_DESC_TEXT,
});

View File

@ -7,7 +7,7 @@
v-show="store.musicOpenState"
>
<div class="btns">
<span @click="musicListShow = true">音乐列表</span>
<span @click="openMusicList()">音乐列表</span>
<span @click="store.musicOpenState = false">回到一言</span>
</div>
<div class="control">
@ -103,7 +103,7 @@
</template>
<script setup>
import { ref, reactive, watch, onMounted, nextTick } from "vue";
import { ref, reactive, watch, onMounted } from "vue";
import {
GoStart,
PlayOne,
@ -119,19 +119,23 @@ import { mainStore } from "@/store";
const store = mainStore();
//
let volumeShow = ref(false);
let volumeNum = ref(store.musicVolume ? store.musicVolume : 0.7);
const volumeShow = ref(false);
const volumeNum = ref(store.musicVolume ? store.musicVolume : 0.7);
//
let musicListShow = ref(false);
const musicListShow = ref(false);
const playerRef = ref(null);
const musicDialog = ref(null);
const playerData = reactive({
server: import.meta.env.VITE_SONG_SERVER,
type: import.meta.env.VITE_SONG_TYPE,
id: import.meta.env.VITE_SONG_ID,
});
//
const openMusicList = () => {
musicListShow.value = true;
};
//
const changePlayState = () => {
playerRef.value.playToggle();
@ -149,6 +153,8 @@ onMounted(() => {
changePlayState();
}
});
// window
window.$openList = openMusicList;
});
//
@ -293,8 +299,8 @@ watch(
border-radius: 6px;
z-index: 999;
@media (max-width: 720px) {
left: calc(50% - 45%);
width: 90%;
left: calc(50% - 45%);
width: 90%;
}
.close {
position: absolute;
@ -336,4 +342,4 @@ watch(
transform: scale(1) translateY(0);
}
}
</style>
</style>

View File

@ -33,12 +33,12 @@ const store = mainStore();
const player = ref(null);
//
let playList = ref([]);
let playerLrc = ref("");
const playList = ref([]);
const playerLrc = ref("");
//
let playIndex = ref(0);
let playListCount = ref(0);
const playIndex = ref(0);
const playListCount = ref(0);
//
const props = defineProps({
@ -216,6 +216,7 @@ defineExpose({ playToggle, changeVolume, changeSong });
width: 80%;
background: transparent;
border-radius: 6px;
font-family: "HarmonyOS_Regular", sans-serif !important;
:deep(.aplayer-body) {
.aplayer-pic {
display: none;

View File

@ -21,6 +21,15 @@
:inactive-icon="CloseSmall"
/>
</div>
<div class="item">
<span class="text">音乐点击是否打开面板</span>
<el-switch
v-model="musicClick"
inline-prompt
:active-icon="CheckSmall"
:inactive-icon="CloseSmall"
/>
</div>
</el-collapse-item>
<el-collapse-item title="其他设置" name="3">
<div>设置内容待增加</div>
@ -39,11 +48,11 @@ import { CheckSmall, CloseSmall } from "@icon-park/vue-next";
import { storeToRefs } from "pinia";
const store = mainStore();
const { siteStartShow } = storeToRefs(store);
const { siteStartShow, musicClick } = storeToRefs(store);
//
let activeName = ref("1");
let bgSet = ref("0");
const activeName = ref("1");
const bgSet = ref("0");
onMounted(() => {
bgSet.value = store.coverType.toString();
@ -130,4 +139,4 @@ watch(
}
}
}
</style>
</style>

View File

@ -23,8 +23,8 @@ import { getSocialLinks } from "@/api";
import { Error } from "@icon-park/vue-next";
//
let socialLinksData = ref([]);
let socialTip = ref("通过这里联系我吧");
const socialLinksData = ref([]);
const socialTip = ref("通过这里联系我吧");
//
const getSocialLinksData = () => {

View File

@ -61,13 +61,13 @@ import { mainStore } from "@/store";
const store = mainStore();
//
let timeData = ref(getTimeCapsule());
let startDate = ref(import.meta.env.VITE_SITE_START);
let startDateText = ref(null);
let timeInterval = null;
const timeData = ref(getTimeCapsule());
const startDate = ref(import.meta.env.VITE_SITE_START);
const startDateText = ref(null);
const timeInterval = ref(null);
onMounted(() => {
timeInterval = setInterval(() => {
timeInterval.value = setInterval(() => {
timeData.value = getTimeCapsule();
if (startDate.value)
startDateText.value = siteDateStatistics(new Date(startDate.value));
@ -75,7 +75,7 @@ onMounted(() => {
});
onBeforeUnmount(() => {
clearInterval(timeInterval);
clearInterval(timeInterval.value);
});
</script>

View File

@ -20,10 +20,10 @@ import { getAdcode, getWeather } from "@/api";
import { Error } from "@icon-park/vue-next";
// Key
let mainKey = import.meta.env.VITE_WEATHER_KEY;
const mainKey = import.meta.env.VITE_WEATHER_KEY;
//
let weatherData = reactive({
const weatherData = reactive({
adCode: {
city: null, //
adcode: null, //

View File

@ -1,75 +1,73 @@
import {
defineStore
} from "pinia";
import { defineStore } from "pinia";
export const mainStore = defineStore("main", {
state: () => {
return {
innerWidth: null, // 当前窗口宽度
coverType: "0", // 壁纸种类
siteStartShow: true, // 建站日期显示
musicIsOk: false, // 音乐是否加载完成
musicVolume: 0, // 音乐音量;
musicOpenState: false, // 音乐面板开启状态
backgroundShow: false, // 壁纸展示状态
boxOpenState: false, // 盒子开启状态
mobileOpenState: false, // 移动端开启状态
mobileFuncState: false, // 移动端功能区开启状态
setOpenState: false, // 设置页面开启状态
playerState: false, // 当前播放状态
playerTitle: null, // 当前播放歌曲名
playerArtist: null, // 当前播放歌手名
playerLrc: "歌词加载中", // 当前播放歌词
}
state: () => {
return {
innerWidth: null, // 当前窗口宽度
coverType: "0", // 壁纸种类
siteStartShow: true, // 建站日期显示
musicIsOk: false, // 音乐是否加载完成
musicVolume: 0, // 音乐音量;
musicOpenState: false, // 音乐面板开启状态
backgroundShow: false, // 壁纸展示状态
boxOpenState: false, // 盒子开启状态
mobileOpenState: false, // 移动端开启状态
mobileFuncState: false, // 移动端功能区开启状态
setOpenState: false, // 设置页面开启状态
playerState: false, // 当前播放状态
playerTitle: null, // 当前播放歌曲名
playerArtist: null, // 当前播放歌手名
playerLrc: "歌词加载中", // 当前播放歌词
musicClick: false, // 音乐链接是否跳转
};
},
getters: {
// 获取歌词
getPlayerLrc(state) {
return state.playerLrc;
},
getters: {
// 获取歌词
getPlayerLrc(state) {
return state.playerLrc;
},
// 获取歌曲信息
getPlayerData(state) {
return {
name: state.playerTitle,
artist: state.playerArtist,
}
},
// 获取页面宽度
getInnerWidth(state) {
return state.innerWidth;
}
// 获取歌曲信息
getPlayerData(state) {
return {
name: state.playerTitle,
artist: state.playerArtist,
};
},
actions: {
// 更改当前页面宽度
setInnerWidth(value) {
this.innerWidth = value;
if (value >= 720) {
this.mobileOpenState = false;
this.mobileFuncState = false;
}
},
// 更改播放状态
setPlayerState(value) {
if (value) {
this.playerState = false;
} else {
this.playerState = true;
}
},
// 更改歌词
setPlayerLrc(value) {
this.playerLrc = value;
},
// 更改歌曲数据
setPlayerData(title, artist) {
this.playerTitle = title;
this.playerArtist = artist;
}
// 获取页面宽度
getInnerWidth(state) {
return state.innerWidth;
},
persist: {
key: 'data',
storage: window.localStorage,
paths: ['coverType', 'musicVolume', 'siteStartShow'],
},
actions: {
// 更改当前页面宽度
setInnerWidth(value) {
this.innerWidth = value;
if (value >= 720) {
this.mobileOpenState = false;
this.mobileFuncState = false;
}
},
})
// 更改播放状态
setPlayerState(value) {
if (value) {
this.playerState = false;
} else {
this.playerState = true;
}
},
// 更改歌词
setPlayerLrc(value) {
this.playerLrc = value;
},
// 更改歌曲数据
setPlayerData(title, artist) {
this.playerTitle = title;
this.playerArtist = artist;
},
},
persist: {
key: "data",
storage: window.localStorage,
paths: ["coverType", "musicVolume", "siteStartShow", "musicClick"],
},
});

View File

@ -37,7 +37,7 @@ import TimeCapsule from "@/components/TimeCapsule/index.vue";
import { mainStore } from "@/store";
const store = mainStore();
let closeShow = ref(false);
const closeShow = ref(false);
</script>
<style lang="scss" scoped>

View File

@ -43,17 +43,17 @@ import Weather from "@/components/Weather/index.vue";
const store = mainStore();
//
let currentTime = ref({});
let timeInterval = null;
const currentTime = ref({});
const timeInterval = ref(null);
onMounted(() => {
timeInterval = setInterval(() => {
timeInterval.value = setInterval(() => {
currentTime.value = getCurrentTime();
}, 1000);
});
onBeforeUnmount(() => {
clearInterval(timeInterval);
clearInterval(timeInterval.value);
});
</script>
@ -137,4 +137,4 @@ onBeforeUnmount(() => {
}
}
}
</style>
</style>

View File

@ -13,14 +13,13 @@
</template>
<script setup>
import { reactive, ref, onMounted } from "vue";
import { mainStore } from "@/store";
import Func from "@/views/Func/index.vue";
import Link from "@/components/Links/index.vue";
const store = mainStore();
//
let siteUrl = import.meta.env.VITE_SITE_URL.split(".");
const siteUrl = import.meta.env.VITE_SITE_URL.split(".");
</script>

View File

@ -79,13 +79,13 @@ import Set from "@/components/Set/index.vue";
import config from "@/../package.json";
const store = mainStore();
let closeShow = ref(false);
const closeShow = ref(false);
//
let siteUrl = import.meta.env.VITE_SITE_URL.split(".");
const siteUrl = import.meta.env.VITE_SITE_URL.split(".");
//
let upData = reactive({
const upData = reactive({
new: [
"采用 Vue 进行重构",
"音乐歌单支持快速自定义",