feat: 修改vuex为pinia

修改vuex为pinia
This commit is contained in:
zc
2021-12-21 07:33:30 +08:00
parent 9f8d5d757b
commit d53c13ecba
10 changed files with 210 additions and 217 deletions

View File

@@ -1,18 +1,24 @@
import {Module} from "vuex";
import {AppState,RootStateTypes} from "@store/interface";
// import {Module} from "vuex";
import {AppState} from "@store/interface";
import {Local} from "@utils/storage";
const appModule: Module<AppState, RootStateTypes> = {
namespaced: true,
state: {
// import { storageLocal } from "/@/utils/storage";
import { store } from "@/store";
// import { appType } from "./types";
import { defineStore } from "pinia";
// import { getConfig } from "/@/config";
export const useAppStore = defineStore({
id: "youlai-app",
state: ():AppState=>({
device: 'desktop',
sidebar: {
opened: Local.get('sidebarStatus') ? !!+Local.get('sidebarStatus') : true,
withoutAnimation: false
}
},
mutations: {
TOGGLE_SIDEBAR: state => {
}),
actions: {
async TOGGLE_SIDEBAR(state:any) {
state.sidebar.opened = !state.sidebar.opened
console.log('state.sidebar.opened',state.sidebar.opened)
state.sidebar.withoutAnimation = false
@@ -22,28 +28,26 @@ const appModule: Module<AppState, RootStateTypes> = {
Local.set('sidebarStatus', 0)
}
},
CLOSE_SIDEBAR: (state, withoutAnimation) => {
async CLOSE_SIDEBAR (state:any, withoutAnimation:any) {
Local.set('sidebarStatus', 0)
state.sidebar.opened = false
state.sidebar.withoutAnimation = withoutAnimation
},
TOGGLE_DEVICE: (state, device) => {
async TOGGLE_DEVICE(state:any, device:any) {
console.log('TOGGLE_DEVICE',device)
state.device = device
}
},
actions: {
toggleSideBar({commit}) {
commit('TOGGLE_SIDEBAR')
},
closeSideBar({commit}, {withoutAnimation}) {
commit('CLOSE_SIDEBAR', withoutAnimation)
},
async toggleDevice({commit}, device) {
commit('TOGGLE_DEVICE', device)
}
// toggleSideBar({commit}) {
// commit('TOGGLE_SIDEBAR')
// },
// closeSideBar({commit}, {withoutAnimation}) {
// commit('CLOSE_SIDEBAR', withoutAnimation)
// },
// async toggleDevice({commit}, device) {
// commit('TOGGLE_DEVICE', device)
// }
}
})
export function useAppStoreHook() {
return useAppStore(store);
}
export default appModule;