初始化
This commit is contained in:
80
src/store/index.js
Normal file
80
src/store/index.js
Normal file
@@ -0,0 +1,80 @@
|
||||
import { createStore } from "vuex";
|
||||
|
||||
export default createStore({
|
||||
state: {
|
||||
appVersion: "0.0.1",
|
||||
debugStr: "测试debug字符",
|
||||
settings: {
|
||||
currentRoute: "/discover/recommend", //当前路由
|
||||
songId: 0, //歌曲id
|
||||
},
|
||||
caches: {},
|
||||
theme: {
|
||||
//主题覆盖变量
|
||||
themeOverrides: {
|
||||
common: {
|
||||
primaryColor: "#5C18A0FF",
|
||||
primaryColorHover: "#7536ADFF",
|
||||
primaryColorPressed: "#690D7EFF",
|
||||
primaryColorSuppl: "#511D77FF",
|
||||
textColorBase: "#1F1F1FFF",
|
||||
},
|
||||
},
|
||||
zmusic: {},
|
||||
},
|
||||
},
|
||||
getters: {
|
||||
//根据当前路由计算主菜单的选择项
|
||||
mainMenuSelected: (state) => (menuOptions) => {
|
||||
return menuOptions.find((item) => {
|
||||
return (
|
||||
state.settings.currentRoute.indexOf(item.key) > -1
|
||||
);
|
||||
})?.key;
|
||||
},
|
||||
},
|
||||
mutations: {
|
||||
//载入settings设置
|
||||
loadSettings(state) {
|
||||
const l = localStorage.getItem("zmusic.settings");
|
||||
if (l) state.settings = JSON.parse(l);
|
||||
},
|
||||
//保存settings设置
|
||||
saveSettings(state, settings) {
|
||||
state.settings = { ...state.settings, ...settings };
|
||||
saveLoaclSettings(state.settings);
|
||||
},
|
||||
|
||||
//保存当前路由
|
||||
saveCurrentRoute(state, currentRoute) {
|
||||
state.settings.currentRoute = currentRoute;
|
||||
saveLoaclSettings(state.settings);
|
||||
},
|
||||
|
||||
//载入theme设置
|
||||
loadTheme(state) {
|
||||
const l = localStorage.getItem("zmusic.theme");
|
||||
if (l) state.theme = JSON.parse(l);
|
||||
},
|
||||
//保存theme设置
|
||||
saveTheme(state, theme) {
|
||||
state.theme = { ...state.theme, ...theme };
|
||||
saveLoaclTheme(state.theme);
|
||||
},
|
||||
},
|
||||
actions: {},
|
||||
modules: {},
|
||||
});
|
||||
|
||||
function saveLoaclSettings(s) {
|
||||
localStorage.setItem(
|
||||
"zmusic.settings",
|
||||
JSON.stringify(s)
|
||||
);
|
||||
}
|
||||
function saveLoaclTheme(s) {
|
||||
localStorage.setItem(
|
||||
"zmusic.theme",
|
||||
JSON.stringify(s)
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user