This commit is contained in:
2023-06-08 21:09:28 +08:00
parent d778ceab61
commit f8947d332a
158 changed files with 17210 additions and 259 deletions

View File

@@ -1,8 +1,13 @@
import { createPinia } from "pinia"
import useUserStore from "./modules/user"
import useAppStore from "./modules/app"
import useTabBarStore from "./modules/tab-bar"
// ma组件新增
import useFormStore from "./modules/form"
import useKeepAliveStore from "./modules/keepAlive"
import useTagStore from "./modules/tag"
const pinia = createPinia()
export { useUserStore, useAppStore }
export { useUserStore, useAppStore, useTabBarStore, useFormStore, useKeepAliveStore, useTagStore }
export default pinia

View File

@@ -0,0 +1,24 @@
import { defineStore } from "pinia"
let defaultConfig = {
formList: [],
crudList: {}
}
const useFormStore = defineStore("form", {
state: () => ({ ...defaultConfig }),
getters: {
appCurrentConfig(state) {
return { ...state }
}
},
actions: {
updateSettings(partial) {
this.$patch(partial)
}
}
})
export default useFormStore

View File

@@ -0,0 +1,46 @@
import { defineStore } from "pinia"
const useKeepAliveStore = defineStore("keepAlive", {
state: () => ({
keepAlives: [],
show: true
}),
getters: {
currentKeepAlive(state) {
return { ...state }
}
},
actions: {
addKeepAlive(component) {
if (component.path.indexOf("maIframe") > -1) {
return
}
if (!this.keepAlives.includes(component.name)) {
this.keepAlives.push(component.name)
}
},
removeKeepAlive(component) {
const idx = this.keepAlives.indexOf(component.name)
if (idx !== -1) {
this.keepAlives.splice(idx, 1)
}
},
display() {
this.show = true
},
hidden() {
this.show = false
},
clearKeepAlive() {
this.keepAlives = []
}
}
})
export default useKeepAliveStore

View File

@@ -0,0 +1,64 @@
import { DEFAULT_ROUTE, DEFAULT_ROUTE_NAME, REDIRECT_ROUTE_NAME } from "@/router/constants"
import { defineStore } from "pinia"
import { isString } from "@/utils/is"
const formatTag = (route) => {
const { name, meta, fullPath, query } = route
return {
title: meta.locale || "",
name: String(name),
fullPath,
query,
ignoreCache: meta.ignoreCache
}
}
const BAN_LIST = [REDIRECT_ROUTE_NAME]
const useTabBarStore = defineStore("tabBar", {
state: () => ({
cacheTabList: new Set([DEFAULT_ROUTE_NAME]),
tagList: [DEFAULT_ROUTE]
}),
getters: {
getTabList() {
return this.tagList
},
getCacheList() {
// Array.from将对象去掉key拿value作为数组
return Array.from(this.cacheTabList)
}
},
actions: {
updateTabList(route) {
if (BAN_LIST.includes(route.name)) return
this.tagList.push(formatTag(route))
if (!route.meta.ignoreCache) {
this.cacheTabList.add(route.name)
}
},
deleteTag(idx, tag) {
this.tagList.splice(idx, 1)
this.cacheTabList.delete(tag.name)
},
addCache(name) {
if (isString(name) && name !== "") this.cacheTabList.add(name)
},
deleteCache(tag) {
this.cacheTabList.delete(tag.name)
},
freshTabList(tags) {
this.tagList = tags
this.cacheTabList.clear()
// 要先判断ignoreCache
this.tagList
.filter((el) => !el.ignoreCache)
.map((el) => el.name)
.forEach((x) => this.cacheTabList.add(x))
},
resetTabList() {
this.tagList = [DEFAULT_ROUTE]
this.cacheTabList.clear()
this.cacheTabList.add(DEFAULT_ROUTE_NAME)
}
}
})
export default useTabBarStore

View File

@@ -0,0 +1,70 @@
import { defineStore } from "pinia"
import tool from "@/utils/tool"
const defaultTag = [{ name: "dashboard", title: "仪表盘", path: "/dashboard", affix: true }]
const useTagStore = defineStore("tag", {
state: () => ({
tags: !tool.local.get("tags") || tool.local.get("tags").length === 0 ? defaultTag : tool.local.get("tags")
}),
getters: {
currentTag(state) {
return { ...state }
}
},
actions: {
addTag(tag) {
const target = this.tags.find((item) => item.path === tag.path)
if (!target && tag.path) {
this.tags.push(tag)
}
this.updateTagsToLocal()
},
removeTag(tag) {
let index = 0
this.tags.map((item, idx) => {
if (item.path === tag.path && !item.affix) {
if (this.tags[idx + 1]) {
index = idx
} else if (idx > 0) {
index = idx - 1
}
this.tags.splice(idx, 1)
}
})
this.updateTagsToLocal()
return this.tags[index]
},
updateTag(tag) {
this.tags.map((item) => {
if (item.path == tag.path) {
item = Object.assign(item, tag)
}
})
this.updateTagsToLocal()
},
updateTagTitle(path, title) {
this.tags.map((item) => {
if (item.path == path) {
item.customTitle = title
}
})
this.updateTagsToLocal()
},
updateTagsToLocal() {
tool.local.set("tags", this.tags)
},
clearTags() {
this.tags = defaultTag
tool.local.set("tags", defaultTag)
}
}
})
export default useTagStore

View File

@@ -6,6 +6,7 @@ import { useAppStore } from "@/store"
const useUserStore = defineStore("user", {
state: () => ({
username: undefined,
name: undefined,
avatar: undefined,
job: undefined,
@@ -21,7 +22,7 @@ const useUserStore = defineStore("user", {
registrationDate: undefined,
accountId: undefined,
certification: undefined,
role: '',
role: ""
}),
getters: {