更新uniapp和platform
This commit is contained in:
1 parent
31ae07175d
commit
7f9a66da0f
47 files changed
+5207
-1974
No files matched your search
Vendored
+2
@@ -11,6 +11,7 @@ export {}
|
||||
/* prettier-ignore */
|
||||
declare module 'vue' {
|
||||
export interface GlobalComponents {
|
||||
AsideMenuItem: typeof import('./src/components/AsideMenuItem.vue')['default']
|
||||
CommonAside: typeof import('./src/components/CommonAside.vue')['default']
|
||||
CommonHeader: typeof import('./src/components/CommonHeader.vue')['default']
|
||||
ElAlert: typeof import('element-plus/es')['ElAlert']
|
||||
@@ -79,6 +80,7 @@ declare module 'vue' {
|
||||
ElTreeSelect: typeof import('element-plus/es')['ElTreeSelect']
|
||||
ElUpload: typeof import('element-plus/es')['ElUpload']
|
||||
FlowCanvas: typeof import('./src/components/approval/FlowCanvas.vue')['default']
|
||||
MenuIcon: typeof import('./src/components/MenuIcon.vue')['default']
|
||||
RouterLink: typeof import('vue-router')['RouterLink']
|
||||
RouterView: typeof import('vue-router')['RouterView']
|
||||
}
|
||||
|
||||
@@ -1,18 +1,9 @@
|
||||
// 数据统计相关API
|
||||
import request from "@/utils/request";
|
||||
|
||||
// 获取内容统计
|
||||
export function getContentStats() {
|
||||
// 用户 / 租户统计(真实数据,取自租户端用户表、租户表与登录日志)
|
||||
export function getPlatformUserAnalytics() {
|
||||
return request({
|
||||
url: "/platform/contentstats",
|
||||
url: "/platform/analytics/users",
|
||||
method: "get",
|
||||
});
|
||||
}
|
||||
|
||||
// 获取用户统计
|
||||
export function getUserStats() {
|
||||
return request({
|
||||
url: "/platform/usersstats",
|
||||
method: "get",
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import request from "@/utils/request";
|
||||
|
||||
// ==================== 附件空间套餐(平台端维护) ====================
|
||||
|
||||
export function getStoragePackages() {
|
||||
return request({
|
||||
url: "/platform/storage/packages",
|
||||
method: "get",
|
||||
});
|
||||
}
|
||||
|
||||
export function createStoragePackage(data) {
|
||||
return request({
|
||||
url: "/platform/storage/package/create",
|
||||
method: "post",
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
export function updateStoragePackage(id, data) {
|
||||
return request({
|
||||
url: `/platform/storage/package/${id}`,
|
||||
method: "post",
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
export function toggleStoragePackage(id, status) {
|
||||
return request({
|
||||
url: `/platform/storage/package/${id}/status`,
|
||||
method: "post",
|
||||
data: { status },
|
||||
});
|
||||
}
|
||||
|
||||
export function deleteStoragePackage(id) {
|
||||
return request({
|
||||
url: `/platform/storage/package/${id}/delete`,
|
||||
method: "delete",
|
||||
});
|
||||
}
|
||||
|
||||
// ==================== 租户空间用量 / 基础额度 ====================
|
||||
|
||||
export function getTenantStorageInfo(tid) {
|
||||
return request({
|
||||
url: `/platform/storage/tenant/${tid}`,
|
||||
method: "get",
|
||||
});
|
||||
}
|
||||
|
||||
export function updateTenantStorageQuota(tid, storageQuotaMB) {
|
||||
return request({
|
||||
url: `/platform/storage/tenant/${tid}/quota`,
|
||||
method: "post",
|
||||
data: { storage_quota_mb: storageQuotaMB },
|
||||
});
|
||||
}
|
||||
|
||||
// ==================== 购买记录 ====================
|
||||
|
||||
export function getStorageOrders(params = {}) {
|
||||
return request({
|
||||
url: "/platform/storage/orders",
|
||||
method: "get",
|
||||
params,
|
||||
});
|
||||
}
|
||||
@@ -35,3 +35,12 @@ export function deleteTenantUser(id) {
|
||||
});
|
||||
}
|
||||
|
||||
/** 查询指定租户的组织架构(部门下拉用) */
|
||||
export function getTenantOrganizations(tid) {
|
||||
return request({
|
||||
url: "/platform/tenantUser/orgs",
|
||||
method: "get",
|
||||
params: { tid },
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,12 +1,51 @@
|
||||
// Element Plus Message z-index
|
||||
// 全局主题:浅蓝白后台框架
|
||||
// 自定义变量供顶栏 / 侧栏 / 内容区统一取色,Element Plus 主色同步收敛。
|
||||
:root {
|
||||
--el-message-z-index: 9999;
|
||||
|
||||
--el-color-primary: #2f6bff;
|
||||
--el-color-primary-light-3: #6f97ff;
|
||||
--el-color-primary-light-5: #97b5ff;
|
||||
--el-color-primary-light-7: #c5d8ff;
|
||||
--el-color-primary-light-8: #dce7ff;
|
||||
--el-color-primary-light-9: #eef4ff;
|
||||
--el-color-primary-dark-2: #2555cc;
|
||||
|
||||
--yz-primary: #2f6bff;
|
||||
--yz-primary-soft: #eef4ff;
|
||||
--yz-primary-softer: #f6f9ff;
|
||||
--yz-header-bg: #ffffff;
|
||||
--yz-aside-bg: #ffffff;
|
||||
--yz-page-bg: #f4f7fd;
|
||||
--yz-card-bg: #ffffff;
|
||||
--yz-border: #e8edf7;
|
||||
--yz-text: #24304a;
|
||||
--yz-text-regular: #5b6785;
|
||||
--yz-text-muted: #93a0b8;
|
||||
--yz-shadow: 0 2px 12px rgba(31, 61, 130, 0.06);
|
||||
--yz-header-height: 64px;
|
||||
}
|
||||
|
||||
// 暗色模式:只覆盖框架自定义变量,Element Plus 变量交给官方 dark css-vars
|
||||
html.dark {
|
||||
--yz-primary: #6f97ff;
|
||||
--yz-primary-soft: rgba(64, 110, 220, 0.2);
|
||||
--yz-primary-softer: rgba(64, 110, 220, 0.12);
|
||||
--yz-header-bg: #1b1f2b;
|
||||
--yz-aside-bg: #1b1f2b;
|
||||
--yz-page-bg: #131720;
|
||||
--yz-card-bg: #1f2431;
|
||||
--yz-border: #2c3344;
|
||||
--yz-text: #e8ecf6;
|
||||
--yz-text-regular: #b9c2d6;
|
||||
--yz-text-muted: #8692ac;
|
||||
--yz-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
// body 样式
|
||||
body {
|
||||
// background-color: #f5f7fa;
|
||||
color: #303133;
|
||||
color: var(--yz-text);
|
||||
background-color: var(--yz-page-bg);
|
||||
transition: background-color 0.3s ease, color 0.3s ease;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<template>
|
||||
<el-menu-item
|
||||
v-if="!item.children || item.children.length === 0"
|
||||
:index="item.path || String(item.id)"
|
||||
:class="{ 'is-locked': item.locked }"
|
||||
>
|
||||
<MenuIcon :icon="item.icon" />
|
||||
<template #title>
|
||||
<span>{{ item.title }}</span>
|
||||
<i v-if="item.locked" class="fa-solid fa-lock lock-badge"></i>
|
||||
</template>
|
||||
</el-menu-item>
|
||||
|
||||
<el-sub-menu
|
||||
v-else
|
||||
:index="item.path || String(item.id)"
|
||||
teleported
|
||||
:class="{ 'is-locked': item.locked }"
|
||||
>
|
||||
<template #title>
|
||||
<MenuIcon :icon="item.icon" />
|
||||
<span>{{ item.title }}</span>
|
||||
<i v-if="item.locked" class="fa-solid fa-lock lock-badge"></i>
|
||||
</template>
|
||||
<AsideMenuItem
|
||||
v-for="child in item.children"
|
||||
:key="child.id"
|
||||
:item="child"
|
||||
/>
|
||||
</el-sub-menu>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import MenuIcon from "@/components/MenuIcon.vue";
|
||||
|
||||
defineOptions({ name: "AsideMenuItem" });
|
||||
|
||||
defineProps({
|
||||
item: { type: Object, required: true },
|
||||
});
|
||||
</script>
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,37 @@
|
||||
<template>
|
||||
<i v-if="isFontAwesome" :class="icon" class="menu-icon"></i>
|
||||
<el-icon v-else class="menu-icon">
|
||||
<component :is="elementIconName" />
|
||||
</el-icon>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, getCurrentInstance } from "vue";
|
||||
|
||||
const props = defineProps({
|
||||
icon: { type: String, default: "" },
|
||||
});
|
||||
|
||||
const instance = getCurrentInstance();
|
||||
const isFontAwesome = computed(() => /fa-|(^|\s)fa[srlb]?\s/.test(props.icon || ""));
|
||||
|
||||
// main.js 已把所有 Element Plus 图标全局注册;数据库里存的是图标组件名,
|
||||
// 未能识别时统一回退到 Grid,避免渲染出空白图标。
|
||||
const elementIconName = computed(() => {
|
||||
const name = props.icon || "Grid";
|
||||
const components = instance?.appContext?.components || {};
|
||||
return components[name] ? name : "Grid";
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.menu-icon {
|
||||
flex-shrink: 0;
|
||||
margin-right: 8px;
|
||||
font-size: 16px;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
text-align: center;
|
||||
color: inherit;
|
||||
}
|
||||
</style>
|
||||
@@ -104,7 +104,7 @@ const staticMainChildren = [
|
||||
}
|
||||
];
|
||||
|
||||
// 静态路由:登录页独立、home 导航门户独立、404 页面独立
|
||||
// 静态路由:登录页独立、404 页面独立(Main 布局路由单独定义,见 mainRoute)
|
||||
const staticRoutes = [
|
||||
{
|
||||
path: "/login",
|
||||
@@ -129,27 +129,43 @@ const staticRoutes = [
|
||||
{
|
||||
path: "/apps/erp/dashborad",
|
||||
redirect: "/apps/erp/dashboard"
|
||||
},
|
||||
{
|
||||
path: "/:pathMatch(.*)*",
|
||||
name: "NotFound",
|
||||
component: () => import("@/views/404/404.vue"),
|
||||
meta: { requiresAuth: false }
|
||||
}
|
||||
];
|
||||
|
||||
const notFoundRoute = {
|
||||
path: "/:pathMatch(.*)*",
|
||||
name: "NotFound",
|
||||
component: () => import("@/views/404/404.vue"),
|
||||
meta: { requiresAuth: false }
|
||||
};
|
||||
|
||||
// 主布局路由必须随应用一起注册:/home、/user/userProfile 等静态页面
|
||||
// 不能等菜单接口返回后才存在。否则菜单接口失败或返回空数组时,
|
||||
// 登录后跳转 /home 会命中 404 兜底路由(URL 停在 /#/home)。
|
||||
const mainRoute = {
|
||||
path: "/",
|
||||
name: "Main",
|
||||
component: () => import("@/views/Main.vue"),
|
||||
redirect: "/home",
|
||||
meta: { requiresAuth: true },
|
||||
children: [...staticMainChildren]
|
||||
};
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHashHistory(),
|
||||
routes: staticRoutes
|
||||
routes: [...staticRoutes, mainRoute, notFoundRoute]
|
||||
});
|
||||
|
||||
let dynamicRoutesAdded = false;
|
||||
let dynamicRoutesData = [];
|
||||
let routesLoadingPromise = null;
|
||||
// 加载代数:登录/登出时自增,用于丢弃「上一账号」发起但已过期的加载结果
|
||||
let routesGeneration = 0;
|
||||
|
||||
export function resetDynamicRoutes() {
|
||||
dynamicRoutesAdded = false;
|
||||
routesLoadingPromise = null;
|
||||
routesGeneration += 1;
|
||||
}
|
||||
|
||||
export async function loadAndAddDynamicRoutes() {
|
||||
@@ -161,26 +177,33 @@ export async function loadAndAddDynamicRoutes() {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
const generation = routesGeneration;
|
||||
routesLoadingPromise = (async () => {
|
||||
try {
|
||||
const { useMenuStore } = await import("@/stores/menu");
|
||||
const menuStore = useMenuStore();
|
||||
const menuData = await menuStore.fetchMenus();
|
||||
|
||||
// 等待期间已切换账号(resetDynamicRoutes 被调用):
|
||||
// 丢弃这批旧结果,避免用上一个会话的菜单覆盖路由表。
|
||||
if (generation !== routesGeneration) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (menuData && menuData.length > 0) {
|
||||
addDynamicRoutes(menuData);
|
||||
dynamicRoutesAdded = true;
|
||||
routesLoadingPromise = null;
|
||||
return Promise.resolve();
|
||||
} else {
|
||||
dynamicRoutesAdded = true;
|
||||
routesLoadingPromise = null;
|
||||
return Promise.resolve();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载动态路由失败:', error);
|
||||
// 菜单为空也要标记完成(/home 等静态页面已在初始路由表中,不受影响),
|
||||
// 避免每次导航都重复请求空菜单接口。
|
||||
dynamicRoutesAdded = true;
|
||||
routesLoadingPromise = null;
|
||||
} catch (error) {
|
||||
console.error('加载动态路由失败:', error);
|
||||
// 关键:失败时不要置 dynamicRoutesAdded,否则同一会话内重新登录
|
||||
// 后不会再加载路由表,业务菜单会全部落到 404;保留重试机会。
|
||||
if (generation === routesGeneration) {
|
||||
routesLoadingPromise = null;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
})();
|
||||
@@ -188,6 +211,20 @@ export async function loadAndAddDynamicRoutes() {
|
||||
return routesLoadingPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* 安全的动态路由加载:从不抛错,返回是否加载成功。
|
||||
* 失败仅记录日志,由路由守卫决定放行静态页面还是重新登录。
|
||||
*/
|
||||
async function ensureDynamicRoutes() {
|
||||
try {
|
||||
await loadAndAddDynamicRoutes();
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('动态路由加载失败:', error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 核心修改:移除扁平化,直接使用嵌套菜单生成路由
|
||||
function addDynamicRoutes(menus) {
|
||||
if (!menus?.length) {
|
||||
@@ -203,11 +240,7 @@ function addDynamicRoutes(menus) {
|
||||
|
||||
// 重新添加主路由,合并静态子路由和动态路由
|
||||
router.addRoute({
|
||||
path: "/",
|
||||
name: "Main",
|
||||
component: () => import("@/views/Main.vue"),
|
||||
redirect: "/home",
|
||||
meta: { requiresAuth: true },
|
||||
...mainRoute,
|
||||
children: [...staticMainChildren, ...dynamicRoutes] // 合并静态和动态子路由
|
||||
});
|
||||
|
||||
@@ -251,7 +284,9 @@ router.beforeEach(async (to, from, next) => {
|
||||
if (publicPaths.includes(to.path)) {
|
||||
if (token) {
|
||||
if (!dynamicRoutesAdded) {
|
||||
await loadAndAddDynamicRoutes();
|
||||
// 已在登录页且带 token:加载失败也要放行(静态路由已就绪),
|
||||
// 不能因为一次接口失败卡在登录页或落到 404。
|
||||
await ensureDynamicRoutes();
|
||||
}
|
||||
next({ path: "/home" });
|
||||
} else {
|
||||
@@ -261,24 +296,24 @@ router.beforeEach(async (to, from, next) => {
|
||||
}
|
||||
|
||||
if (!token) {
|
||||
next({ path: "/login", query: { redirect: to.path } });
|
||||
next({ path: "/login", query: { redirect: to.fullPath || to.path } });
|
||||
return;
|
||||
}
|
||||
|
||||
if (!dynamicRoutesAdded) {
|
||||
try {
|
||||
await loadAndAddDynamicRoutes();
|
||||
} catch (error) {
|
||||
console.error('动态路由加载失败:', error);
|
||||
// token 无效时跳转登录
|
||||
if (error?.message === 'token无效' || error?.response?.status === 401) {
|
||||
next({ path: '/login' });
|
||||
return;
|
||||
}
|
||||
const loaded = await ensureDynamicRoutes();
|
||||
// 加载过程中请求被判 401,拦截器已清掉 token,直接回登录页
|
||||
if (!localStorage.getItem("token")) {
|
||||
next({ path: '/login' });
|
||||
return;
|
||||
}
|
||||
// 路由加载后重新导航,确保路由匹配正确
|
||||
next({ path: to.path, replace: true });
|
||||
return;
|
||||
if (loaded) {
|
||||
// 路由表刚变化,重新解析目标地址,避免命中兜底 404
|
||||
next({ path: to.path, query: to.query, hash: to.hash, replace: true });
|
||||
return;
|
||||
}
|
||||
// 加载失败但 token 仍有效:静态页面(/home 等)照常放行,
|
||||
// 下次导航会再次尝试加载业务路由。
|
||||
}
|
||||
|
||||
next();
|
||||
|
||||
@@ -15,11 +15,25 @@ export const useAllDataStore = defineStore('allData', () => {
|
||||
function increment() {
|
||||
count.value++;
|
||||
}
|
||||
|
||||
// 是否为手机端(≤768px),通过 matchMedia 响应式监听
|
||||
const mobileQuery = window.matchMedia('(max-width: 768px)');
|
||||
const isMobile = ref(mobileQuery.matches);
|
||||
const handleMobileQueryChange = (e) => {
|
||||
isMobile.value = e.matches;
|
||||
};
|
||||
if (typeof mobileQuery.addEventListener === 'function') {
|
||||
mobileQuery.addEventListener('change', handleMobileQueryChange);
|
||||
} else {
|
||||
mobileQuery.addListener(handleMobileQueryChange);
|
||||
}
|
||||
|
||||
return {
|
||||
state,
|
||||
count,
|
||||
doubleCount,
|
||||
increment,
|
||||
isMobile,
|
||||
};
|
||||
});
|
||||
|
||||
@@ -37,14 +51,13 @@ import { ref as vueRef } from 'vue';
|
||||
* }
|
||||
*/
|
||||
export const useTabsStore = defineTabsStore('tabs', () => {
|
||||
// 固定首页tab
|
||||
// 固定首页 tab:/home 是数据概览页
|
||||
const defaultDashboardPath = '/home';
|
||||
|
||||
|
||||
// 从 localStorage 恢复 tabs 状态
|
||||
function loadTabsFromStorage() {
|
||||
try {
|
||||
const savedTabs = localStorage.getItem('tabs_list');
|
||||
const savedActiveTab = localStorage.getItem('active_tab');
|
||||
if (savedTabs) {
|
||||
const tabs = JSON.parse(savedTabs);
|
||||
// 确保至少包含首页
|
||||
@@ -59,7 +72,7 @@ export const useTabsStore = defineTabsStore('tabs', () => {
|
||||
}
|
||||
return [{ title: '首页', fullPath: defaultDashboardPath, name: 'Home' }];
|
||||
}
|
||||
|
||||
|
||||
// 保存 tabs 到 localStorage
|
||||
function saveTabsToStorage(tabs, active) {
|
||||
try {
|
||||
@@ -71,7 +84,7 @@ export const useTabsStore = defineTabsStore('tabs', () => {
|
||||
console.warn('保存 tabs 失败:', e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const tabList = vueRef(loadTabsFromStorage());
|
||||
const savedActiveTab = localStorage.getItem('active_tab');
|
||||
const activeTab = vueRef(savedActiveTab || defaultDashboardPath);
|
||||
@@ -88,6 +101,7 @@ export const useTabsStore = defineTabsStore('tabs', () => {
|
||||
|
||||
// 删除指定tab并切换激活tab
|
||||
function removeTab(fullPath) {
|
||||
if (fullPath === defaultDashboardPath) return;
|
||||
const idx = tabList.value.findIndex((t) => t.fullPath === fullPath);
|
||||
if (idx > -1) {
|
||||
tabList.value.splice(idx, 1);
|
||||
@@ -118,15 +132,13 @@ export const useTabsStore = defineTabsStore('tabs', () => {
|
||||
function closeLeft(targetFullPath) {
|
||||
const targetIndex = tabList.value.findIndex((t) => t.fullPath === targetFullPath);
|
||||
if (targetIndex > -1) {
|
||||
// 保留首页和目标tab及其右侧的所有tab
|
||||
const beforeIndex = tabList.value.slice(0, targetIndex);
|
||||
const hasCloseableLeft = beforeIndex.some(t => t.fullPath !== defaultDashboardPath);
|
||||
|
||||
|
||||
if (hasCloseableLeft) {
|
||||
tabList.value = tabList.value.filter((t, index) =>
|
||||
tabList.value = tabList.value.filter((t, index) =>
|
||||
t.fullPath === defaultDashboardPath || index >= targetIndex
|
||||
);
|
||||
// 如果关闭的tab中包含了当前激活的tab,则激活目标tab
|
||||
if (!tabList.value.find(t => t.fullPath === activeTab.value)) {
|
||||
activeTab.value = targetFullPath;
|
||||
}
|
||||
@@ -139,15 +151,13 @@ export const useTabsStore = defineTabsStore('tabs', () => {
|
||||
function closeRight(targetFullPath) {
|
||||
const targetIndex = tabList.value.findIndex((t) => t.fullPath === targetFullPath);
|
||||
if (targetIndex > -1) {
|
||||
// 保留首页和目标tab及其左侧的所有tab
|
||||
const afterIndex = tabList.value.slice(targetIndex + 1);
|
||||
const hasCloseableRight = afterIndex.length > 0;
|
||||
|
||||
|
||||
if (hasCloseableRight) {
|
||||
tabList.value = tabList.value.filter((t, index) =>
|
||||
tabList.value = tabList.value.filter((t, index) =>
|
||||
t.fullPath === defaultDashboardPath || index <= targetIndex
|
||||
);
|
||||
// 如果关闭的tab中包含了当前激活的tab,则激活目标tab
|
||||
if (!tabList.value.find(t => t.fullPath === activeTab.value)) {
|
||||
activeTab.value = targetFullPath;
|
||||
}
|
||||
@@ -162,7 +172,7 @@ export const useTabsStore = defineTabsStore('tabs', () => {
|
||||
activeTab.value = defaultDashboardPath;
|
||||
saveTabsToStorage(tabList.value, activeTab.value);
|
||||
}
|
||||
|
||||
|
||||
// 设置激活tab(不触发路由跳转,仅用于更新状态)
|
||||
function setActiveTab(fullPath) {
|
||||
activeTab.value = fullPath;
|
||||
@@ -171,9 +181,8 @@ export const useTabsStore = defineTabsStore('tabs', () => {
|
||||
|
||||
// 重置 tabs store 到初始状态(登出时使用)
|
||||
function resetTabs() {
|
||||
tabList.value = [{ title: '首页', fullPath: defaultDashboardPath, name: 'Dashboard' }];
|
||||
tabList.value = [{ title: '首页', fullPath: defaultDashboardPath, name: 'Home' }];
|
||||
activeTab.value = defaultDashboardPath;
|
||||
// 清除 localStorage 中的 tabs 数据
|
||||
localStorage.removeItem('tabs_list');
|
||||
localStorage.removeItem('active_tab');
|
||||
}
|
||||
@@ -181,6 +190,7 @@ export const useTabsStore = defineTabsStore('tabs', () => {
|
||||
return {
|
||||
tabList,
|
||||
activeTab,
|
||||
defaultDashboardPath,
|
||||
addTab,
|
||||
removeTab,
|
||||
closeOthers,
|
||||
@@ -194,4 +204,4 @@ export const useTabsStore = defineTabsStore('tabs', () => {
|
||||
});
|
||||
|
||||
// ========== 菜单 Menu Store ==========
|
||||
export { useMenuStore } from './menu';
|
||||
export { useMenuStore } from './menu';
|
||||
@@ -16,13 +16,16 @@ export const useMenuStore = defineStore('menu', () => {
|
||||
// 正在加载的 Promise(用于避免重复请求)
|
||||
let loadingPromise = null;
|
||||
|
||||
// 菜单缓存 key(基于用户类型和角色ID)
|
||||
// 菜单缓存 key(基于用户类型、角色ID、用户ID)
|
||||
// 必须带上用户ID:同一浏览器换账号登录时,若只看角色ID会复用上一个账号的菜单,
|
||||
// 导致新账号进入后菜单/路由与权限不匹配。
|
||||
const getCacheKey = () => {
|
||||
try {
|
||||
const userInfo = JSON.parse(localStorage.getItem('userInfo') || '{}');
|
||||
const loginType = userInfo.type || 'user';
|
||||
const roleId = userInfo.rid || 0;
|
||||
return `menu_cache_${loginType}_${roleId}`;
|
||||
const userId = userInfo.id || 0;
|
||||
return `menu_cache_${loginType}_${roleId}_${userId}`;
|
||||
} catch (e) {
|
||||
return 'menu_cache_default';
|
||||
}
|
||||
@@ -59,13 +62,17 @@ export const useMenuStore = defineStore('menu', () => {
|
||||
}
|
||||
};
|
||||
|
||||
// 清除菜单缓存
|
||||
// 清除菜单缓存(含历史 key 格式与其他账号遗留的缓存)
|
||||
const clearCache = () => {
|
||||
try {
|
||||
const cacheKey = getCacheKey();
|
||||
localStorage.removeItem(cacheKey);
|
||||
// 也清除其他可能的缓存key(兼容旧代码)
|
||||
localStorage.removeItem('menu_cache');
|
||||
const cacheKeys = [];
|
||||
for (let i = 0; i < localStorage.length; i++) {
|
||||
const key = localStorage.key(i);
|
||||
if (key && key.indexOf('menu_cache') === 0) {
|
||||
cacheKeys.push(key);
|
||||
}
|
||||
}
|
||||
cacheKeys.forEach((key) => localStorage.removeItem(key));
|
||||
} catch (e) {
|
||||
console.warn('清除菜单缓存失败:', e);
|
||||
}
|
||||
|
||||
+312
-287
@@ -4,29 +4,64 @@ import CommonHeader from '@/components/CommonHeader.vue';
|
||||
import { useTabsStore } from '@/stores';
|
||||
import { useDictStore } from '@/stores/dict';
|
||||
import { useRouter, useRoute } from 'vue-router';
|
||||
import { ref, watch, reactive, nextTick, onMounted, computed } from 'vue';
|
||||
import { More, Close, CircleClose, ArrowUp } from '@element-plus/icons-vue';
|
||||
import { ref, watch, reactive, nextTick, onMounted, onBeforeUnmount, computed } from 'vue';
|
||||
import { More, ArrowUp, Fold, Expand } from '@element-plus/icons-vue';
|
||||
import { ElMessage } from 'element-plus';
|
||||
|
||||
const tabsStore = useTabsStore();
|
||||
const dictStore = useDictStore();
|
||||
const router = useRouter();
|
||||
const route = useRoute();
|
||||
const asideRef = ref(null);
|
||||
const defaultDashboardPath = '/home';
|
||||
|
||||
// 固定首页(数据概览)作为不可关闭的默认标签
|
||||
const defaultDashboardPath = computed(
|
||||
() => tabsStore.defaultDashboardPath || '/home'
|
||||
);
|
||||
|
||||
// ========== 手机端侧栏抽屉控制 ==========
|
||||
const MOBILE_QUERY = '(max-width: 768px)';
|
||||
const mobileMedia = window.matchMedia(MOBILE_QUERY);
|
||||
const isMobile = ref(mobileMedia.matches);
|
||||
const sidebarVisible = ref(false);
|
||||
|
||||
const handleMobileMediaChange = (e) => {
|
||||
isMobile.value = e.matches;
|
||||
if (!e.matches) {
|
||||
sidebarVisible.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
if (typeof mobileMedia.addEventListener === 'function') {
|
||||
mobileMedia.addEventListener('change', handleMobileMediaChange);
|
||||
} else {
|
||||
mobileMedia.addListener(handleMobileMediaChange);
|
||||
}
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (typeof mobileMedia.removeEventListener === 'function') {
|
||||
mobileMedia.removeEventListener('change', handleMobileMediaChange);
|
||||
} else {
|
||||
mobileMedia.removeListener(handleMobileMediaChange);
|
||||
}
|
||||
});
|
||||
|
||||
const toggleMobileSidebar = () => {
|
||||
sidebarVisible.value = !sidebarVisible.value;
|
||||
};
|
||||
|
||||
const closeMobileSidebar = () => {
|
||||
sidebarVisible.value = false;
|
||||
};
|
||||
|
||||
// 根据当前路由恢复 tab(刷新时使用)
|
||||
function restoreTabFromRoute() {
|
||||
const currentPath = route.fullPath;
|
||||
const currentName = route.name;
|
||||
const currentMeta = route.meta || {};
|
||||
|
||||
// 如果当前路径不在 tabList 中,添加它
|
||||
|
||||
const existTab = tabsStore.tabList.find(t => t.fullPath === currentPath);
|
||||
if (!existTab) {
|
||||
// 从路由 meta 获取标题,如果没有则使用路由 name 或路径
|
||||
const title = currentMeta.title || currentName || '页面';
|
||||
// 使用 addTab 会自动保存到 localStorage
|
||||
tabsStore.addTab({
|
||||
title: title,
|
||||
fullPath: currentPath,
|
||||
@@ -34,49 +69,25 @@ function restoreTabFromRoute() {
|
||||
icon: currentMeta.icon
|
||||
});
|
||||
} else {
|
||||
// 如果已存在,只激活它(不触发路由跳转)
|
||||
tabsStore.setActiveTab(currentPath);
|
||||
}
|
||||
}
|
||||
|
||||
// 组件挂载后,根据当前路由恢复 tab
|
||||
onMounted(() => {
|
||||
// 进入后台后把库里所有字典预热到缓存(失败不影响按需加载)
|
||||
dictStore.loadAll();
|
||||
|
||||
// 等待路由完全加载后再恢复
|
||||
nextTick(() => {
|
||||
// 刷新时,localStorage 中已保存的 tabs 会在 store 初始化时恢复
|
||||
// 这里只需要确保当前路由对应的 tab 存在并激活
|
||||
restoreTabFromRoute();
|
||||
|
||||
// 为 tabs 容器添加右键事件监听(使用事件委托)
|
||||
|
||||
const tabsWrapper = document.querySelector('.multi-tabs-wrapper');
|
||||
if (tabsWrapper) {
|
||||
tabsWrapper.addEventListener('contextmenu', (e) => {
|
||||
// 排除编辑器相关区域,避免影响编辑器功能
|
||||
// 如果点击在编辑器区域内,完全不做任何处理(优先检查)
|
||||
const editorWrapper = e.target.closest?.('.tiptap-editor-wrapper');
|
||||
if (editorWrapper) {
|
||||
// 在编辑器区域内,不处理右键菜单,也不阻止事件
|
||||
return;
|
||||
}
|
||||
const insideEditor =
|
||||
e.target.closest?.('.tiptap-editor-wrapper') ||
|
||||
e.target.closest?.('.tiptap-toolbar') ||
|
||||
e.target.closest?.('[class*="tiptap-"]');
|
||||
if (insideEditor) return;
|
||||
|
||||
// 检查其他编辑器元素(工具栏、下拉面板等)
|
||||
const editorElements = [
|
||||
'.tiptap-toolbar',
|
||||
'.tiptap',
|
||||
'[class*="tiptap-"]'
|
||||
];
|
||||
|
||||
for (const selector of editorElements) {
|
||||
if (e.target.closest && e.target.closest(selector)) {
|
||||
// 在编辑器元素内,不处理右键菜单
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 只有在非编辑器区域的 tab item 上才处理右键菜单
|
||||
const tabItem = e.target.closest('.el-tabs__item');
|
||||
if (tabItem) {
|
||||
e.preventDefault();
|
||||
@@ -94,65 +105,64 @@ watch(
|
||||
(newPath) => {
|
||||
if (newPath) {
|
||||
restoreTabFromRoute();
|
||||
if (isMobile.value) sidebarVisible.value = false;
|
||||
}
|
||||
},
|
||||
{ immediate: false }
|
||||
);
|
||||
|
||||
// 1. 侧栏菜单点击:加入/激活Tab并切换路由
|
||||
// 侧栏/顶栏菜单点击:加入/激活 Tab 并切换路由
|
||||
const handleAsideMenuClick = async (menuItem) => {
|
||||
const targetPath = menuItem.path;
|
||||
if (!targetPath) return;
|
||||
|
||||
if (targetPath === '/home' || targetPath === defaultDashboardPath) {
|
||||
if (targetPath === '/home') {
|
||||
tabsStore.closeAll();
|
||||
router.push(defaultDashboardPath);
|
||||
router.push('/home');
|
||||
return;
|
||||
}
|
||||
|
||||
// 先添加tab
|
||||
tabsStore.addTab({
|
||||
title: menuItem.title,
|
||||
fullPath: targetPath,
|
||||
name: menuItem.title,
|
||||
icon: menuItem.icon
|
||||
});
|
||||
|
||||
// 如果当前路由已经是目标路由,不需要跳转
|
||||
if (router.currentRoute.value.fullPath === targetPath) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (router.currentRoute.value.fullPath === targetPath) return;
|
||||
|
||||
router.push(targetPath).catch(err => {
|
||||
if (err.name !== 'NavigationDuplicated') {
|
||||
ElMessage.warning(`路由 ${targetPath} 不存在,请刷新缓存后重试`);
|
||||
console.error('路由跳转失败:', err);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const tabsCloseTab = (targetKey) => {
|
||||
tabsStore.removeTab(targetKey);
|
||||
if (route.fullPath !== tabsStore.activeTab) {
|
||||
router.push(tabsStore.activeTab);
|
||||
}
|
||||
};
|
||||
|
||||
const closeOthers = () => {
|
||||
tabsStore.closeOthers();
|
||||
if (!tabsStore.tabList.find(tab => tab.fullPath === route.fullPath)) {
|
||||
router.push(tabsStore.activeTab);
|
||||
}
|
||||
};
|
||||
|
||||
const closeAll = () => {
|
||||
tabsStore.closeAll();
|
||||
router.push(defaultDashboardPath);
|
||||
router.push(defaultDashboardPath.value || route.fullPath);
|
||||
};
|
||||
// 主动监听tab激活,保证切tab时内容区切换(仅用于tab点击切换,菜单点击由handleAsideMenuClick处理)
|
||||
// 使用 immediate: false 避免初始化时触发,使用 flush: 'post' 确保在 DOM 更新后执行
|
||||
|
||||
// 主动监听 tab 激活,保证切 tab 时内容区切换
|
||||
watch(
|
||||
() => tabsStore.activeTab,
|
||||
(newVal, oldVal) => {
|
||||
if (newVal && oldVal !== undefined && router.currentRoute.value.fullPath !== newVal) {
|
||||
if (newVal === defaultDashboardPath) {
|
||||
tabsStore.closeAll();
|
||||
}
|
||||
nextTick(() => {
|
||||
router.push(newVal).catch(err => {
|
||||
if (err.name !== 'NavigationDuplicated') {
|
||||
@@ -165,25 +175,21 @@ watch(
|
||||
{ flush: 'post' }
|
||||
);
|
||||
|
||||
// ========== 右键菜单逻辑 ========== //
|
||||
// ========== 右键菜单逻辑 ==========
|
||||
const contextMenu = reactive({
|
||||
visible: false,
|
||||
x: 0,
|
||||
y: 0,
|
||||
tab: null,
|
||||
});
|
||||
const contextDropdownRef = ref(null);
|
||||
|
||||
// 处理 tabs 容器的右键事件
|
||||
const handleTabsContextMenu = (event) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
// 找到点击的 tab item 元素(el-tabs__item)
|
||||
|
||||
let target = event.target;
|
||||
let tabItem = null;
|
||||
|
||||
// 向上查找 el-tabs__item 元素
|
||||
|
||||
while (target && target !== event.currentTarget) {
|
||||
if (target.classList && target.classList.contains('el-tabs__item')) {
|
||||
tabItem = target;
|
||||
@@ -191,10 +197,8 @@ const handleTabsContextMenu = (event) => {
|
||||
}
|
||||
target = target.parentElement;
|
||||
}
|
||||
|
||||
if (!tabItem) return;
|
||||
|
||||
// Element Plus 的 tab item 的 id 格式通常是 "tab-{name}",其中 name 是 tab-pane 的 name 属性
|
||||
|
||||
const tabId = tabItem.id;
|
||||
if (tabId && tabId.startsWith('tab-')) {
|
||||
const tabName = tabId.replace('tab-', '');
|
||||
@@ -204,184 +208,151 @@ const handleTabsContextMenu = (event) => {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 如果通过 id 找不到,尝试通过 aria-controls 或其他属性
|
||||
|
||||
const ariaControls = tabItem.getAttribute('aria-controls');
|
||||
if (ariaControls) {
|
||||
const tabName = ariaControls.replace('pane-', '');
|
||||
const matchedTab = tabsStore.tabList.find(t => t.fullPath === tabName);
|
||||
if (matchedTab) {
|
||||
showContextMenu(event, matchedTab);
|
||||
}
|
||||
if (matchedTab) showContextMenu(event, matchedTab);
|
||||
}
|
||||
};
|
||||
|
||||
// 显示右键菜单
|
||||
const showContextMenu = (event, tab) => {
|
||||
// 使用 nextTick 确保在下一个事件循环中更新状态,避免在渲染过程中触发更新
|
||||
nextTick(() => {
|
||||
contextMenu.visible = true;
|
||||
contextMenu.x = event.clientX;
|
||||
contextMenu.y = event.clientY;
|
||||
contextMenu.tab = tab;
|
||||
|
||||
// 延迟添加事件监听器,确保菜单已渲染
|
||||
// 关键:完全排除编辑器区域,确保编辑器的事件不被干扰
|
||||
|
||||
setTimeout(() => {
|
||||
const hideMenuHandler = (e) => {
|
||||
// 如果右键菜单已经隐藏,直接返回
|
||||
if (!contextMenu.visible) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!contextMenu.visible) return;
|
||||
const target = e.target;
|
||||
if (!target) {
|
||||
hideContextMenu();
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查点击是否在右键菜单本身上
|
||||
if (target.closest?.('.context-menu')) {
|
||||
return; // 点击在菜单上,不隐藏
|
||||
}
|
||||
|
||||
// ========== 关键修复:优先检查编辑器区域 ==========
|
||||
// 如果在编辑器区域内,立即返回,不执行任何操作,让编辑器的事件正常处理
|
||||
|
||||
// 先检查是否在编辑器包装器内(最快判断)
|
||||
const tiptapEditorWrapper = target.closest?.('.tiptap-editor-wrapper');
|
||||
if (tiptapEditorWrapper) {
|
||||
// 在编辑器包装器内,完全不做任何处理,让编辑器正常处理
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查所有可能的编辑器元素(包括工具栏、下拉面板、模态框等)
|
||||
const editorSelectors = [
|
||||
'.tiptap-toolbar',
|
||||
'.tiptap',
|
||||
'.editor-container',
|
||||
'[class*="tiptap-"]'
|
||||
];
|
||||
|
||||
for (const selector of editorSelectors) {
|
||||
if (target.closest?.(selector)) {
|
||||
// 在编辑器区域内,完全不做任何处理,让编辑器的事件正常处理
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 其他区域点击,隐藏菜单
|
||||
hideContextMenu();
|
||||
};
|
||||
|
||||
// 关键修复:使用 capture: false 在冒泡阶段处理,并且延迟注册
|
||||
// 这样可以确保编辑器的监听器(通常在目标元素上)先处理事件
|
||||
// 然后再处理我们的监听器(在 body 上)
|
||||
// 注意:只有在右键菜单显示时才注册,并且排除编辑器区域
|
||||
setTimeout(() => {
|
||||
// 再次检查右键菜单是否仍然可见
|
||||
if (contextMenu.visible) {
|
||||
document.body.addEventListener('click', hideMenuHandler, { once: true, capture: false, passive: true });
|
||||
}
|
||||
}, 100); // 延迟注册,确保编辑器的事件监听器已经注册并可以正常处理
|
||||
|
||||
const hideContextMenuHandler = (e) => {
|
||||
const target = e.target;
|
||||
if (!target) {
|
||||
hideContextMenu();
|
||||
return;
|
||||
}
|
||||
|
||||
// 排除编辑器区域和右键菜单本身
|
||||
if (target.closest?.('.tiptap-toolbar') || target.closest?.('.context-menu') || target.closest?.('.tiptap-editor-wrapper')) {
|
||||
if (target.closest?.('.context-menu')) return;
|
||||
if (
|
||||
target.closest?.('.tiptap-toolbar') ||
|
||||
target.closest?.('.tiptap-editor-wrapper')
|
||||
) {
|
||||
return;
|
||||
}
|
||||
hideContextMenu();
|
||||
};
|
||||
|
||||
document.body.addEventListener('contextmenu', hideContextMenuHandler, { once: true });
|
||||
document.body.addEventListener('click', hideMenuHandler, { once: true });
|
||||
document.body.addEventListener('contextmenu', hideMenuHandler, { once: true });
|
||||
}, 0);
|
||||
});
|
||||
};
|
||||
|
||||
function hideContextMenu() {
|
||||
contextMenu.visible = false;
|
||||
contextMenu.tab = null;
|
||||
}
|
||||
|
||||
function closeTabContextTab() {
|
||||
if (contextMenu.tab && contextMenu.tab.fullPath !== defaultDashboardPath) {
|
||||
if (contextMenu.tab && contextMenu.tab.fullPath !== defaultDashboardPath.value) {
|
||||
tabsStore.removeTab(contextMenu.tab.fullPath);
|
||||
if (route.fullPath !== tabsStore.activeTab) {
|
||||
router.push(tabsStore.activeTab);
|
||||
}
|
||||
}
|
||||
hideContextMenu();
|
||||
}
|
||||
// 关闭左侧
|
||||
|
||||
function closeLeftContextTab() {
|
||||
if (contextMenu.tab) {
|
||||
tabsStore.closeLeft(contextMenu.tab.fullPath);
|
||||
// 如果当前路由对应的tab被关闭了,跳转到激活的tab
|
||||
if (!tabsStore.tabList.find(tab => tab.fullPath === route.fullPath)) {
|
||||
if (!tabsStore.tabList.find(t => t.fullPath === route.fullPath)) {
|
||||
router.push(tabsStore.activeTab);
|
||||
}
|
||||
}
|
||||
hideContextMenu();
|
||||
}
|
||||
|
||||
// 关闭右侧
|
||||
function closeRightContextTab() {
|
||||
if (contextMenu.tab) {
|
||||
tabsStore.closeRight(contextMenu.tab.fullPath);
|
||||
// 如果当前路由对应的tab被关闭了,跳转到激活的tab
|
||||
if (!tabsStore.tabList.find(tab => tab.fullPath === route.fullPath)) {
|
||||
if (!tabsStore.tabList.find(t => t.fullPath === route.fullPath)) {
|
||||
router.push(tabsStore.activeTab);
|
||||
}
|
||||
}
|
||||
hideContextMenu();
|
||||
}
|
||||
|
||||
// 关闭其他
|
||||
function closeOthersContextTab() {
|
||||
if (contextMenu.tab) {
|
||||
tabsStore.setActiveTab(contextMenu.tab.fullPath);
|
||||
tabsStore.addTab(contextMenu.tab);
|
||||
tabsStore.closeOthers();
|
||||
if (!tabsStore.tabList.find(tab => tab.fullPath === route.fullPath)) {
|
||||
router.push(tabsStore.activeTab);
|
||||
}
|
||||
router.push(contextMenu.tab.fullPath);
|
||||
}
|
||||
hideContextMenu();
|
||||
}
|
||||
|
||||
// 关闭全部
|
||||
function closeAllTabs() {
|
||||
tabsStore.closeAll();
|
||||
router.push(defaultDashboardPath.value || route.fullPath);
|
||||
hideContextMenu();
|
||||
router.push(defaultDashboardPath);
|
||||
}
|
||||
|
||||
// 计算是否可以关闭左侧/右侧
|
||||
const canCloseLeft = computed(() => {
|
||||
if (!contextMenu.tab) return false;
|
||||
const targetIndex = tabsStore.tabList.findIndex(t => t.fullPath === contextMenu.tab.fullPath);
|
||||
// 至少左侧有一个可关闭的tab(排除首页)
|
||||
return targetIndex > 0 && tabsStore.tabList.slice(0, targetIndex).some(t => t.fullPath !== defaultDashboardPath);
|
||||
const targetIndex = tabsStore.tabList.findIndex(
|
||||
t => t.fullPath === contextMenu.tab.fullPath
|
||||
);
|
||||
return (
|
||||
targetIndex > 0 &&
|
||||
tabsStore.tabList
|
||||
.slice(0, targetIndex)
|
||||
.some(t => t.fullPath !== defaultDashboardPath.value)
|
||||
);
|
||||
});
|
||||
|
||||
const canCloseRight = computed(() => {
|
||||
if (!contextMenu.tab) return false;
|
||||
const targetIndex = tabsStore.tabList.findIndex(t => t.fullPath === contextMenu.tab.fullPath);
|
||||
// 右侧至少有一个tab
|
||||
return targetIndex < tabsStore.tabList.length - 1;
|
||||
const targetIndex = tabsStore.tabList.findIndex(
|
||||
t => t.fullPath === contextMenu.tab.fullPath
|
||||
);
|
||||
return targetIndex > -1 && targetIndex < tabsStore.tabList.length - 1;
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="common-layout">
|
||||
<el-container class="main-container">
|
||||
<div class="aside-wrapper">
|
||||
<common-aside ref="asideRef" @menu-click="handleAsideMenuClick" />
|
||||
</div>
|
||||
<el-container>
|
||||
<el-header class="main-header">
|
||||
<common-header @collapse="() => asideRef?.toggleMobile()" />
|
||||
</el-header>
|
||||
<!-- 手机端汉堡菜单按钮(仅 ≤768px 显示,CSS 控制) -->
|
||||
<button
|
||||
class="mobile-menu-btn"
|
||||
:aria-label="sidebarVisible ? '关闭菜单' : '打开菜单'"
|
||||
@click="toggleMobileSidebar"
|
||||
>
|
||||
<el-icon :size="20">
|
||||
<Expand v-if="sidebarVisible" />
|
||||
<Fold v-else />
|
||||
</el-icon>
|
||||
</button>
|
||||
|
||||
<!-- 手机端遮罩层,点击关闭侧栏 -->
|
||||
<transition name="mask-fade">
|
||||
<div
|
||||
v-if="isMobile && sidebarVisible"
|
||||
class="mobile-sidebar-mask"
|
||||
@click="closeMobileSidebar"
|
||||
></div>
|
||||
</transition>
|
||||
|
||||
<el-container class="main-container" direction="vertical">
|
||||
<!-- 顶栏全宽:logo 位于页面真正的左上角 -->
|
||||
<el-header class="main-header">
|
||||
<common-header @menu-click="handleAsideMenuClick" />
|
||||
</el-header>
|
||||
<el-container class="main-body">
|
||||
<common-aside
|
||||
class="common-aside-wrapper"
|
||||
:class="{ 'mobile-open': sidebarVisible }"
|
||||
@menu-click="handleAsideMenuClick"
|
||||
/>
|
||||
<el-main class="right-main">
|
||||
<div class="multi-tabs-wrapper">
|
||||
<el-tabs
|
||||
@@ -400,7 +371,7 @@ const canCloseRight = computed(() => {
|
||||
:data-tab-path="tab.fullPath"
|
||||
/>
|
||||
</el-tabs>
|
||||
|
||||
|
||||
<!-- 右键菜单 -->
|
||||
<teleport to="body">
|
||||
<div
|
||||
@@ -467,7 +438,7 @@ const canCloseRight = computed(() => {
|
||||
</keep-alive>
|
||||
</router-view>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- 回到顶部按钮 -->
|
||||
<el-backtop :target="'.right-main'" :visibility-height="300" :right="30" :bottom="50">
|
||||
<div class="backtop-button">
|
||||
@@ -483,125 +454,113 @@ const canCloseRight = computed(() => {
|
||||
</template>
|
||||
|
||||
<style scoped lang="less">
|
||||
.common-layout, .main-container {
|
||||
.common-layout,
|
||||
.main-container {
|
||||
height: 100vh;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
background-color: var(--bg-color-page);
|
||||
background-color: var(--yz-page-bg);
|
||||
transition: background-color 0.3s ease;
|
||||
|
||||
:deep(.el-aside) {
|
||||
display: block !important;
|
||||
// 侧栏内部是「菜单 + 底部装饰」的纵向布局:
|
||||
// 必须是 flex 列容器,菜单才能 flex:1 收缩并在内部滚动。
|
||||
// 不能写成 display:block,否则 el-menu 的高度会撑开、溢出被裁剪且无法滚动。
|
||||
display: flex !important;
|
||||
flex-direction: column;
|
||||
visibility: visible !important;
|
||||
height: 100vh;
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.aside-wrapper {
|
||||
flex-shrink: 0;
|
||||
position: relative;
|
||||
transition: width 0.3s;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.aside-wrapper {
|
||||
width: 0 !important;
|
||||
overflow: visible;
|
||||
}
|
||||
.right-main {
|
||||
padding: 12px 8px !important;
|
||||
}
|
||||
}
|
||||
.main-header {
|
||||
background-color: var(--header-bg-color, #3973ff);
|
||||
background-color: var(--yz-header-bg);
|
||||
transition: background-color 0.3s ease;
|
||||
height: 80px;
|
||||
height: var(--yz-header-height);
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.right-main {
|
||||
background-color: var(--el-bg-color-page);
|
||||
color: var(--el-text-color-primary);
|
||||
background-color: var(--yz-page-bg);
|
||||
color: var(--yz-text);
|
||||
transition: background-color 0.3s ease, color 0.3s ease;
|
||||
padding: 20px;
|
||||
padding: 16px 20px 20px;
|
||||
overflow-y: auto;
|
||||
|
||||
|
||||
.multi-tabs-wrapper {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
background: var(--el-bg-color);
|
||||
border-radius: 8px;
|
||||
padding: 8px 12px;
|
||||
border: 1px solid var(--el-border-color-lighter);
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
|
||||
margin-bottom: 14px;
|
||||
background: var(--yz-card-bg);
|
||||
border-radius: 12px;
|
||||
padding: 6px 10px;
|
||||
border: 1px solid var(--yz-border);
|
||||
box-shadow: var(--yz-shadow);
|
||||
}
|
||||
|
||||
|
||||
.multi-tabs {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
|
||||
|
||||
:deep(.el-tabs__header) {
|
||||
margin: 0;
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
|
||||
:deep(.el-tabs__nav-wrap) {
|
||||
overflow-x: auto;
|
||||
overflow-y: hidden;
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: var(--el-border-color) transparent;
|
||||
|
||||
scrollbar-color: var(--yz-border) transparent;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
height: 4px;
|
||||
}
|
||||
|
||||
|
||||
&::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background: var(--el-border-color);
|
||||
background: var(--yz-border);
|
||||
border-radius: 2px;
|
||||
|
||||
&:hover {
|
||||
background: var(--el-border-color-darker);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
:deep(.el-tabs__item) {
|
||||
border: 1px solid var(--el-border-color-lighter);
|
||||
border-radius: 6px;
|
||||
margin-right: 8px;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 8px;
|
||||
margin-right: 6px;
|
||||
padding: 8px 16px;
|
||||
height: 36px;
|
||||
line-height: 20px;
|
||||
color: var(--el-text-color-regular);
|
||||
background: var(--el-fill-color-lighter);
|
||||
transition: all 0.3s;
|
||||
|
||||
color: var(--yz-text-regular);
|
||||
background: transparent;
|
||||
transition: all 0.25s;
|
||||
|
||||
&:hover {
|
||||
color: var(--el-color-primary);
|
||||
border-color: var(--el-color-primary-light-7);
|
||||
background: var(--el-color-primary-light-9);
|
||||
color: var(--yz-primary);
|
||||
background: var(--yz-primary-softer);
|
||||
}
|
||||
|
||||
|
||||
&.is-active {
|
||||
color: var(--el-color-primary);
|
||||
border-color: #4f84ff;
|
||||
background: #4f84ff;
|
||||
color: #fff;
|
||||
|
||||
border-color: var(--el-color-primary-light-7);
|
||||
background: var(--yz-primary-soft);
|
||||
color: var(--yz-primary);
|
||||
font-weight: 600;
|
||||
|
||||
.el-icon-close {
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
|
||||
color: var(--yz-primary);
|
||||
|
||||
&:hover {
|
||||
color: #fff;
|
||||
background-color: rgba(255, 255, 255, 0.2);
|
||||
color: var(--yz-primary);
|
||||
background-color: var(--el-color-primary-light-7);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.el-icon-close {
|
||||
margin-left: 8px;
|
||||
border-radius: 50%;
|
||||
@@ -609,45 +568,138 @@ const canCloseRight = computed(() => {
|
||||
height: 16px;
|
||||
line-height: 16px;
|
||||
transition: all 0.2s;
|
||||
|
||||
|
||||
&:hover {
|
||||
background-color: var(--el-fill-color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
:deep(.el-tabs__nav) {
|
||||
border: none;
|
||||
}
|
||||
|
||||
|
||||
:deep(.el-tabs__content) {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
.tabs-extra-actions {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
|
||||
.extra-btn {
|
||||
padding: 8px;
|
||||
font-size: 18px;
|
||||
color: var(--el-text-color-regular);
|
||||
|
||||
color: var(--yz-text-regular);
|
||||
|
||||
&:hover {
|
||||
color: var(--el-color-primary);
|
||||
color: var(--yz-primary);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
:deep(.el-menu){
|
||||
.main-body {
|
||||
display: flex;
|
||||
flex: 1 1 auto;
|
||||
min-height: 0;
|
||||
min-width: 0;
|
||||
background-color: var(--yz-page-bg);
|
||||
}
|
||||
|
||||
.main-panel {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
:deep(.el-menu) {
|
||||
border-right: none !important;
|
||||
}
|
||||
|
||||
// ========== 手机端侧栏抽屉(仅 ≤768px 生效,桌面端不受影响) ==========
|
||||
.mobile-menu-btn {
|
||||
display: none;
|
||||
position: fixed;
|
||||
top: 12px;
|
||||
left: 12px;
|
||||
z-index: 2200;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border: none;
|
||||
border-radius: 50%;
|
||||
background: var(--yz-primary);
|
||||
color: #fff;
|
||||
box-shadow: 0 4px 12px rgba(47, 107, 255, 0.3);
|
||||
cursor: pointer;
|
||||
transition: transform 0.2s ease, box-shadow 0.2s ease;
|
||||
|
||||
&:active {
|
||||
transform: scale(0.92);
|
||||
}
|
||||
}
|
||||
|
||||
.mobile-sidebar-mask {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
z-index: 2000;
|
||||
background: rgba(0, 0, 0, 0.45);
|
||||
backdrop-filter: blur(2px);
|
||||
}
|
||||
|
||||
.mask-fade-enter-active,
|
||||
.mask-fade-leave-active {
|
||||
transition: opacity 0.3s ease;
|
||||
}
|
||||
|
||||
.mask-fade-enter-from,
|
||||
.mask-fade-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.mobile-menu-btn {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
// 覆盖 el-aside 的 :width 内联宽度(224px/64px),改为 fixed 抽屉
|
||||
.common-layout .common-aside-wrapper {
|
||||
position: fixed !important;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
width: 260px !important;
|
||||
max-width: 80vw;
|
||||
height: 100vh;
|
||||
z-index: 2100;
|
||||
transform: translateX(-100%);
|
||||
transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
box-shadow: none;
|
||||
|
||||
&.mobile-open {
|
||||
transform: translateX(0);
|
||||
box-shadow: 4px 0 24px rgba(0, 0, 0, 0.25);
|
||||
}
|
||||
}
|
||||
|
||||
.main-container {
|
||||
:deep(.el-header),
|
||||
:deep(.el-main) {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.right-main {
|
||||
padding: 64px 12px 12px;
|
||||
}
|
||||
}
|
||||
|
||||
// 回到顶部按钮样式
|
||||
.backtop-button {
|
||||
width: 40px;
|
||||
@@ -655,51 +707,22 @@ const canCloseRight = computed(() => {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: var(--el-color-primary);
|
||||
background: var(--yz-primary);
|
||||
color: #fff;
|
||||
border-radius: 50%;
|
||||
box-shadow: 0 4px 12px rgba(64, 129, 255, 0.4);
|
||||
box-shadow: 0 4px 12px rgba(47, 107, 255, 0.35);
|
||||
transition: all 0.3s ease;
|
||||
cursor: pointer;
|
||||
|
||||
|
||||
&:hover {
|
||||
background: var(--el-color-primary-light-3);
|
||||
box-shadow: 0 6px 16px rgba(64, 129, 255, 0.5);
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
|
||||
&:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.common-layout,
|
||||
.main-container {
|
||||
.main-header {
|
||||
height: 64px;
|
||||
}
|
||||
|
||||
.right-main {
|
||||
padding: 8px;
|
||||
|
||||
.multi-tabs-wrapper {
|
||||
margin-bottom: 10px;
|
||||
padding: 6px 8px;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.tabs-extra-actions {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.backtop-button {
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
<style lang="less">
|
||||
@@ -709,23 +732,25 @@ const canCloseRight = computed(() => {
|
||||
z-index: 9999 !important;
|
||||
background: var(--el-bg-color-overlay) !important;
|
||||
border: 1px solid var(--el-border-color-lighter) !important;
|
||||
border-radius: 4px !important;
|
||||
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1) !important;
|
||||
min-width: 120px !important;
|
||||
padding: 4px 0 !important;
|
||||
pointer-events: auto !important; // 确保菜单本身可以接收点击
|
||||
|
||||
border-radius: 8px !important;
|
||||
box-shadow: 0 10px 30px rgba(31, 61, 130, 0.16) !important;
|
||||
min-width: 128px !important;
|
||||
padding: 4px !important;
|
||||
pointer-events: auto !important;
|
||||
|
||||
.context-menu-item {
|
||||
padding: 8px 16px !important;
|
||||
padding: 8px 12px !important;
|
||||
border-radius: 6px !important;
|
||||
cursor: pointer !important;
|
||||
color: var(--el-text-color-primary) !important;
|
||||
font-size: 14px !important;
|
||||
font-size: 13px !important;
|
||||
transition: background-color 0.2s !important;
|
||||
|
||||
|
||||
&:hover:not(.is-disabled) {
|
||||
background-color: var(--el-fill-color-light) !important;
|
||||
background-color: var(--yz-primary-softer) !important;
|
||||
color: var(--yz-primary) !important;
|
||||
}
|
||||
|
||||
|
||||
&.is-disabled {
|
||||
color: var(--el-text-color-disabled) !important;
|
||||
cursor: not-allowed !important;
|
||||
@@ -735,7 +760,7 @@ const canCloseRight = computed(() => {
|
||||
}
|
||||
|
||||
// 确保编辑器工具栏的 z-index 高于右键菜单
|
||||
:deep(.tiptap-toolbar) {
|
||||
.tiptap-toolbar {
|
||||
z-index: 10000 !important;
|
||||
pointer-events: auto !important;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div class="statistics-container">
|
||||
<div v-loading="loading" class="statistics-container">
|
||||
<el-row :gutter="20" class="data-overview">
|
||||
<el-col :xs="12" :sm="12" :md="6" v-for="item in summaryData" :key="item.title">
|
||||
<el-card shadow="hover" class="data-card">
|
||||
@@ -9,11 +9,18 @@
|
||||
</div>
|
||||
<div class="text-box">
|
||||
<div class="title">{{ item.title }}</div>
|
||||
<div class="value">{{ item.value.toLocaleString() }}</div>
|
||||
<div class="trend" :class="item.isUp ? 'up' : 'down'">
|
||||
{{ item.isUp ? '↑' : '↓' }} {{ item.percentage }}%
|
||||
<div class="value">{{ (item.value || 0).toLocaleString() }}</div>
|
||||
<div
|
||||
v-if="item.percentage !== null && item.percentage !== undefined"
|
||||
class="trend"
|
||||
:class="item.isUp ? 'up' : 'down'"
|
||||
>
|
||||
{{ item.isUp ? "↑" : "↓" }} {{ item.percentage }}%
|
||||
<span>较上月</span>
|
||||
</div>
|
||||
<div v-else class="trend">
|
||||
<span class="sub-text">{{ item.sub }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
@@ -22,12 +29,12 @@
|
||||
|
||||
<el-row :gutter="20" class="charts-row">
|
||||
<el-col :xs="24" :sm="24" :md="16">
|
||||
<el-card shadow="hover" header="用户增长趋势">
|
||||
<el-card shadow="hover" header="近 14 天新增用户 / 租户">
|
||||
<div ref="lineChartRef" class="chart-box"></div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :xs="24" :sm="24" :md="8">
|
||||
<el-card shadow="hover" header="用户等级分布">
|
||||
<el-card shadow="hover" header="租户用户数分布">
|
||||
<div ref="pieChartRef" class="chart-box"></div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
@@ -36,111 +43,186 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, onUnmounted, shallowRef } from 'vue';
|
||||
import * as echarts from 'echarts';
|
||||
import { User, Pointer, Connection, Histogram } from '@element-plus/icons-vue';
|
||||
import { ref, onMounted, onUnmounted, shallowRef, nextTick } from "vue";
|
||||
import * as echarts from "echarts";
|
||||
import { ElMessage } from "element-plus";
|
||||
import { User, OfficeBuilding, Pointer, Connection } from "@element-plus/icons-vue";
|
||||
import { getPlatformUserAnalytics } from "@/api/analytics";
|
||||
|
||||
// --- 类型定义 ---
|
||||
interface SummaryItem {
|
||||
title: string;
|
||||
value: number;
|
||||
icon: any;
|
||||
color: string;
|
||||
percentage: number;
|
||||
isUp: boolean;
|
||||
percentage?: number | null;
|
||||
isUp?: boolean;
|
||||
sub?: string;
|
||||
}
|
||||
|
||||
// --- 响应式数据 ---
|
||||
const loading = ref(false);
|
||||
const lineChartRef = ref<HTMLElement | null>(null);
|
||||
const pieChartRef = ref<HTMLElement | null>(null);
|
||||
const lineChartInstance = shallowRef<echarts.ECharts | null>(null);
|
||||
const pieChartInstance = shallowRef<echarts.ECharts | null>(null);
|
||||
|
||||
const summaryData = ref<SummaryItem[]>([
|
||||
{ title: '总用户数', value: 12840, icon: User, color: '#3973FF', percentage: 12, isUp: true },
|
||||
{ title: '今日新增', value: 156, icon: Pointer, color: '#67C23A', percentage: 5, isUp: true },
|
||||
{ title: '活跃用户', value: 3420, icon: Connection, color: '#E6A23C', percentage: 2, isUp: false },
|
||||
{ title: '留存率', value: 85, icon: Histogram, color: '#F56C6C', percentage: 1, isUp: true },
|
||||
{ title: "总用户数", value: 0, icon: User, color: "#3973FF", percentage: 0, isUp: true },
|
||||
{ title: "租户数", value: 0, icon: OfficeBuilding, color: "#67C23A", sub: "启用 0 / 共 0" },
|
||||
{ title: "今日新增用户", value: 0, icon: Pointer, color: "#E6A23C", sub: "本月新增 0" },
|
||||
{ title: "近 30 天活跃用户", value: 0, icon: Connection, color: "#F56C6C", sub: "今日登录 0 次" },
|
||||
]);
|
||||
|
||||
// --- 初始化图表 ---
|
||||
const initCharts = () => {
|
||||
// 折线图配置
|
||||
if (lineChartRef.value) {
|
||||
lineChartInstance.value = echarts.init(lineChartRef.value);
|
||||
lineChartInstance.value.setOption({
|
||||
tooltip: { trigger: 'axis' },
|
||||
grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true },
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
boundaryGap: false,
|
||||
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
|
||||
},
|
||||
yAxis: { type: 'value' },
|
||||
series: [
|
||||
{
|
||||
name: '新增用户',
|
||||
type: 'line',
|
||||
smooth: true,
|
||||
data: [120, 132, 101, 134, 90, 230, 210],
|
||||
areaStyle: { opacity: 0.3 },
|
||||
itemStyle: { color: '#3973FF' }
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
const trendOption = (days: string[], users: number[], tenants: number[]) => ({
|
||||
tooltip: { trigger: "axis" },
|
||||
legend: { data: ["新增用户", "新增租户"], top: 4 },
|
||||
grid: { left: "3%", right: "4%", bottom: "3%", top: 48, containLabel: true },
|
||||
xAxis: {
|
||||
type: "category",
|
||||
boundaryGap: false,
|
||||
data: days,
|
||||
},
|
||||
yAxis: { type: "value", minInterval: 1 },
|
||||
series: [
|
||||
{
|
||||
name: "新增用户",
|
||||
type: "line",
|
||||
smooth: true,
|
||||
data: users,
|
||||
areaStyle: { opacity: 0.12 },
|
||||
itemStyle: { color: "#3973FF" },
|
||||
},
|
||||
{
|
||||
name: "新增租户",
|
||||
type: "line",
|
||||
smooth: true,
|
||||
data: tenants,
|
||||
itemStyle: { color: "#67C23A" },
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// 饼图配置
|
||||
if (pieChartRef.value) {
|
||||
const pieOption = (items: { name: string; value: number }[]) => ({
|
||||
tooltip: { trigger: "item", formatter: "{b}: {c} 人({d}%)" },
|
||||
legend: {
|
||||
orient: "vertical",
|
||||
right: "5%",
|
||||
top: "center",
|
||||
type: "scroll",
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: "租户用户数",
|
||||
type: "pie",
|
||||
radius: ["40%", "70%"],
|
||||
center: ["35%", "50%"],
|
||||
avoidLabelOverlap: false,
|
||||
itemStyle: { borderRadius: 10, borderColor: "#fff", borderWidth: 2 },
|
||||
label: { show: false },
|
||||
data: items.length ? items : [{ name: "暂无数据", value: 0 }],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const initCharts = () => {
|
||||
if (lineChartRef.value && !lineChartInstance.value) {
|
||||
lineChartInstance.value = echarts.init(lineChartRef.value);
|
||||
lineChartInstance.value.setOption(trendOption([], [], []));
|
||||
}
|
||||
if (pieChartRef.value && !pieChartInstance.value) {
|
||||
pieChartInstance.value = echarts.init(pieChartRef.value);
|
||||
pieChartInstance.value.setOption({
|
||||
tooltip: { trigger: 'item' },
|
||||
legend: {
|
||||
orient: 'vertical',
|
||||
right: '5%',
|
||||
top: 'center',
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: '等级分布',
|
||||
type: 'pie',
|
||||
radius: ['40%', '70%'],
|
||||
center: ['35%', '50%'],
|
||||
avoidLabelOverlap: false,
|
||||
itemStyle: { borderRadius: 10, borderColor: '#fff', borderWidth: 2 },
|
||||
label: { show: false },
|
||||
data: [
|
||||
{ value: 1048, name: '普通用户' },
|
||||
{ value: 735, name: 'VIP会员' },
|
||||
{ value: 580, name: '超级管理员' },
|
||||
{ value: 484, name: '运营人员' }
|
||||
]
|
||||
}
|
||||
]
|
||||
});
|
||||
pieChartInstance.value.setOption(pieOption([]));
|
||||
}
|
||||
};
|
||||
|
||||
const renderCharts = (trend: any, tenantUserTop: any[]) => {
|
||||
lineChartInstance.value?.setOption(
|
||||
trendOption(
|
||||
trend?.days || [],
|
||||
trend?.users || [],
|
||||
trend?.tenants || [],
|
||||
),
|
||||
{ notMerge: true },
|
||||
);
|
||||
pieChartInstance.value?.setOption(pieOption(tenantUserTop || []), {
|
||||
notMerge: true,
|
||||
});
|
||||
};
|
||||
|
||||
const fetchAnalytics = async () => {
|
||||
loading.value = true;
|
||||
try {
|
||||
const res = await getPlatformUserAnalytics();
|
||||
if (!res || res.code !== 200) {
|
||||
throw new Error(res?.msg || "获取统计数据失败");
|
||||
}
|
||||
const data = res.data || {};
|
||||
|
||||
summaryData.value = [
|
||||
{
|
||||
title: "总用户数",
|
||||
value: Number(data.totalUsers) || 0,
|
||||
icon: User,
|
||||
color: "#3973FF",
|
||||
percentage: Number(data.userGrowthPct) || 0,
|
||||
isUp: data.userGrowthUp !== false,
|
||||
},
|
||||
{
|
||||
title: "租户数",
|
||||
value: Number(data.totalTenants) || 0,
|
||||
icon: OfficeBuilding,
|
||||
color: "#67C23A",
|
||||
sub: `启用 ${Number(data.activeTenants) || 0} / 共 ${Number(data.totalTenants) || 0}`,
|
||||
},
|
||||
{
|
||||
title: "今日新增用户",
|
||||
value: Number(data.todayNewUsers) || 0,
|
||||
icon: Pointer,
|
||||
color: "#E6A23C",
|
||||
sub: `本月新增 ${Number(data.monthNewUsers) || 0}`,
|
||||
},
|
||||
{
|
||||
title: "近 30 天活跃用户",
|
||||
value: Number(data.activeUsers30d) || 0,
|
||||
icon: Connection,
|
||||
color: "#F56C6C",
|
||||
sub: `今日登录 ${Number(data.todayLogins) || 0} 次`,
|
||||
},
|
||||
];
|
||||
|
||||
await nextTick();
|
||||
renderCharts(data.trend, data.tenantUserTop);
|
||||
} catch (error: any) {
|
||||
console.error("获取统计数据失败:", error);
|
||||
ElMessage.error(error?.message || error?.response?.data?.msg || "获取统计数据失败");
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// --- 生命周期与自适应 ---
|
||||
const handleResize = () => {
|
||||
lineChartInstance.value?.resize();
|
||||
pieChartInstance.value?.resize();
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
onMounted(async () => {
|
||||
await nextTick();
|
||||
initCharts();
|
||||
window.addEventListener('resize', handleResize);
|
||||
await fetchAnalytics();
|
||||
window.addEventListener("resize", handleResize);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('resize', handleResize);
|
||||
window.removeEventListener("resize", handleResize);
|
||||
lineChartInstance.value?.dispose();
|
||||
lineChartInstance.value = null;
|
||||
pieChartInstance.value?.dispose();
|
||||
pieChartInstance.value = null;
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.statistics-container {
|
||||
padding: 20px;
|
||||
min-height: 100vh;
|
||||
|
||||
.data-overview {
|
||||
margin-bottom: 20px;
|
||||
@@ -167,6 +249,7 @@ onUnmounted(() => {
|
||||
|
||||
.text-box {
|
||||
min-width: 0;
|
||||
|
||||
.title {
|
||||
font-size: 14px;
|
||||
color: #909399;
|
||||
@@ -174,17 +257,34 @@ onUnmounted(() => {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.value {
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
margin: 4px 0;
|
||||
color: var(--el-text-color-primary);
|
||||
}
|
||||
|
||||
.trend {
|
||||
font-size: 12px;
|
||||
&.up { color: #67c23a; }
|
||||
&.down { color: #f56c6c; }
|
||||
span { color: #909399; margin-left: 4px; }
|
||||
|
||||
&.up {
|
||||
color: #67c23a;
|
||||
}
|
||||
|
||||
&.down {
|
||||
color: #f56c6c;
|
||||
}
|
||||
|
||||
span {
|
||||
color: #909399;
|
||||
margin-left: 4px;
|
||||
}
|
||||
|
||||
.sub-text {
|
||||
color: #909399;
|
||||
margin-left: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -195,11 +295,19 @@ onUnmounted(() => {
|
||||
.el-col {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.chart-box {
|
||||
height: 350px;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
// 暗色主题:卡片数字用纯白
|
||||
html.dark & {
|
||||
.data-overview .data-card .card-content .text-box .value {
|
||||
color: #fff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
@@ -213,6 +321,7 @@ onUnmounted(() => {
|
||||
font-size: 20px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.text-box .value {
|
||||
font-size: 20px;
|
||||
}
|
||||
@@ -224,10 +333,9 @@ onUnmounted(() => {
|
||||
}
|
||||
}
|
||||
|
||||
// 深度修改 Element Plus 卡片头部样式
|
||||
:deep(.el-card__header) {
|
||||
font-weight: bold;
|
||||
font-size: 16px;
|
||||
border-bottom: 1px solid #ebeef5;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
@@ -0,0 +1,269 @@
|
||||
<template>
|
||||
<div class="container-box">
|
||||
<div class="header-bar">
|
||||
<h2>存储套餐</h2>
|
||||
<div class="header-actions">
|
||||
<el-button @click="refresh">刷新</el-button>
|
||||
<el-button type="primary" @click="openCreate">新增套餐</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<el-alert
|
||||
type="info"
|
||||
:closable="false"
|
||||
show-icon
|
||||
class="tips"
|
||||
title="附件空间单独计费:租户默认 500MB,超出后购买这里的套餐扩容。容量按「实际可用 = max(基础额度, 生效套餐容量)」计算。"
|
||||
/>
|
||||
|
||||
<el-table :data="list" v-loading="loading" border stripe>
|
||||
<el-table-column prop="name" label="套餐名称" min-width="140" />
|
||||
<el-table-column prop="code" label="编码" min-width="120" />
|
||||
<el-table-column label="容量" width="120">
|
||||
<template #default="{ row }">{{ formatCapacity(row.capacity_mb) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="价格" width="110">
|
||||
<template #default="{ row }">¥{{ Number(row.price || 0).toFixed(2) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="时长" width="110">
|
||||
<template #default="{ row }">{{ durationText(row.duration_days) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="sort" label="排序" width="80" />
|
||||
<el-table-column label="状态" width="100">
|
||||
<template #default="{ row }">
|
||||
<el-switch
|
||||
:model-value="Number(row.status) === 1"
|
||||
@change="(val) => handleToggle(row, val)"
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="remark" label="备注" min-width="160" show-overflow-tooltip />
|
||||
<el-table-column label="操作" width="150" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" @click="openEdit(row)">编辑</el-button>
|
||||
<el-button link type="danger" @click="handleDelete(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<el-dialog
|
||||
v-model="dialogVisible"
|
||||
:title="editingId ? '编辑套餐' : '新增套餐'"
|
||||
width="520px"
|
||||
:close-on-click-modal="false"
|
||||
>
|
||||
<el-form ref="formRef" :model="form" :rules="rules" label-width="110px">
|
||||
<el-form-item label="套餐名称" prop="name">
|
||||
<el-input v-model="form.name" placeholder="如:5GB" maxlength="64" />
|
||||
</el-form-item>
|
||||
<el-form-item label="套餐编码" prop="code">
|
||||
<el-input v-model="form.code" placeholder="如:storage_5g(可留空)" maxlength="64" />
|
||||
</el-form-item>
|
||||
<el-form-item label="容量(MB)" prop="capacity_mb">
|
||||
<el-input-number v-model="form.capacity_mb" :min="1" :step="1024" class="full" />
|
||||
<div class="form-tip">1024MB = 1GB,例如 5GB 填 5120</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="价格(元)" prop="price">
|
||||
<el-input-number v-model="form.price" :min="0" :precision="2" :step="10" class="full" />
|
||||
</el-form-item>
|
||||
<el-form-item label="有效天数" prop="duration_days">
|
||||
<el-input-number v-model="form.duration_days" :min="1" :step="30" class="full" />
|
||||
<div class="form-tip">365 = 一年,90 = 一季度</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="排序">
|
||||
<el-input-number v-model="form.sort" :min="0" class="full" />
|
||||
</el-form-item>
|
||||
<el-form-item label="备注">
|
||||
<el-input v-model="form.remark" type="textarea" :rows="2" maxlength="255" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="dialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="saving" @click="handleSave">保存</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref } from "vue";
|
||||
import { ElMessage, ElMessageBox, type FormInstance, type FormRules } from "element-plus";
|
||||
import {
|
||||
createStoragePackage,
|
||||
deleteStoragePackage,
|
||||
getStoragePackages,
|
||||
toggleStoragePackage,
|
||||
updateStoragePackage,
|
||||
} from "@/api/storage";
|
||||
|
||||
const loading = ref(false);
|
||||
const list = ref<any[]>([]);
|
||||
|
||||
const dialogVisible = ref(false);
|
||||
const saving = ref(false);
|
||||
const editingId = ref<number | null>(null);
|
||||
const formRef = ref<FormInstance>();
|
||||
|
||||
const form = reactive({
|
||||
name: "",
|
||||
code: "",
|
||||
capacity_mb: 5120,
|
||||
price: 0,
|
||||
duration_days: 365,
|
||||
sort: 0,
|
||||
remark: "",
|
||||
});
|
||||
|
||||
const rules: FormRules = {
|
||||
name: [{ required: true, message: "请填写套餐名称", trigger: "blur" }],
|
||||
capacity_mb: [{ required: true, message: "请填写容量", trigger: "blur" }],
|
||||
};
|
||||
|
||||
const formatCapacity = (mb: any) => {
|
||||
const n = Number(mb) || 0;
|
||||
return n >= 1024 ? `${(n / 1024).toFixed(n % 1024 === 0 ? 0 : 1)} GB` : `${n} MB`;
|
||||
};
|
||||
|
||||
const durationText = (days: any) => {
|
||||
const n = Number(days) || 0;
|
||||
if (n === 365) return "1 年";
|
||||
if (n === 180) return "半年";
|
||||
if (n === 90) return "1 季";
|
||||
if (n === 30) return "1 月";
|
||||
return `${n} 天`;
|
||||
};
|
||||
|
||||
const loadList = async () => {
|
||||
loading.value = true;
|
||||
try {
|
||||
const res = await getStoragePackages();
|
||||
list.value = res?.code === 200 ? res.data?.list || [] : [];
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message || "加载套餐失败");
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const refresh = async () => {
|
||||
await loadList();
|
||||
ElMessage.success("刷新成功");
|
||||
};
|
||||
|
||||
const resetForm = () => {
|
||||
editingId.value = null;
|
||||
form.name = "";
|
||||
form.code = "";
|
||||
form.capacity_mb = 5120;
|
||||
form.price = 0;
|
||||
form.duration_days = 365;
|
||||
form.sort = 0;
|
||||
form.remark = "";
|
||||
};
|
||||
|
||||
const openCreate = () => {
|
||||
resetForm();
|
||||
dialogVisible.value = true;
|
||||
};
|
||||
|
||||
const openEdit = (row: any) => {
|
||||
editingId.value = row.id;
|
||||
form.name = row.name || "";
|
||||
form.code = row.code || "";
|
||||
form.capacity_mb = Number(row.capacity_mb) || 0;
|
||||
form.price = Number(row.price) || 0;
|
||||
form.duration_days = Number(row.duration_days) || 365;
|
||||
form.sort = Number(row.sort) || 0;
|
||||
form.remark = row.remark || "";
|
||||
dialogVisible.value = true;
|
||||
};
|
||||
|
||||
const handleSave = async () => {
|
||||
if (!formRef.value) return;
|
||||
const valid = await formRef.value.validate().catch(() => false);
|
||||
if (!valid) return;
|
||||
|
||||
saving.value = true;
|
||||
try {
|
||||
const payload = { ...form };
|
||||
const res = editingId.value
|
||||
? await updateStoragePackage(editingId.value, payload)
|
||||
: await createStoragePackage(payload);
|
||||
if (res?.code !== 200) {
|
||||
ElMessage.error(res?.msg || "保存失败");
|
||||
return;
|
||||
}
|
||||
ElMessage.success("保存成功");
|
||||
dialogVisible.value = false;
|
||||
await loadList();
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message || "保存失败");
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleToggle = async (row: any, val: boolean) => {
|
||||
try {
|
||||
const res = await toggleStoragePackage(row.id, val ? 1 : 0);
|
||||
if (res?.code !== 200) {
|
||||
ElMessage.error(res?.msg || "更新失败");
|
||||
return;
|
||||
}
|
||||
row.status = val ? 1 : 0;
|
||||
ElMessage.success("已更新");
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message || "更新失败");
|
||||
}
|
||||
};
|
||||
|
||||
const handleDelete = async (row: any) => {
|
||||
try {
|
||||
await ElMessageBox.confirm(`确认删除套餐「${row.name}」?`, "提示", {
|
||||
type: "warning",
|
||||
confirmButtonText: "确定",
|
||||
cancelButtonText: "取消",
|
||||
});
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const res = await deleteStoragePackage(row.id);
|
||||
if (res?.code !== 200) {
|
||||
ElMessage.error(res?.msg || "删除失败");
|
||||
return;
|
||||
}
|
||||
ElMessage.success("删除成功");
|
||||
await loadList();
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message || "删除失败");
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(loadList);
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.header-bar {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.header-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.tips {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.full {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.form-tip {
|
||||
margin-top: 4px;
|
||||
font-size: 12px;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
</style>
|
||||
@@ -53,10 +53,9 @@
|
||||
* 租户详情内「添加用户」:提交到 /platform/tenantUser/create,
|
||||
* 后端写入 yz_tenant_user(租户-用户绑定,含冗余账号/密码等字段)。
|
||||
*/
|
||||
import { ref, reactive, onMounted } from 'vue';
|
||||
import { ref, reactive } from 'vue';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { createTenantUser } from '@/api/tenantUser';
|
||||
import { getOrganizationList } from '@/api/erp';
|
||||
import { createTenantUser, getTenantOrganizations } from '@/api/tenantUser';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const visible = ref(false);
|
||||
@@ -96,11 +95,14 @@ const buildOrgTree = (list: any[]): any[] => {
|
||||
return tree;
|
||||
};
|
||||
|
||||
const loadOrgs = async () => {
|
||||
// 部门下拉取「当前租户」的组织架构(平台自己的组织与租户无关)
|
||||
const loadOrgs = async (tid: number | null) => {
|
||||
orgTree.value = [];
|
||||
if (!tid) return;
|
||||
try {
|
||||
const res = await getOrganizationList();
|
||||
const res = await getTenantOrganizations(tid);
|
||||
if (res?.code === 200) {
|
||||
const list = res?.data?.list || res?.data || [];
|
||||
const list = res?.data?.list || [];
|
||||
orgTree.value = buildOrgTree(list);
|
||||
}
|
||||
} catch {
|
||||
@@ -108,8 +110,6 @@ const loadOrgs = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(loadOrgs);
|
||||
|
||||
const rules = {
|
||||
account: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
|
||||
password: [{ required: true, message: '请输入密码', trigger: 'blur', min: 5 }],
|
||||
@@ -151,6 +151,8 @@ const open = (tenantId: number) => {
|
||||
status: 1,
|
||||
org_id: undefined
|
||||
});
|
||||
// 每次打开都按当前租户拉一次部门,避免沿用上一个租户的组织
|
||||
loadOrgs(tenantId);
|
||||
};
|
||||
|
||||
const submitForm = async () => {
|
||||
|
||||
@@ -39,6 +39,11 @@
|
||||
controls-position="right" />
|
||||
<div class="form-tip">默认 20 人;达到上限后需增购用户数才能继续开账号</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="附件空间(MB)" prop="storage_quota_mb">
|
||||
<el-input-number v-model="formData.storage_quota_mb" :min="0" :step="512"
|
||||
controls-position="right" />
|
||||
<div class="form-tip">默认 500MB;实际可用空间取「本值」与「租户已购存储套餐」的较大者</div>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="!formData.id" label="指定管理员" prop="admin_identifier">
|
||||
<el-input v-model="formData.admin_identifier" placeholder="选填:已有用户的账号或手机号" clearable />
|
||||
<div class="form-tip">填已有用户,创建后自动绑定为该租户的管理员(不新建账号、不修改其原密码);留空则租户暂无管理员</div>
|
||||
@@ -114,6 +119,7 @@ const initialData = {
|
||||
status: 1,
|
||||
package_id: undefined as number | undefined,
|
||||
user_quota: 20,
|
||||
storage_quota_mb: 500,
|
||||
admin_identifier: '' as string
|
||||
};
|
||||
|
||||
|
||||
@@ -124,14 +124,15 @@
|
||||
</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="status" label="租户状态" width="80" align="center">
|
||||
<!-- 状态与操作都固定在右侧:避免横向滚动时操作列盖住状态标签 -->
|
||||
<el-table-column prop="status" label="租户状态" width="90" align="center" fixed="right">
|
||||
<template #default="scope">
|
||||
<el-tag :type="scope.row.status === 1 ? 'success' : 'danger'">{{
|
||||
scope.row.status === 1 ? "启用" : "禁用"
|
||||
}}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="160" align="center" fixed="right">
|
||||
<el-table-column label="操作" width="110" align="center" fixed="right">
|
||||
<template #default="scope">
|
||||
<div class="action-icons">
|
||||
<el-tooltip content="编辑" placement="top">
|
||||
@@ -321,7 +322,20 @@ onMounted(() => {
|
||||
.action-icons {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
justify-content: center;
|
||||
gap: 4px;
|
||||
|
||||
// 图标按钮保持正方形热区,避免被单元格压缩变形
|
||||
:deep(.el-button.is-text) {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
padding: 0;
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
:deep(.el-icon) {
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 暗色主题适配 =====
|
||||
|
||||
@@ -342,7 +342,6 @@ onUnmounted(() => {
|
||||
<style scoped lang="less">
|
||||
.statistics-container {
|
||||
padding: 20px;
|
||||
min-height: 100vh;
|
||||
|
||||
.data-overview {
|
||||
margin-bottom: 20px;
|
||||
|
||||
@@ -219,6 +219,25 @@ const cleanCaptchaInstance = () => {
|
||||
}
|
||||
};
|
||||
|
||||
// --- 登录成功后的统一收尾 ---
|
||||
// 重置动态路由加载状态并强制刷新菜单缓存:
|
||||
// 否则可能沿用上一次会话的「已加载」标记或他人账号的菜单缓存,
|
||||
// 导致业务路由没有按本次登录重建,跳转 /home 时命中 404。
|
||||
const afterLogin = async () => {
|
||||
try {
|
||||
const [{ useMenuStore }, { resetDynamicRoutes }] = await Promise.all([
|
||||
import("@/stores/menu"),
|
||||
import("@/router/index"),
|
||||
]);
|
||||
resetDynamicRoutes();
|
||||
await useMenuStore().refreshMenus();
|
||||
} catch (err) {
|
||||
// 菜单拉取失败不阻断登录,路由守卫会再次尝试加载
|
||||
console.warn("登录后刷新菜单失败:", err);
|
||||
}
|
||||
router.push({ path: "/home" });
|
||||
};
|
||||
|
||||
// --- 执行登录请求 ---
|
||||
const performLoginRequest = async () => {
|
||||
const res = await login({
|
||||
@@ -247,7 +266,7 @@ const performLoginRequest = async () => {
|
||||
const tabsStore = useTabsStore();
|
||||
tabsStore.resetTabs();
|
||||
|
||||
router.push({ path: "/home" });
|
||||
await afterLogin();
|
||||
ElMessage.success("登录成功!");
|
||||
return true;
|
||||
} else {
|
||||
@@ -368,7 +387,7 @@ const startGeetest4 = async () => {
|
||||
const { useTabsStore } = await import("@/stores");
|
||||
const tabsStore = useTabsStore();
|
||||
tabsStore.resetTabs();
|
||||
router.push({ path: "/home" });
|
||||
await afterLogin();
|
||||
ElMessage.success("登录成功!");
|
||||
} else {
|
||||
errorMsg.value = loginRes.msg || "登录失败";
|
||||
|
||||
Reference in new issue
Block a user