feat: 初始化
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { changeColor } from "@/utils/themeUtil";
|
||||
import config from "@/config";
|
||||
import { message } from "ant-design-vue";
|
||||
import tool from "@/utils/tool";
|
||||
|
||||
const toolDataGet = (key) => {
|
||||
return tool.data.get(key);
|
||||
};
|
||||
|
||||
// 获取缓存中的,如果取不到那就用配置的
|
||||
const getCacheConfig = (value) => {
|
||||
const data = toolDataGet(value);
|
||||
if (data === null) {
|
||||
return config[value];
|
||||
}
|
||||
return data;
|
||||
};
|
||||
|
||||
/**
|
||||
* deprecated 请使用 useGlobalStore
|
||||
*/
|
||||
export const globalStore = defineStore({
|
||||
id: "global",
|
||||
state: () => ({
|
||||
// 布局
|
||||
layout: getCacheConfig("LAYOUT"),
|
||||
// 菜单是否折叠 toggle
|
||||
menuIsCollapse: getCacheConfig("MENU_COLLAPSE"),
|
||||
// 侧边菜单是否排他展开
|
||||
sideUniqueOpen: getCacheConfig("SIDE_UNIQUE_OPEN"),
|
||||
// 多标签栏
|
||||
layoutTagsOpen: getCacheConfig("LAYOUT_TAGS_OPEN"),
|
||||
// 是否展示面包屑
|
||||
breadcrumbOpen: getCacheConfig("BREADCRUMD_OPEN"),
|
||||
// 顶栏是否应用主题色
|
||||
topHanderThemeColorOpen: getCacheConfig("TOP_HANDER_THEME_COLOR_OPEN"),
|
||||
// 顶栏主题色通栏
|
||||
topHanderThemeColorSpread: getCacheConfig("TOP_HANDER_THEME_COLOR_SPREAD"),
|
||||
// 模块坞
|
||||
moduleUnfoldOpen: getCacheConfig("MODULE_UNFOLD_OPEN"),
|
||||
// 主题
|
||||
theme: getCacheConfig("THEME"),
|
||||
// 主题颜色
|
||||
themeColor: toolDataGet("THEME_COLOR") || config.COLOR,
|
||||
// 整体表单风格
|
||||
formStyle: getCacheConfig("FORM_STYLE"),
|
||||
// 用户信息
|
||||
userInfo: toolDataGet("USER_INFO") || {},
|
||||
// 系统配置
|
||||
sysBaseConfig: toolDataGet("SYS_BASE_CONFIG") || config.SYS_BASE_CONFIG
|
||||
}),
|
||||
getters: {
|
||||
getPrimaryColor() {
|
||||
return this.themeColor;
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
setLayout(key) {
|
||||
this.layout = key;
|
||||
},
|
||||
setTheme(key) {
|
||||
this.theme = key;
|
||||
const closeMessage = message.loading(`加载中...`);
|
||||
changeColor(this.themeColor, key).then(closeMessage);
|
||||
},
|
||||
setThemeColor(key) {
|
||||
this.themeColor = key;
|
||||
const closeMessage = message.loading(`加载中...`);
|
||||
changeColor(key, this.theme).then(closeMessage);
|
||||
},
|
||||
initTheme() {
|
||||
const closeMessage = message.loading(`加载中...`);
|
||||
changeColor(this.themeColor, this.theme).then(closeMessage)
|
||||
},
|
||||
toggleConfig(key) {
|
||||
this[key] = !this[key];
|
||||
},
|
||||
setFormStyle(key) {
|
||||
this.formStyle = key;
|
||||
},
|
||||
setUserInfo(key) {
|
||||
this.userInfo = key;
|
||||
},
|
||||
setSysBaseConfig(key) {
|
||||
this.sysBaseConfig = key;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export const useGlobalStore = globalStore;
|
||||
@@ -0,0 +1,43 @@
|
||||
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
export const iframeStore = defineStore({
|
||||
id: 'iframe',
|
||||
state: () => ({
|
||||
iframeList: []
|
||||
}),
|
||||
getters: {},
|
||||
actions: {
|
||||
setIframeList(route) {
|
||||
this.iframeList = []
|
||||
this.iframeList.push(route)
|
||||
},
|
||||
pushIframeList(route) {
|
||||
const target = this.iframeList.find((item) => item.path === route.path)
|
||||
if (!target) {
|
||||
this.iframeList.push(route)
|
||||
}
|
||||
},
|
||||
removeIframeList(route) {
|
||||
this.iframeList.forEach((item, index) => {
|
||||
if (item.path === route.path) {
|
||||
this.iframeList.splice(index, 1)
|
||||
}
|
||||
})
|
||||
},
|
||||
refreshIframe(route) {
|
||||
this.iframeList.forEach((item) => {
|
||||
if (item.path === route.path) {
|
||||
const url = route.meta.url
|
||||
item.meta.url = ''
|
||||
setTimeout(() => {
|
||||
item.meta.url = url
|
||||
}, 200)
|
||||
}
|
||||
})
|
||||
},
|
||||
clearIframeList() {
|
||||
this.iframeList = []
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
export * from './global'
|
||||
export * from './search'
|
||||
export * from './iframe'
|
||||
export * from './keepAlive'
|
||||
export * from './viewTags'
|
||||
@@ -0,0 +1,37 @@
|
||||
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
export const keepAliveStore = defineStore({
|
||||
id: 'keepAlive',
|
||||
state: () => ({
|
||||
keepLiveRoute: [],
|
||||
routeKey: null,
|
||||
routeShow: true
|
||||
}),
|
||||
getters: {},
|
||||
actions: {
|
||||
pushKeepLive(component) {
|
||||
if (!this.keepLiveRoute.includes(component)) {
|
||||
this.keepLiveRoute.push(component)
|
||||
}
|
||||
},
|
||||
removeKeepLive(component) {
|
||||
const index = this.keepLiveRoute.indexOf(component)
|
||||
if (index !== -1) {
|
||||
this.keepLiveRoute.splice(index, 1)
|
||||
}
|
||||
},
|
||||
clearKeepLive() {
|
||||
this.keepLiveRoute = []
|
||||
},
|
||||
setRouteKey(key) {
|
||||
this.routeKey = key
|
||||
},
|
||||
setRouteShow(key) {
|
||||
this.routeShow = key
|
||||
},
|
||||
setRouteKeyAction(key) {
|
||||
this.setRouteKey(key)
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,57 @@
|
||||
import '@/utils/objects'
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
export const searchStore = defineStore({
|
||||
id: 'search',
|
||||
state: () => ({
|
||||
active: false,
|
||||
hotkey: {
|
||||
open: 's',
|
||||
close: 'esc'
|
||||
},
|
||||
pool: []
|
||||
}),
|
||||
getters: {},
|
||||
actions: {
|
||||
toggleActive() {
|
||||
this.active = !this.active
|
||||
},
|
||||
setActive(active) {
|
||||
this.active = active
|
||||
},
|
||||
init(menu) {
|
||||
const pool = []
|
||||
const getFullName = function (meta) {
|
||||
if (meta.breadcrumb) {
|
||||
let list = []
|
||||
meta.breadcrumb.forEach((item) => {
|
||||
list.push(item.meta.title)
|
||||
})
|
||||
return list.join(' / ')
|
||||
}
|
||||
return meta.title
|
||||
}
|
||||
const push = function (menu) {
|
||||
menu.forEach((m) => {
|
||||
if ('menu' === m.meta.type) {
|
||||
if (m.children) {
|
||||
push(m.children)
|
||||
} else if (m.children === null) {
|
||||
pool.push({
|
||||
icon: m.meta.icon,
|
||||
path: m.path,
|
||||
fullPath: m.path,
|
||||
name: m.meta.title,
|
||||
fullName: getFullName(m.meta),
|
||||
namePinyin: m.meta.title.toPinyin(),
|
||||
namePinyinFirst: m.meta.title.toPinyin(true)
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
push(menu)
|
||||
this.pool = pool
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,30 @@
|
||||
|
||||
import configApi from '@/api/sys/dev/configApi'
|
||||
import { message } from 'ant-design-vue'
|
||||
|
||||
const formData = ref({
|
||||
SYS_LOGO: '',
|
||||
SYS_BACK_IMAGE: '',
|
||||
SYS_NAME: '',
|
||||
SYS_VERSION: '',
|
||||
SYS_COPYRIGHT: '',
|
||||
SYS_COPYRIGHT_URL: '',
|
||||
SYS_DEFAULT_FILE_ENGINE: 'LOCAL',
|
||||
SYS_DEFAULT_PASSWORD: ''
|
||||
})
|
||||
|
||||
const param = {
|
||||
category: 'SYS_BASE'
|
||||
}
|
||||
|
||||
const getSysBaseConfig = () => {
|
||||
configApi.configList(param).then((data) => {
|
||||
if (data) {
|
||||
data.forEach((item) => {
|
||||
formData.value[item.configKey] = item.configValue ? '' : item.configValue
|
||||
})
|
||||
} else {
|
||||
message.warning('表单项不存在,请初始化数据库')
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
export const viewTagsStore = defineStore({
|
||||
id: 'viewTags',
|
||||
state: () => ({
|
||||
viewTags: []
|
||||
}),
|
||||
getters: {},
|
||||
actions: {
|
||||
pushViewTags(route) {
|
||||
const target = this.viewTags.find((item) => item.fullPath === route.fullPath)
|
||||
const isName = route.name
|
||||
if (!target && isName) {
|
||||
this.viewTags.push(route)
|
||||
}
|
||||
},
|
||||
removeViewTags(route) {
|
||||
this.viewTags.forEach((item, index) => {
|
||||
if (item.fullPath === route.fullPath) {
|
||||
this.viewTags.splice(index, 1)
|
||||
}
|
||||
})
|
||||
},
|
||||
updateViewTags(route) {
|
||||
this.viewTags.forEach((item) => {
|
||||
if (item.fullPath == route.fullPath) {
|
||||
Object.assign(item, route)
|
||||
}
|
||||
})
|
||||
},
|
||||
updateViewTagsTitle(title = '') {
|
||||
const nowFullPath = location.hash.substring(1)
|
||||
this.viewTags.forEach((item) => {
|
||||
if (item.fullPath == nowFullPath) {
|
||||
item.meta.title = title
|
||||
}
|
||||
})
|
||||
},
|
||||
clearViewTags() {
|
||||
this.viewTags = []
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user