首次提交
This commit is contained in:
116
chengduTestPlant/src/store/modules/app.js
Normal file
116
chengduTestPlant/src/store/modules/app.js
Normal file
@@ -0,0 +1,116 @@
|
||||
let defaultSetting = {
|
||||
mode: "light",
|
||||
tag: true,
|
||||
menuCollapse: false,
|
||||
menuWidth: 230,
|
||||
layout: "classic",
|
||||
skin: "mine",
|
||||
i18n: false,
|
||||
language: "zh_CN",
|
||||
animation: "ma-slide-down",
|
||||
color: "#165dff",
|
||||
settingOpen: false,
|
||||
searchOpen: false
|
||||
}
|
||||
|
||||
import { defineStore } from "pinia"
|
||||
import tool from "@/utils/tool"
|
||||
import { generate, getRgbStr } from "@arco-design/color"
|
||||
|
||||
if (!tool.local.get("setting")) {
|
||||
tool.local.set("setting", defaultSetting)
|
||||
} else {
|
||||
defaultSetting = tool.local.get("setting")
|
||||
}
|
||||
|
||||
document.body.setAttribute("arco-theme", defaultSetting.mode)
|
||||
document.body.setAttribute("mine-skin", defaultSetting.skin)
|
||||
|
||||
const useAppStore = defineStore("app", {
|
||||
state: () => ({ ...defaultSetting }),
|
||||
|
||||
getters: {
|
||||
appCurrentSetting(state) {
|
||||
return { ...state }
|
||||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
updateSettings(partial) {
|
||||
this.$patch(partial)
|
||||
},
|
||||
|
||||
toggleMode(dark) {
|
||||
this.mode = dark
|
||||
document.body.setAttribute("arco-theme", this.mode)
|
||||
defaultSetting.mode = this.mode
|
||||
this.changeColor(this.color)
|
||||
tool.local.set("setting", defaultSetting)
|
||||
},
|
||||
|
||||
toggleMenu(status) {
|
||||
this.menuCollapse = status
|
||||
defaultSetting.menuCollapse = this.menuCollapse
|
||||
tool.local.set("setting", defaultSetting)
|
||||
},
|
||||
|
||||
toggleTag(status) {
|
||||
this.tag = status
|
||||
defaultSetting.tag = this.tag
|
||||
tool.local.set("setting", defaultSetting)
|
||||
},
|
||||
|
||||
toggleI18n(i18n) {
|
||||
this.i18n = i18n
|
||||
defaultSetting.i18n = this.i18n
|
||||
tool.local.set("setting", defaultSetting)
|
||||
},
|
||||
|
||||
changeMenuWidth(width) {
|
||||
this.menuWidth = width
|
||||
defaultSetting.menuWidth = this.menuWidth
|
||||
tool.local.set("setting", defaultSetting)
|
||||
},
|
||||
|
||||
changeLayout(layout) {
|
||||
this.layout = layout
|
||||
defaultSetting.layout = this.layout
|
||||
tool.local.set("setting", defaultSetting)
|
||||
},
|
||||
|
||||
changeLanguage(language) {
|
||||
this.language = language
|
||||
defaultSetting.language = this.language
|
||||
tool.local.set("setting", defaultSetting)
|
||||
window.location.reload()
|
||||
},
|
||||
|
||||
changeColor(color) {
|
||||
if (!/^#[0-9A-Za-z]{6}/.test(color)) return
|
||||
this.color = color
|
||||
const list = generate(this.color, { list: true, dark: this.mode === "dark" })
|
||||
list.forEach((color, index) => {
|
||||
const rgbStr = getRgbStr(color)
|
||||
document.body.style.setProperty(`--primary-${index + 1}`, rgbStr)
|
||||
document.body.style.setProperty(`--arcoblue-${index + 1}`, rgbStr)
|
||||
})
|
||||
defaultSetting.color = this.color
|
||||
tool.local.set("setting", defaultSetting)
|
||||
},
|
||||
|
||||
changeAnimation(name) {
|
||||
this.animation = name
|
||||
defaultSetting.animation = this.animation
|
||||
tool.local.set("setting", defaultSetting)
|
||||
},
|
||||
|
||||
useSkin(name) {
|
||||
this.skin = name
|
||||
defaultSetting.skin = this.skin
|
||||
document.body.setAttribute("mine-skin", this.skin)
|
||||
tool.local.set("setting", defaultSetting)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export default useAppStore
|
||||
29
chengduTestPlant/src/store/modules/config.js
Normal file
29
chengduTestPlant/src/store/modules/config.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import { defineStore } from "pinia"
|
||||
|
||||
let defaultConfig = {
|
||||
site_name: "MineAdmin",
|
||||
site_keywords: "",
|
||||
site_desc: "",
|
||||
site_record_number: "",
|
||||
site_copyright: "",
|
||||
site_storage_mode: "",
|
||||
web_close: ""
|
||||
}
|
||||
|
||||
const useConfigStore = defineStore("config", {
|
||||
state: () => ({ ...defaultConfig }),
|
||||
|
||||
getters: {
|
||||
appCurrentConfig(state) {
|
||||
return { ...state }
|
||||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
updateSettings(partial) {
|
||||
this.$patch(partial)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export default useConfigStore
|
||||
24
chengduTestPlant/src/store/modules/doc.js
Normal file
24
chengduTestPlant/src/store/modules/doc.js
Normal file
@@ -0,0 +1,24 @@
|
||||
import { defineStore } from "pinia"
|
||||
|
||||
const useDocStore = defineStore("doc", {
|
||||
state: () => ({
|
||||
auth: undefined,
|
||||
appId: undefined,
|
||||
appSecret: undefined,
|
||||
globalParams: undefined
|
||||
}),
|
||||
|
||||
getters: {
|
||||
setDoc(state) {
|
||||
return { ...state }
|
||||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
setInfo(data) {
|
||||
this.$patch(data)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export default useDocStore
|
||||
24
chengduTestPlant/src/store/modules/form.js
Normal file
24
chengduTestPlant/src/store/modules/form.js
Normal 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
|
||||
48
chengduTestPlant/src/store/modules/iframe.js
Normal file
48
chengduTestPlant/src/store/modules/iframe.js
Normal file
@@ -0,0 +1,48 @@
|
||||
import { defineStore } from "pinia"
|
||||
|
||||
const useIframeStore = defineStore("iframe", {
|
||||
state: () => ({
|
||||
iframes: [],
|
||||
name: null,
|
||||
show: true
|
||||
}),
|
||||
|
||||
getters: {
|
||||
currentIframe(state) {
|
||||
return { ...state }
|
||||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
addIframe(component) {
|
||||
if (!this.iframes.includes(component)) {
|
||||
this.iframes.push(component)
|
||||
}
|
||||
},
|
||||
|
||||
removeIframe(component) {
|
||||
const idx = this.iframes.indexOf(component)
|
||||
if (idx !== -1) {
|
||||
this.iframes.splice(idx, 1)
|
||||
}
|
||||
},
|
||||
|
||||
display() {
|
||||
this.show = true
|
||||
},
|
||||
|
||||
hidden() {
|
||||
this.show = false
|
||||
},
|
||||
|
||||
setName(name) {
|
||||
this.name = name
|
||||
},
|
||||
|
||||
clearIframe() {
|
||||
this.iframes = []
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export default useIframeStore
|
||||
46
chengduTestPlant/src/store/modules/keepAlive.js
Normal file
46
chengduTestPlant/src/store/modules/keepAlive.js
Normal 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
|
||||
23
chengduTestPlant/src/store/modules/message.js
Normal file
23
chengduTestPlant/src/store/modules/message.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import { defineStore } from "pinia"
|
||||
|
||||
let defaultType = {
|
||||
messageList: []
|
||||
}
|
||||
|
||||
const useMessageStore = defineStore("message", {
|
||||
state: () => ({ ...defaultType }),
|
||||
|
||||
getters: {
|
||||
appCurrentMessage(state) {
|
||||
return { ...state }
|
||||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
updateMessage(partial) {
|
||||
this.$patch(partial)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export default useMessageStore
|
||||
70
chengduTestPlant/src/store/modules/tag.js
Normal file
70
chengduTestPlant/src/store/modules/tag.js
Normal 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
|
||||
184
chengduTestPlant/src/store/modules/user.js
Normal file
184
chengduTestPlant/src/store/modules/user.js
Normal file
@@ -0,0 +1,184 @@
|
||||
import { defineStore } from "pinia"
|
||||
import loginApi from "@/api/login"
|
||||
import tool from "@/utils/tool"
|
||||
import router from "@/router"
|
||||
import webRouter from "@/router/webRouter"
|
||||
import { homePage } from "@/router/homePageRoutes"
|
||||
import { useAppStore } from "@/store"
|
||||
|
||||
const useUserStore = defineStore("user", {
|
||||
state: () => ({
|
||||
codes: undefined,
|
||||
roles: undefined,
|
||||
routers: undefined,
|
||||
user: undefined,
|
||||
menus: undefined
|
||||
}),
|
||||
|
||||
getters: {
|
||||
setUserInfo(state) {
|
||||
return { ...state }
|
||||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
setToken(token) {
|
||||
tool.local.set(import.meta.env.VITE_APP_TOKEN_PREFIX, token)
|
||||
},
|
||||
|
||||
getToken() {
|
||||
return tool.local.get(import.meta.env.VITE_APP_TOKEN_PREFIX)
|
||||
},
|
||||
|
||||
clearToken() {
|
||||
tool.local.remove(import.meta.env.VITE_APP_TOKEN_PREFIX)
|
||||
},
|
||||
|
||||
setInfo(data) {
|
||||
this.$patch(data)
|
||||
},
|
||||
|
||||
resetUserInfo() {
|
||||
this.$reset()
|
||||
},
|
||||
|
||||
setMenu(data) {
|
||||
const routers = flatAsyncRoutes(filterAsyncRouter(data))
|
||||
routers.map((item) => router.addRoute("layout", item))
|
||||
},
|
||||
|
||||
// action调用login的getInfo()接口
|
||||
requestUserInfo() {
|
||||
return new Promise((resolve, reject) => {
|
||||
loginApi.getInfo().then((response) => {
|
||||
// 如果没有返回res或者res.data,则调用clearToken()的action
|
||||
// 清除localStorage的token后跳转login
|
||||
if (!response || !response.data) {
|
||||
this.clearToken()
|
||||
router.push({ name: "login" })
|
||||
reject(false)
|
||||
} else {
|
||||
// 如果有数据,则将数据data覆盖state
|
||||
this.setInfo(response.data)
|
||||
// 其实下面步骤就是将homePageRoutes.js上面路由
|
||||
// 放到homePage路由的children里面
|
||||
homePage.children = webRouter[0].children
|
||||
this.setMenu(this.routers)
|
||||
this.routers = removeButtonMenu(this.routers)
|
||||
this.routers.unshift(homePage)
|
||||
this.setApp()
|
||||
resolve(response.data)
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
login(form) {
|
||||
return loginApi
|
||||
.login(form)
|
||||
.then((r) => {
|
||||
if (r.success) {
|
||||
this.setToken(r.data.token)
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
console.error(e)
|
||||
return false
|
||||
})
|
||||
},
|
||||
|
||||
async logout() {
|
||||
await loginApi.logout()
|
||||
tool.local.remove("tags")
|
||||
this.clearToken()
|
||||
this.resetUserInfo()
|
||||
},
|
||||
|
||||
async setApp() {
|
||||
const appStore = useAppStore()
|
||||
const setting = this.user.backend_setting
|
||||
if (setting) {
|
||||
appStore.toggleMode(setting.mode)
|
||||
appStore.toggleMenu(setting.menuCollapse)
|
||||
appStore.toggleTag(setting.tag)
|
||||
appStore.changeMenuWidth(setting.menuWidth)
|
||||
appStore.changeLayout(setting.layout)
|
||||
appStore.useSkin(setting.skin)
|
||||
appStore.changeColor(setting.color)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
// ~~~~~~~~~~~工具函数~~~~~~~~~~~
|
||||
// 路由扁平化
|
||||
const flatAsyncRoutes = (routes, breadcrumb = []) => {
|
||||
let res = []
|
||||
routes.forEach((route) => {
|
||||
const tmp = { ...route }
|
||||
if (tmp.children) {
|
||||
// 如果路由有儿子
|
||||
let childrenBreadcrumb = [...breadcrumb]
|
||||
childrenBreadcrumb.push(route)
|
||||
let tmpRoute = { ...route }
|
||||
tmpRoute.meta.breadcrumb = childrenBreadcrumb
|
||||
delete tmpRoute.children
|
||||
res.push(tmpRoute)
|
||||
let childrenRoutes = flatAsyncRoutes(tmp.children, childrenBreadcrumb)
|
||||
childrenRoutes.map((item) => {
|
||||
res.push(item)
|
||||
})
|
||||
} else {
|
||||
let tmpBreadcrumb = [...breadcrumb]
|
||||
tmpBreadcrumb.push(tmp)
|
||||
tmp.meta.breadcrumb = tmpBreadcrumb
|
||||
res.push(tmp)
|
||||
}
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
const views = import.meta.glob("../../views/**/**.vue")
|
||||
const empty = import.meta.glob("../../layout/empty.vue")
|
||||
|
||||
// 菜单转换路由
|
||||
const filterAsyncRouter = (routerMap) => {
|
||||
const accessedRouters = []
|
||||
routerMap.forEach((item) => {
|
||||
if (item.meta.type !== "B") {
|
||||
if (item.meta.type === "I") {
|
||||
item.meta.url = item.path
|
||||
item.path = `/maIframe/${item.name}`
|
||||
}
|
||||
|
||||
const route = {
|
||||
path: item.path,
|
||||
name: item.name,
|
||||
hidden: item.hidden == 1,
|
||||
meta: item.meta,
|
||||
children: item.children ? filterAsyncRouter(item.children) : null,
|
||||
component: views[`../../views/${item.component}.vue`]
|
||||
}
|
||||
accessedRouters.push(route)
|
||||
}
|
||||
})
|
||||
return accessedRouters
|
||||
}
|
||||
|
||||
// 去除按钮菜单
|
||||
const removeButtonMenu = (routers) => {
|
||||
let handlerAfterRouters = []
|
||||
routers.forEach((item) => {
|
||||
if (item.meta.type !== "B" && !item.meta.hidden) {
|
||||
let route = item
|
||||
if (item.children && item.children.length > 0) {
|
||||
route.children = removeButtonMenu(item.children)
|
||||
}
|
||||
handlerAfterRouters.push(route)
|
||||
}
|
||||
})
|
||||
return handlerAfterRouters
|
||||
}
|
||||
export default useUserStore
|
||||
Reference in New Issue
Block a user