diff --git a/src/store/index.js b/src/store/index.js index 417d6af..4db579a 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -4,13 +4,10 @@ import state from "./state"; import mutations from "./mutations"; import actions from "./actions"; import { changeAppearance } from "@/utils/common"; -import updateApp from "@/utils/updateApp"; import Player from "@/utils/Player"; // vuex 自定义插件 import saveToLocalStorage from "./plugins/localStorage"; -updateApp(); - Vue.use(Vuex); let plugins = [saveToLocalStorage]; diff --git a/src/store/initLocalStorage.js b/src/store/initLocalStorage.js index e543c66..ee16fb9 100644 --- a/src/store/initLocalStorage.js +++ b/src/store/initLocalStorage.js @@ -12,6 +12,7 @@ let localStorage = { showUnavailableSongInGreyStyle: true, automaticallyCacheSongs: false, nyancatStyle: false, + showLyricsTranslation: true, }, data: { user: {}, diff --git a/src/store/state.js b/src/store/state.js index 898bae8..9f7065c 100644 --- a/src/store/state.js +++ b/src/store/state.js @@ -1,5 +1,6 @@ import initLocalStorage from "./initLocalStorage"; import pkg from "../../package.json"; +import updateApp from "@/utils/updateApp"; if (localStorage.getItem("appVersion") === null) { localStorage.setItem("settings", JSON.stringify(initLocalStorage.settings)); @@ -7,6 +8,8 @@ if (localStorage.getItem("appVersion") === null) { localStorage.setItem("appVersion", pkg.version); } +updateApp(); + export default { showLyrics: false, liked: { diff --git a/src/utils/updateApp.js b/src/utils/updateApp.js index cadbef3..ebbeeff 100644 --- a/src/utils/updateApp.js +++ b/src/utils/updateApp.js @@ -3,13 +3,19 @@ import pkg from "../../package.json"; const updateSetting = () => { const parsedSettings = JSON.parse(localStorage.getItem("settings")); + const { + playlistCategories, + showUnavailableSongInGreyStyle, + automaticallyCacheSongs, + nyancatStyle, + showLyricsTranslation, + } = initLocalStorage.settings; const settings = { - playlistCategories: initLocalStorage?.settings?.playlistCategories, - showUnavailableSongInGreyStyle: - initLocalStorage?.settings?.showUnavailableSongInGreyStyle, - automaticallyCacheSongs: - initLocalStorage?.settings?.automaticallyCacheSongs, - nyancatStyle: initLocalStorage?.settings?.nyancatStyle, + playlistCategories, + showUnavailableSongInGreyStyle, + automaticallyCacheSongs, + nyancatStyle, + showLyricsTranslation, ...parsedSettings, }; diff --git a/src/views/lyrics.vue b/src/views/lyrics.vue index 9241e00..9bb55fd 100644 --- a/src/views/lyrics.vue +++ b/src/views/lyrics.vue @@ -134,6 +134,7 @@ " > + v-html="formatLine(line)"
@@ -274,6 +275,15 @@ export default { } }, 500); }, + formatLine(line) { + const showLyricsTranslation = this.$store.state.settings + .showLyricsTranslation; + if (showLyricsTranslation && line.contents[1]) { + return line.contents[0] + "
" + line.contents[1]; + } else { + return line.contents[0]; + } + }, }, watch: { currentTrack() { diff --git a/src/views/settings.vue b/src/views/settings.vue index 5a98bf9..f59a536 100644 --- a/src/views/settings.vue +++ b/src/views/settings.vue @@ -109,6 +109,22 @@
+
+
+
显示歌词翻译
+
+
+
+ + +
+
+
{{ $t("settings.showGitHubIcon") }}
@@ -294,6 +310,17 @@ export default { } }, }, + showLyricsTranslation: { + get() { + return this.settings.showLyricsTranslation; + }, + set(value) { + this.$store.commit("updateSettings", { + key: "showLyricsTranslation", + value, + }); + }, + }, }, methods: { logout() {