feat:接入pinia持久化存储

This commit is contained in:
Xwen
2023-12-15 12:47:03 +08:00
parent ebc58ccd00
commit d210760e08
5 changed files with 1768 additions and 1689 deletions

View File

@@ -1,22 +1,37 @@
import {getAll} from '@/apis/configApi'
import { defineStore } from 'pinia'
const useConfigStore = defineStore('config',
{
state: () => ({
data: []
}),
getters: {
name:(state)=>state.data.filter(s=> s.configKey=='bbs.site.name').map(x=>x.configValue)[0],
author:(state)=>state.data.filter(s=> s.configKey=='bbs.site.author').map(x=>x.configValue)[0],
icp:(state)=>state.data.filter(s=> s.configKey=='bbs.site.icp').map(x=>x.configValue)[0],
bottom:(state)=>state.data.filter(s=>s.configKey=='bbs.site.bottom').map(x=>x.configValue)[0]
},
actions: {
// 登录
async getConfig() {
const response = await getAll();
this.data = response.data.items;
},
},
})
import { getAll } from "@/apis/configApi";
import { defineStore } from "pinia";
const useConfigStore = defineStore("config", {
state: () => ({
data: [],
}),
getters: {
name: (state) =>
state.data
.filter((s) => s.configKey == "bbs.site.name")
.map((x) => x.configValue)[0],
author: (state) =>
state.data
.filter((s) => s.configKey == "bbs.site.author")
.map((x) => x.configValue)[0],
icp: (state) =>
state.data
.filter((s) => s.configKey == "bbs.site.icp")
.map((x) => x.configValue)[0],
bottom: (state) =>
state.data
.filter((s) => s.configKey == "bbs.site.bottom")
.map((x) => x.configValue)[0],
},
actions: {
// 登录
async getConfig() {
const response = await getAll();
this.data = response.data.items;
},
},
persist: {
key: "configInfo",
storage: window.sessionStorage,
},
});
export default useConfigStore;