bugfix
This commit is contained in:
@ -1,3 +1,3 @@
|
||||
const store = createPinia()
|
||||
|
||||
export default store
|
||||
const store = createPinia();
|
||||
|
||||
export default store;
|
||||
|
||||
@ -1,47 +1,46 @@
|
||||
import Cookies from 'js-cookie'
|
||||
|
||||
|
||||
const useAppStore = defineStore(
|
||||
'app',
|
||||
{
|
||||
state: () => ({
|
||||
sidebar: {
|
||||
opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true,
|
||||
withoutAnimation: false,
|
||||
hide: false
|
||||
},
|
||||
device: 'desktop',
|
||||
size: Cookies.get('size') || 'default'
|
||||
}),
|
||||
actions: {
|
||||
toggleSideBar(withoutAnimation) {
|
||||
if (this.sidebar.hide) {
|
||||
return false;
|
||||
}
|
||||
this.sidebar.opened = !this.sidebar.opened
|
||||
this.sidebar.withoutAnimation = withoutAnimation
|
||||
if (this.sidebar.opened) {
|
||||
Cookies.set('sidebarStatus', 1)
|
||||
} else {
|
||||
Cookies.set('sidebarStatus', 0)
|
||||
}
|
||||
},
|
||||
closeSideBar(withoutAnimation) {
|
||||
Cookies.set('sidebarStatus', 0)
|
||||
this.sidebar.opened = false
|
||||
this.sidebar.withoutAnimation = withoutAnimation
|
||||
},
|
||||
toggleDevice(device) {
|
||||
this.device = device
|
||||
},
|
||||
setSize(size) {
|
||||
this.size = size;
|
||||
Cookies.set('size', size)
|
||||
},
|
||||
toggleSideBarHide(status) {
|
||||
this.sidebar.hide = status
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export default useAppStore
|
||||
import Cookies from "js-cookie";
|
||||
|
||||
const useAppStore = defineStore("app", {
|
||||
state: () => ({
|
||||
sidebar: {
|
||||
opened: Cookies.get("sidebarStatus")
|
||||
? !!+Cookies.get("sidebarStatus")
|
||||
: true,
|
||||
withoutAnimation: false,
|
||||
hide: false,
|
||||
},
|
||||
device: "desktop",
|
||||
size: Cookies.get("size") || "default",
|
||||
}),
|
||||
actions: {
|
||||
toggleSideBar(withoutAnimation) {
|
||||
if (this.sidebar.hide) {
|
||||
return false;
|
||||
}
|
||||
this.sidebar.opened = !this.sidebar.opened;
|
||||
this.sidebar.withoutAnimation = withoutAnimation;
|
||||
if (this.sidebar.opened) {
|
||||
Cookies.set("sidebarStatus", 1);
|
||||
} else {
|
||||
Cookies.set("sidebarStatus", 0);
|
||||
}
|
||||
},
|
||||
closeSideBar(withoutAnimation) {
|
||||
Cookies.set("sidebarStatus", 0);
|
||||
this.sidebar.opened = false;
|
||||
this.sidebar.withoutAnimation = withoutAnimation;
|
||||
},
|
||||
toggleDevice(device) {
|
||||
this.device = device;
|
||||
},
|
||||
setSize(size) {
|
||||
this.size = size;
|
||||
Cookies.set("size", size);
|
||||
},
|
||||
toggleSideBarHide(status) {
|
||||
this.sidebar.hide = status;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default useAppStore;
|
||||
|
||||
@ -1,138 +1,138 @@
|
||||
import auth from '@/plugins/auth'
|
||||
import router, { constantRoutes, dynamicRoutes } from '@/router'
|
||||
import { getRouters } from '@/api/menu'
|
||||
import Layout from '@/layout/index'
|
||||
import ParentView from '@/components/ParentView'
|
||||
import InnerLink from '@/layout/components/InnerLink'
|
||||
|
||||
// 匹配views里面所有的.vue文件
|
||||
const modules = import.meta.glob('./../../views/**/*.vue')
|
||||
|
||||
const usePermissionStore = defineStore(
|
||||
'permission',
|
||||
{
|
||||
state: () => ({
|
||||
routes: [],
|
||||
addRoutes: [],
|
||||
defaultRoutes: [],
|
||||
topbarRouters: [],
|
||||
sidebarRouters: []
|
||||
}),
|
||||
actions: {
|
||||
setRoutes(routes) {
|
||||
this.addRoutes = routes
|
||||
this.routes = constantRoutes.concat(routes)
|
||||
},
|
||||
setDefaultRoutes(routes) {
|
||||
this.defaultRoutes = constantRoutes.concat(routes)
|
||||
},
|
||||
setTopbarRoutes(routes) {
|
||||
this.topbarRouters = routes
|
||||
},
|
||||
setSidebarRouters(routes) {
|
||||
this.sidebarRouters = routes
|
||||
},
|
||||
generateRoutes(roles) {
|
||||
return new Promise(resolve => {
|
||||
// 向后端请求路由数据
|
||||
getRouters().then(res => {
|
||||
const sdata = JSON.parse(JSON.stringify(res.data))
|
||||
const rdata = JSON.parse(JSON.stringify(res.data))
|
||||
const defaultData = JSON.parse(JSON.stringify(res.data))
|
||||
const sidebarRoutes = filterAsyncRouter(sdata)
|
||||
const rewriteRoutes = filterAsyncRouter(rdata, false, true)
|
||||
const defaultRoutes = filterAsyncRouter(defaultData)
|
||||
const asyncRoutes = filterDynamicRoutes(dynamicRoutes)
|
||||
asyncRoutes.forEach(route => { router.addRoute(route) })
|
||||
this.setRoutes(rewriteRoutes)
|
||||
this.setSidebarRouters(constantRoutes.concat(sidebarRoutes))
|
||||
this.setDefaultRoutes(sidebarRoutes)
|
||||
this.setTopbarRoutes(defaultRoutes)
|
||||
resolve(rewriteRoutes)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// 遍历后台传来的路由字符串,转换为组件对象
|
||||
function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) {
|
||||
return asyncRouterMap.filter(route => {
|
||||
if (type && route.children) {
|
||||
route.children = filterChildren(route.children)
|
||||
}
|
||||
if (route.component) {
|
||||
// Layout ParentView 组件特殊处理
|
||||
if (route.component === 'Layout') {
|
||||
route.component = Layout
|
||||
} else if (route.component === 'ParentView') {
|
||||
route.component = ParentView
|
||||
} else if (route.component === 'InnerLink') {
|
||||
route.component = InnerLink
|
||||
} else {
|
||||
route.component = loadView(route.component)
|
||||
}
|
||||
}
|
||||
if (route.children != null && route.children && route.children.length) {
|
||||
route.children = filterAsyncRouter(route.children, route, type)
|
||||
} else {
|
||||
delete route['children']
|
||||
delete route['redirect']
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
function filterChildren(childrenMap, lastRouter = false) {
|
||||
var children = []
|
||||
childrenMap.forEach((el, index) => {
|
||||
if (el.children && el.children.length) {
|
||||
if (el.component === 'ParentView' && !lastRouter) {
|
||||
el.children.forEach(c => {
|
||||
c.path = el.path + '/' + c.path
|
||||
if (c.children && c.children.length) {
|
||||
children = children.concat(filterChildren(c.children, c))
|
||||
return
|
||||
}
|
||||
children.push(c)
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
if (lastRouter) {
|
||||
el.path = lastRouter.path + '/' + el.path
|
||||
}
|
||||
children = children.concat(el)
|
||||
})
|
||||
return children
|
||||
}
|
||||
|
||||
// 动态路由遍历,验证是否具备权限
|
||||
export function filterDynamicRoutes(routes) {
|
||||
const res = []
|
||||
routes.forEach(route => {
|
||||
if (route.permissions) {
|
||||
if (auth.hasPermiOr(route.permissions)) {
|
||||
res.push(route)
|
||||
}
|
||||
} else if (route.roles) {
|
||||
if (auth.hasRoleOr(route.roles)) {
|
||||
res.push(route)
|
||||
}
|
||||
}
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
export const loadView = (view) => {
|
||||
let res;
|
||||
for (const path in modules) {
|
||||
const dir = path.split('views/')[1].split('.vue')[0];
|
||||
if (dir === view) {
|
||||
res = () => modules[path]();
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
export default usePermissionStore
|
||||
import auth from "@/plugins/auth";
|
||||
import router, { constantRoutes, dynamicRoutes } from "@/router";
|
||||
import { getRouters } from "@/api/menu";
|
||||
import Layout from "@/layout/index";
|
||||
import ParentView from "@/components/ParentView";
|
||||
import InnerLink from "@/layout/components/InnerLink";
|
||||
|
||||
// 匹配views里面所有的.vue文件
|
||||
const modules = import.meta.glob("./../../views/**/*.vue");
|
||||
|
||||
const usePermissionStore = defineStore("permission", {
|
||||
state: () => ({
|
||||
routes: [],
|
||||
addRoutes: [],
|
||||
defaultRoutes: [],
|
||||
topbarRouters: [],
|
||||
sidebarRouters: [],
|
||||
}),
|
||||
actions: {
|
||||
setRoutes(routes) {
|
||||
this.addRoutes = routes;
|
||||
this.routes = constantRoutes.concat(routes);
|
||||
},
|
||||
setDefaultRoutes(routes) {
|
||||
this.defaultRoutes = constantRoutes.concat(routes);
|
||||
},
|
||||
setTopbarRoutes(routes) {
|
||||
this.topbarRouters = routes;
|
||||
},
|
||||
setSidebarRouters(routes) {
|
||||
this.sidebarRouters = routes;
|
||||
},
|
||||
generateRoutes(roles) {
|
||||
return new Promise((resolve) => {
|
||||
// 向后端请求路由数据
|
||||
getRouters().then((res) => {
|
||||
const sdata = JSON.parse(JSON.stringify(res.data));
|
||||
const rdata = JSON.parse(JSON.stringify(res.data));
|
||||
const defaultData = JSON.parse(JSON.stringify(res.data));
|
||||
const sidebarRoutes = filterAsyncRouter(sdata);
|
||||
const rewriteRoutes = filterAsyncRouter(rdata, false, true);
|
||||
const defaultRoutes = filterAsyncRouter(defaultData);
|
||||
const asyncRoutes = filterDynamicRoutes(dynamicRoutes);
|
||||
asyncRoutes.forEach((route) => {
|
||||
router.addRoute(route);
|
||||
});
|
||||
this.setRoutes(rewriteRoutes);
|
||||
this.setSidebarRouters(constantRoutes.concat(sidebarRoutes));
|
||||
this.setDefaultRoutes(sidebarRoutes);
|
||||
this.setTopbarRoutes(defaultRoutes);
|
||||
resolve(rewriteRoutes);
|
||||
});
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// 遍历后台传来的路由字符串,转换为组件对象
|
||||
function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) {
|
||||
return asyncRouterMap.filter((route) => {
|
||||
if (type && route.children) {
|
||||
route.children = filterChildren(route.children);
|
||||
}
|
||||
if (route.component) {
|
||||
// Layout ParentView 组件特殊处理
|
||||
if (route.component === "Layout") {
|
||||
route.component = Layout;
|
||||
} else if (route.component === "ParentView") {
|
||||
route.component = ParentView;
|
||||
} else if (route.component === "InnerLink") {
|
||||
route.component = InnerLink;
|
||||
} else {
|
||||
route.component = loadView(route.component);
|
||||
}
|
||||
}
|
||||
if (route.children != null && route.children && route.children.length) {
|
||||
route.children = filterAsyncRouter(route.children, route, type);
|
||||
} else {
|
||||
delete route["children"];
|
||||
delete route["redirect"];
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
function filterChildren(childrenMap, lastRouter = false) {
|
||||
var children = [];
|
||||
childrenMap.forEach((el, index) => {
|
||||
if (el.children && el.children.length) {
|
||||
if (el.component === "ParentView" && !lastRouter) {
|
||||
el.children.forEach((c) => {
|
||||
c.path = el.path + "/" + c.path;
|
||||
if (c.children && c.children.length) {
|
||||
children = children.concat(filterChildren(c.children, c));
|
||||
return;
|
||||
}
|
||||
children.push(c);
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (lastRouter) {
|
||||
el.path = lastRouter.path + "/" + el.path;
|
||||
}
|
||||
children = children.concat(el);
|
||||
});
|
||||
return children;
|
||||
}
|
||||
|
||||
// 动态路由遍历,验证是否具备权限
|
||||
export function filterDynamicRoutes(routes) {
|
||||
const res = [];
|
||||
routes.forEach((route) => {
|
||||
if (route.permissions) {
|
||||
if (auth.hasPermiOr(route.permissions)) {
|
||||
res.push(route);
|
||||
}
|
||||
} else if (route.roles) {
|
||||
if (auth.hasRoleOr(route.roles)) {
|
||||
res.push(route);
|
||||
}
|
||||
}
|
||||
});
|
||||
return res;
|
||||
}
|
||||
|
||||
export const loadView = (view) => {
|
||||
let res;
|
||||
for (const path in modules) {
|
||||
const dir = path.split("views/")[1].split(".vue")[0];
|
||||
if (dir === view) {
|
||||
res = () => modules[path]();
|
||||
}
|
||||
}
|
||||
return res;
|
||||
};
|
||||
|
||||
export default usePermissionStore;
|
||||
|
||||
@ -1,38 +1,57 @@
|
||||
import defaultSettings from '@/settings'
|
||||
import { useDynamicTitle } from '@/utils/dynamicTitle'
|
||||
|
||||
const { sideTheme, showSettings, topNav, tagsView, fixedHeader, sidebarLogo, dynamicTitle } = defaultSettings
|
||||
|
||||
const storageSetting = JSON.parse(localStorage.getItem('layout-setting')) || ''
|
||||
|
||||
const useSettingsStore = defineStore(
|
||||
'settings',
|
||||
{
|
||||
state: () => ({
|
||||
title: '',
|
||||
theme: storageSetting.theme || '#409EFF',
|
||||
sideTheme: storageSetting.sideTheme || sideTheme,
|
||||
showSettings: showSettings,
|
||||
topNav: storageSetting.topNav === undefined ? topNav : storageSetting.topNav,
|
||||
tagsView: storageSetting.tagsView === undefined ? tagsView : storageSetting.tagsView,
|
||||
fixedHeader: storageSetting.fixedHeader === undefined ? fixedHeader : storageSetting.fixedHeader,
|
||||
sidebarLogo: storageSetting.sidebarLogo === undefined ? sidebarLogo : storageSetting.sidebarLogo,
|
||||
dynamicTitle: storageSetting.dynamicTitle === undefined ? dynamicTitle : storageSetting.dynamicTitle
|
||||
}),
|
||||
actions: {
|
||||
// 修改布局设置
|
||||
changeSetting(data) {
|
||||
const { key, value } = data
|
||||
if (this.hasOwnProperty(key)) {
|
||||
this[key] = value
|
||||
}
|
||||
},
|
||||
// 设置网页标题
|
||||
setTitle(title) {
|
||||
this.title = title
|
||||
useDynamicTitle();
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export default useSettingsStore
|
||||
import defaultSettings from "@/settings";
|
||||
import { useDynamicTitle } from "@/utils/dynamicTitle";
|
||||
|
||||
const {
|
||||
sideTheme,
|
||||
showSettings,
|
||||
topNav,
|
||||
tagsView,
|
||||
fixedHeader,
|
||||
sidebarLogo,
|
||||
dynamicTitle,
|
||||
} = defaultSettings;
|
||||
|
||||
const storageSetting = JSON.parse(localStorage.getItem("layout-setting")) || "";
|
||||
|
||||
const useSettingsStore = defineStore("settings", {
|
||||
state: () => ({
|
||||
title: "",
|
||||
theme: storageSetting.theme || "#409EFF",
|
||||
sideTheme: storageSetting.sideTheme || sideTheme,
|
||||
showSettings: showSettings,
|
||||
topNav:
|
||||
storageSetting.topNav === undefined ? topNav : storageSetting.topNav,
|
||||
tagsView:
|
||||
storageSetting.tagsView === undefined
|
||||
? tagsView
|
||||
: storageSetting.tagsView,
|
||||
fixedHeader:
|
||||
storageSetting.fixedHeader === undefined
|
||||
? fixedHeader
|
||||
: storageSetting.fixedHeader,
|
||||
sidebarLogo:
|
||||
storageSetting.sidebarLogo === undefined
|
||||
? sidebarLogo
|
||||
: storageSetting.sidebarLogo,
|
||||
dynamicTitle:
|
||||
storageSetting.dynamicTitle === undefined
|
||||
? dynamicTitle
|
||||
: storageSetting.dynamicTitle,
|
||||
}),
|
||||
actions: {
|
||||
// 修改布局设置
|
||||
changeSetting(data) {
|
||||
const { key, value } = data;
|
||||
if (this.hasOwnProperty(key)) {
|
||||
this[key] = value;
|
||||
}
|
||||
},
|
||||
// 设置网页标题
|
||||
setTitle(title) {
|
||||
this.title = title;
|
||||
useDynamicTitle();
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default useSettingsStore;
|
||||
|
||||
@ -1,156 +1,154 @@
|
||||
const useTagsViewStore = defineStore(
|
||||
'tags-view',
|
||||
{
|
||||
state: () => ({
|
||||
visitedViews: [],
|
||||
cachedViews: []
|
||||
}),
|
||||
actions: {
|
||||
addView(view) {
|
||||
this.addVisitedView(view)
|
||||
this.addCachedView(view)
|
||||
},
|
||||
addVisitedView(view) {
|
||||
if (this.visitedViews.some(v => v.path === view.path)) return
|
||||
this.visitedViews.push(
|
||||
Object.assign({}, view, {
|
||||
title: view.meta.title || 'no-name'
|
||||
})
|
||||
)
|
||||
},
|
||||
addCachedView(view) {
|
||||
if (this.cachedViews.includes(view.name)) return
|
||||
if (!view.meta.noCache) {
|
||||
this.cachedViews.push(view.name)
|
||||
}
|
||||
},
|
||||
delView(view) {
|
||||
return new Promise(resolve => {
|
||||
this.delVisitedView(view)
|
||||
this.delCachedView(view)
|
||||
resolve({
|
||||
visitedViews: [...this.visitedViews],
|
||||
cachedViews: [...this.cachedViews]
|
||||
})
|
||||
})
|
||||
},
|
||||
delVisitedView(view) {
|
||||
return new Promise(resolve => {
|
||||
for (const [i, v] of this.visitedViews.entries()) {
|
||||
if (v.path === view.path) {
|
||||
this.visitedViews.splice(i, 1)
|
||||
break
|
||||
}
|
||||
}
|
||||
resolve([...this.visitedViews])
|
||||
})
|
||||
},
|
||||
delCachedView(view) {
|
||||
return new Promise(resolve => {
|
||||
const index = this.cachedViews.indexOf(view.name)
|
||||
index > -1 && this.cachedViews.splice(index, 1)
|
||||
resolve([...this.cachedViews])
|
||||
})
|
||||
},
|
||||
delOthersViews(view) {
|
||||
return new Promise(resolve => {
|
||||
this.delOthersVisitedViews(view)
|
||||
this.delOthersCachedViews(view)
|
||||
resolve({
|
||||
visitedViews: [...this.visitedViews],
|
||||
cachedViews: [...this.cachedViews]
|
||||
})
|
||||
})
|
||||
},
|
||||
delOthersVisitedViews(view) {
|
||||
return new Promise(resolve => {
|
||||
this.visitedViews = this.visitedViews.filter(v => {
|
||||
return v.meta.affix || v.path === view.path
|
||||
})
|
||||
resolve([...this.visitedViews])
|
||||
})
|
||||
},
|
||||
delOthersCachedViews(view) {
|
||||
return new Promise(resolve => {
|
||||
const index = this.cachedViews.indexOf(view.name)
|
||||
if (index > -1) {
|
||||
this.cachedViews = this.cachedViews.slice(index, index + 1)
|
||||
} else {
|
||||
this.cachedViews = []
|
||||
}
|
||||
resolve([...this.cachedViews])
|
||||
})
|
||||
},
|
||||
delAllViews(view) {
|
||||
return new Promise(resolve => {
|
||||
this.delAllVisitedViews(view)
|
||||
this.delAllCachedViews(view)
|
||||
resolve({
|
||||
visitedViews: [...this.visitedViews],
|
||||
cachedViews: [...this.cachedViews]
|
||||
})
|
||||
})
|
||||
},
|
||||
delAllVisitedViews(view) {
|
||||
return new Promise(resolve => {
|
||||
const affixTags = this.visitedViews.filter(tag => tag.meta.affix)
|
||||
this.visitedViews = affixTags
|
||||
resolve([...this.visitedViews])
|
||||
})
|
||||
},
|
||||
delAllCachedViews(view) {
|
||||
return new Promise(resolve => {
|
||||
this.cachedViews = []
|
||||
resolve([...this.cachedViews])
|
||||
})
|
||||
},
|
||||
updateVisitedView(view) {
|
||||
for (let v of this.visitedViews) {
|
||||
if (v.path === view.path) {
|
||||
v = Object.assign(v, view)
|
||||
break
|
||||
}
|
||||
}
|
||||
},
|
||||
delRightTags(view) {
|
||||
return new Promise(resolve => {
|
||||
const index = this.visitedViews.findIndex(v => v.path === view.path)
|
||||
if (index === -1) {
|
||||
return
|
||||
}
|
||||
this.visitedViews = this.visitedViews.filter((item, idx) => {
|
||||
if (idx <= index || (item.meta && item.meta.affix)) {
|
||||
return true
|
||||
}
|
||||
const i = this.cachedViews.indexOf(item.name)
|
||||
if (i > -1) {
|
||||
this.cachedViews.splice(i, 1)
|
||||
}
|
||||
return false
|
||||
})
|
||||
resolve([...this.visitedViews])
|
||||
})
|
||||
},
|
||||
delLeftTags(view) {
|
||||
return new Promise(resolve => {
|
||||
const index = this.visitedViews.findIndex(v => v.path === view.path)
|
||||
if (index === -1) {
|
||||
return
|
||||
}
|
||||
this.visitedViews = this.visitedViews.filter((item, idx) => {
|
||||
if (idx >= index || (item.meta && item.meta.affix)) {
|
||||
return true
|
||||
}
|
||||
const i = this.cachedViews.indexOf(item.name)
|
||||
if (i > -1) {
|
||||
this.cachedViews.splice(i, 1)
|
||||
}
|
||||
return false
|
||||
})
|
||||
resolve([...this.visitedViews])
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export default useTagsViewStore
|
||||
const useTagsViewStore = defineStore("tags-view", {
|
||||
state: () => ({
|
||||
visitedViews: [],
|
||||
cachedViews: [],
|
||||
}),
|
||||
actions: {
|
||||
addView(view) {
|
||||
this.addVisitedView(view);
|
||||
this.addCachedView(view);
|
||||
},
|
||||
addVisitedView(view) {
|
||||
if (this.visitedViews.some((v) => v.path === view.path)) return;
|
||||
this.visitedViews.push(
|
||||
Object.assign({}, view, {
|
||||
title: view.meta.title || "no-name",
|
||||
})
|
||||
);
|
||||
},
|
||||
addCachedView(view) {
|
||||
if (this.cachedViews.includes(view.name)) return;
|
||||
if (!view.meta.noCache) {
|
||||
this.cachedViews.push(view.name);
|
||||
}
|
||||
},
|
||||
delView(view) {
|
||||
return new Promise((resolve) => {
|
||||
this.delVisitedView(view);
|
||||
this.delCachedView(view);
|
||||
resolve({
|
||||
visitedViews: [...this.visitedViews],
|
||||
cachedViews: [...this.cachedViews],
|
||||
});
|
||||
});
|
||||
},
|
||||
delVisitedView(view) {
|
||||
return new Promise((resolve) => {
|
||||
for (const [i, v] of this.visitedViews.entries()) {
|
||||
if (v.path === view.path) {
|
||||
this.visitedViews.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
resolve([...this.visitedViews]);
|
||||
});
|
||||
},
|
||||
delCachedView(view) {
|
||||
return new Promise((resolve) => {
|
||||
const index = this.cachedViews.indexOf(view.name);
|
||||
index > -1 && this.cachedViews.splice(index, 1);
|
||||
resolve([...this.cachedViews]);
|
||||
});
|
||||
},
|
||||
delOthersViews(view) {
|
||||
return new Promise((resolve) => {
|
||||
this.delOthersVisitedViews(view);
|
||||
this.delOthersCachedViews(view);
|
||||
resolve({
|
||||
visitedViews: [...this.visitedViews],
|
||||
cachedViews: [...this.cachedViews],
|
||||
});
|
||||
});
|
||||
},
|
||||
delOthersVisitedViews(view) {
|
||||
return new Promise((resolve) => {
|
||||
this.visitedViews = this.visitedViews.filter((v) => {
|
||||
return v.meta.affix || v.path === view.path;
|
||||
});
|
||||
resolve([...this.visitedViews]);
|
||||
});
|
||||
},
|
||||
delOthersCachedViews(view) {
|
||||
return new Promise((resolve) => {
|
||||
const index = this.cachedViews.indexOf(view.name);
|
||||
if (index > -1) {
|
||||
this.cachedViews = this.cachedViews.slice(index, index + 1);
|
||||
} else {
|
||||
this.cachedViews = [];
|
||||
}
|
||||
resolve([...this.cachedViews]);
|
||||
});
|
||||
},
|
||||
delAllViews(view) {
|
||||
return new Promise((resolve) => {
|
||||
this.delAllVisitedViews(view);
|
||||
this.delAllCachedViews(view);
|
||||
resolve({
|
||||
visitedViews: [...this.visitedViews],
|
||||
cachedViews: [...this.cachedViews],
|
||||
});
|
||||
});
|
||||
},
|
||||
delAllVisitedViews(view) {
|
||||
return new Promise((resolve) => {
|
||||
const affixTags = this.visitedViews.filter((tag) => tag.meta.affix);
|
||||
this.visitedViews = affixTags;
|
||||
resolve([...this.visitedViews]);
|
||||
});
|
||||
},
|
||||
delAllCachedViews(view) {
|
||||
return new Promise((resolve) => {
|
||||
this.cachedViews = [];
|
||||
resolve([...this.cachedViews]);
|
||||
});
|
||||
},
|
||||
updateVisitedView(view) {
|
||||
for (let v of this.visitedViews) {
|
||||
if (v.path === view.path) {
|
||||
v = Object.assign(v, view);
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
delRightTags(view) {
|
||||
return new Promise((resolve) => {
|
||||
const index = this.visitedViews.findIndex((v) => v.path === view.path);
|
||||
if (index === -1) {
|
||||
return;
|
||||
}
|
||||
this.visitedViews = this.visitedViews.filter((item, idx) => {
|
||||
if (idx <= index || (item.meta && item.meta.affix)) {
|
||||
return true;
|
||||
}
|
||||
const i = this.cachedViews.indexOf(item.name);
|
||||
if (i > -1) {
|
||||
this.cachedViews.splice(i, 1);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
resolve([...this.visitedViews]);
|
||||
});
|
||||
},
|
||||
delLeftTags(view) {
|
||||
return new Promise((resolve) => {
|
||||
const index = this.visitedViews.findIndex((v) => v.path === view.path);
|
||||
if (index === -1) {
|
||||
return;
|
||||
}
|
||||
this.visitedViews = this.visitedViews.filter((item, idx) => {
|
||||
if (idx >= index || (item.meta && item.meta.affix)) {
|
||||
return true;
|
||||
}
|
||||
const i = this.cachedViews.indexOf(item.name);
|
||||
if (i > -1) {
|
||||
this.cachedViews.splice(i, 1);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
resolve([...this.visitedViews]);
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default useTagsViewStore;
|
||||
|
||||
@ -1,176 +1,179 @@
|
||||
import {getInfo, login, logout} from "@/api/login";
|
||||
import {getToken, removeToken, setToken} from "@/utils/auth";
|
||||
import defAva from "@/assets/images/profile.jpg";
|
||||
import md5 from "js-md5";
|
||||
import {companyList} from "@/api/dataList/enterprise";
|
||||
import {expertList} from "@/api/expert/expert";
|
||||
import {listCasDemand} from "../../api/dataApproval/enterpriseServiceDemand";
|
||||
import {expertAchievementList} from "../../api/dataApproval/achivement";
|
||||
import {businessList} from "../../api/Businessneeds";
|
||||
import {enterpriseProductApprovalList} from "../../api/dataApproval/enterpriseProduct";
|
||||
import {getUnApprovalCount, resetUnApprovalCount,} from "../../api/dataApproval/count";
|
||||
import {casLaboratoryList} from "@/api/dataList/laboratory";
|
||||
|
||||
const useUserStore = defineStore("user", {
|
||||
state: () => ({
|
||||
token: getToken(),
|
||||
name: "",
|
||||
avatar: "",
|
||||
roles: [],
|
||||
permissions: [],
|
||||
unApprovedBusiness: 0,
|
||||
unApprovedExpert: 0,
|
||||
unApprovedAchivement: 0,
|
||||
unApprovedTechnology: 0,
|
||||
unApprovedService: 0,
|
||||
unApprovedProduct: 0,
|
||||
unApprovedLab: 0,
|
||||
serviceDemandTotal: 0,
|
||||
achievementTotal: 0,
|
||||
technologyTotal: 0,
|
||||
productTotal: 0,
|
||||
}),
|
||||
actions: {
|
||||
// 登录
|
||||
login(userInfo) {
|
||||
const username = userInfo.username.trim();
|
||||
const password = md5(userInfo.password);
|
||||
const code = userInfo.code;
|
||||
const uuid = userInfo.uuid;
|
||||
return new Promise((resolve, reject) => {
|
||||
login(username, password, code, uuid)
|
||||
.then((res) => {
|
||||
setToken(res.token);
|
||||
this.token = res.token;
|
||||
resolve();
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
},
|
||||
// 获取用户信息
|
||||
getInfo() {
|
||||
return new Promise((resolve, reject) => {
|
||||
getInfo()
|
||||
.then((res) => {
|
||||
const user = res.user;
|
||||
const avatar =
|
||||
user.avatar == "" || user.avatar == null
|
||||
? defAva
|
||||
: import.meta.env.VITE_APP_BASE_API + user.avatar;
|
||||
|
||||
if (res.roles && res.roles.length > 0) {
|
||||
// 验证返回的roles是否是一个非空数组
|
||||
this.roles = res.roles;
|
||||
this.permissions = res.permissions;
|
||||
} else {
|
||||
this.roles = ["ROLE_DEFAULT"];
|
||||
}
|
||||
this.name = user.userName;
|
||||
this.avatar = avatar;
|
||||
resolve(res);
|
||||
// return res;
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
async getApprovalCount() {
|
||||
this.getUnApprovedBusiness();
|
||||
this.getUnApprovedExpert();
|
||||
this.getUnApprovedAchivement();
|
||||
this.getUnApprovedTechnology();
|
||||
this.getUnApprovedService();
|
||||
this.getUnApprovedProduct();
|
||||
this.getServiceDemandTotal();
|
||||
this.getAchievementTotal();
|
||||
this.getProductTotal();
|
||||
this.getTechnologyTotal();
|
||||
this.getUnApprovedLab()
|
||||
},
|
||||
|
||||
async resetUnApproval(name, field) {
|
||||
await resetUnApprovalCount(name);
|
||||
this[field] = 0;
|
||||
},
|
||||
|
||||
async getUnApprovedBusiness() {
|
||||
const resp = await companyList({
|
||||
examineStatus: 0,
|
||||
pageSize: 1,
|
||||
pageNum: 10,
|
||||
});
|
||||
this.unApprovedBusiness = resp.total;
|
||||
},
|
||||
async getUnApprovedExpert() {
|
||||
const resp = await expertList({
|
||||
examineStatus: 0,
|
||||
pageSize: 1,
|
||||
pageNum: 10,
|
||||
});
|
||||
this.unApprovedExpert = resp.total;
|
||||
},
|
||||
async getUnApprovedAchivement() {
|
||||
const resp = await getUnApprovalCount("achievement");
|
||||
this.unApprovedAchivement = resp.data ?? 0;
|
||||
},
|
||||
async getUnApprovedTechnology() {
|
||||
const resp = await getUnApprovalCount("technology");
|
||||
this.unApprovedTechnology = resp.data ?? 0;
|
||||
},
|
||||
async getUnApprovedService() {
|
||||
const resp = await getUnApprovalCount("service");
|
||||
this.unApprovedService = resp.data ?? 0;
|
||||
},
|
||||
async getUnApprovedProduct() {
|
||||
const resp = await getUnApprovalCount("product");
|
||||
this.unApprovedProduct = resp.data ?? 0;
|
||||
},
|
||||
|
||||
async getServiceDemandTotal() {
|
||||
const resp = await listCasDemand();
|
||||
this.serviceDemandTotal = resp.total;
|
||||
},
|
||||
async getAchievementTotal() {
|
||||
const resp = await expertAchievementList();
|
||||
this.achievementTotal = resp.total;
|
||||
},
|
||||
async getTechnologyTotal() {
|
||||
const resp = await businessList();
|
||||
this.technologyTotal = resp.total;
|
||||
},
|
||||
async getProductTotal() {
|
||||
const resp = await enterpriseProductApprovalList();
|
||||
this.productTotal = resp.total;
|
||||
},
|
||||
async getUnApprovedLab() {
|
||||
const resp = await casLaboratoryList({
|
||||
examineStatus: 0,
|
||||
pageSize: 1,
|
||||
pageNum: 10,
|
||||
});
|
||||
this.unApprovedBusiness = resp.total;
|
||||
},
|
||||
// 退出系统
|
||||
logOut() {
|
||||
return new Promise((resolve, reject) => {
|
||||
logout(this.token)
|
||||
.then(() => {
|
||||
this.token = "";
|
||||
this.roles = [];
|
||||
this.permissions = [];
|
||||
removeToken();
|
||||
resolve();
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default useUserStore;
|
||||
import { getInfo, login, logout } from "@/api/login";
|
||||
import { getToken, removeToken, setToken } from "@/utils/auth";
|
||||
import defAva from "@/assets/images/profile.jpg";
|
||||
import md5 from "js-md5";
|
||||
import { companyList } from "@/api/dataList/enterprise";
|
||||
import { expertList } from "@/api/expert/expert";
|
||||
import { listCasDemand } from "../../api/dataApproval/enterpriseServiceDemand";
|
||||
import { expertAchievementList } from "../../api/dataApproval/achivement";
|
||||
import { businessList } from "../../api/Businessneeds";
|
||||
import { enterpriseProductApprovalList } from "../../api/dataApproval/enterpriseProduct";
|
||||
import {
|
||||
getUnApprovalCount,
|
||||
resetUnApprovalCount,
|
||||
} from "../../api/dataApproval/count";
|
||||
import { casLaboratoryList } from "@/api/dataList/laboratory";
|
||||
|
||||
const useUserStore = defineStore("user", {
|
||||
state: () => ({
|
||||
token: getToken(),
|
||||
name: "",
|
||||
avatar: "",
|
||||
roles: [],
|
||||
permissions: [],
|
||||
unApprovedBusiness: 0,
|
||||
unApprovedExpert: 0,
|
||||
unApprovedAchivement: 0,
|
||||
unApprovedTechnology: 0,
|
||||
unApprovedService: 0,
|
||||
unApprovedProduct: 0,
|
||||
unApprovedLab: 0,
|
||||
serviceDemandTotal: 0,
|
||||
achievementTotal: 0,
|
||||
technologyTotal: 0,
|
||||
productTotal: 0,
|
||||
}),
|
||||
actions: {
|
||||
// 登录
|
||||
login(userInfo) {
|
||||
const username = userInfo.username.trim();
|
||||
const password = md5(userInfo.password);
|
||||
const code = userInfo.code;
|
||||
const uuid = userInfo.uuid;
|
||||
return new Promise((resolve, reject) => {
|
||||
login(username, password, code, uuid)
|
||||
.then((res) => {
|
||||
setToken(res.token);
|
||||
this.token = res.token;
|
||||
resolve();
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
},
|
||||
// 获取用户信息
|
||||
getInfo() {
|
||||
return new Promise((resolve, reject) => {
|
||||
getInfo()
|
||||
.then((res) => {
|
||||
const user = res.user;
|
||||
const avatar =
|
||||
user.avatar == "" || user.avatar == null
|
||||
? defAva
|
||||
: import.meta.env.VITE_APP_BASE_API + user.avatar;
|
||||
|
||||
if (res.roles && res.roles.length > 0) {
|
||||
// 验证返回的roles是否是一个非空数组
|
||||
this.roles = res.roles;
|
||||
this.permissions = res.permissions;
|
||||
} else {
|
||||
this.roles = ["ROLE_DEFAULT"];
|
||||
}
|
||||
this.name = user.userName;
|
||||
this.avatar = avatar;
|
||||
resolve(res);
|
||||
// return res;
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
async getApprovalCount() {
|
||||
this.getUnApprovedBusiness();
|
||||
this.getUnApprovedExpert();
|
||||
this.getUnApprovedAchivement();
|
||||
this.getUnApprovedTechnology();
|
||||
this.getUnApprovedService();
|
||||
this.getUnApprovedProduct();
|
||||
this.getServiceDemandTotal();
|
||||
this.getAchievementTotal();
|
||||
this.getProductTotal();
|
||||
this.getTechnologyTotal();
|
||||
this.getUnApprovedLab();
|
||||
},
|
||||
|
||||
async resetUnApproval(name, field) {
|
||||
await resetUnApprovalCount(name);
|
||||
this[field] = 0;
|
||||
},
|
||||
|
||||
async getUnApprovedBusiness() {
|
||||
const resp = await companyList({
|
||||
examineStatus: 0,
|
||||
pageSize: 1,
|
||||
pageNum: 10,
|
||||
});
|
||||
this.unApprovedBusiness = resp.total;
|
||||
},
|
||||
async getUnApprovedExpert() {
|
||||
const resp = await expertList({
|
||||
examineStatus: 0,
|
||||
pageSize: 1,
|
||||
pageNum: 10,
|
||||
});
|
||||
this.unApprovedExpert = resp.total;
|
||||
},
|
||||
async getUnApprovedAchivement() {
|
||||
const resp = await getUnApprovalCount("achievement");
|
||||
this.unApprovedAchivement = resp.data ?? 0;
|
||||
},
|
||||
async getUnApprovedTechnology() {
|
||||
const resp = await getUnApprovalCount("technology");
|
||||
this.unApprovedTechnology = resp.data ?? 0;
|
||||
},
|
||||
async getUnApprovedService() {
|
||||
const resp = await getUnApprovalCount("service");
|
||||
this.unApprovedService = resp.data ?? 0;
|
||||
},
|
||||
async getUnApprovedProduct() {
|
||||
const resp = await getUnApprovalCount("product");
|
||||
this.unApprovedProduct = resp.data ?? 0;
|
||||
},
|
||||
|
||||
async getServiceDemandTotal() {
|
||||
const resp = await listCasDemand();
|
||||
this.serviceDemandTotal = resp.total;
|
||||
},
|
||||
async getAchievementTotal() {
|
||||
const resp = await expertAchievementList();
|
||||
this.achievementTotal = resp.total;
|
||||
},
|
||||
async getTechnologyTotal() {
|
||||
const resp = await businessList();
|
||||
this.technologyTotal = resp.total;
|
||||
},
|
||||
async getProductTotal() {
|
||||
const resp = await enterpriseProductApprovalList();
|
||||
this.productTotal = resp.total;
|
||||
},
|
||||
async getUnApprovedLab() {
|
||||
const resp = await casLaboratoryList({
|
||||
examineStatus: 0,
|
||||
pageSize: 1,
|
||||
pageNum: 10,
|
||||
});
|
||||
this.unApprovedBusiness = resp.total;
|
||||
},
|
||||
// 退出系统
|
||||
logOut() {
|
||||
return new Promise((resolve, reject) => {
|
||||
logout(this.token)
|
||||
.then(() => {
|
||||
this.token = "";
|
||||
this.roles = [];
|
||||
this.permissions = [];
|
||||
removeToken();
|
||||
resolve();
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default useUserStore;
|
||||
|
||||
Reference in New Issue
Block a user