|
@@ -8,10 +8,13 @@ import { LogoutOutlined } from '@ant-design/icons-vue';
|
|
|
import { useElementSize } from '@vueuse/core';
|
|
import { useElementSize } from '@vueuse/core';
|
|
|
import { useRequest } from 'alova/client';
|
|
import { useRequest } from 'alova/client';
|
|
|
import { notification } from 'ant-design-vue';
|
|
import { notification } from 'ant-design-vue';
|
|
|
|
|
+import type { MenuProps } from 'ant-design-vue';
|
|
|
|
|
|
|
|
import { storeToRefs } from 'pinia';
|
|
import { storeToRefs } from 'pinia';
|
|
|
import { VxeButton, VxeUI } from 'vxe-pc-ui';
|
|
import { VxeButton, VxeUI } from 'vxe-pc-ui';
|
|
|
|
|
|
|
|
|
|
+defineOptions({ name: 'IndexPage' });
|
|
|
|
|
+
|
|
|
const title = import.meta.env.SIX_TITLE;
|
|
const title = import.meta.env.SIX_TITLE;
|
|
|
const Account = useAccountStore();
|
|
const Account = useAccountStore();
|
|
|
const { local, menus, token } = storeToRefs(Account);
|
|
const { local, menus, token } = storeToRefs(Account);
|
|
@@ -20,50 +23,28 @@ const titleRef = ref();
|
|
|
const { width } = useElementSize(titleRef, void 0, { box: 'border-box' });
|
|
const { width } = useElementSize(titleRef, void 0, { box: 'border-box' });
|
|
|
|
|
|
|
|
const router = useRouter();
|
|
const router = useRouter();
|
|
|
-// 记录用户是否点了菜单
|
|
|
|
|
-const hasUserNavigated = ref(false);
|
|
|
|
|
-
|
|
|
|
|
-// 监听路由变化,标记用户已经点了菜单
|
|
|
|
|
-watch(
|
|
|
|
|
- () => router.currentRoute.value.path,
|
|
|
|
|
- (newPath, oldPath) => {
|
|
|
|
|
- if (oldPath && oldPath !== '/' && newPath !== oldPath) {
|
|
|
|
|
- hasUserNavigated.value = true;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+function findMenuKeyDeep(items: any[] | undefined, targetKey: string): string | undefined {
|
|
|
|
|
+ if (!items?.length) return void 0;
|
|
|
|
|
+ for (const item of items) {
|
|
|
|
|
+ if (item?.key === targetKey) return item.key;
|
|
|
|
|
+ const hit = findMenuKeyDeep(item?.children as any[], targetKey);
|
|
|
|
|
+ if (hit) return hit;
|
|
|
}
|
|
}
|
|
|
-);
|
|
|
|
|
|
|
+ return void 0;
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
const selectedKeys = computed(() => {
|
|
const selectedKeys = computed(() => {
|
|
|
- // 获取当前路由路径
|
|
|
|
|
const currentPath = router.currentRoute.value.path;
|
|
const currentPath = router.currentRoute.value.path;
|
|
|
|
|
+ if (currentPath && currentPath !== '/') return [currentPath];
|
|
|
|
|
|
|
|
- // 检查是否有患者管理权限(菜单中有 /patient/history 就说明有权限)
|
|
|
|
|
- const hasPatientPermission = menus.value?.some((menu) => menu.key === '/patient/history' || menu.label === '患者管理' || menu.title === '患者管理') ?? false;
|
|
|
|
|
-
|
|
|
|
|
- // 当前在患者管理页面,直接高亮当前路由
|
|
|
|
|
- if (hasUserNavigated.value || currentPath.startsWith('/patient')) {
|
|
|
|
|
- return [currentPath];
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- //有患者管理权限,默认高亮患者管理菜单
|
|
|
|
|
- if (hasPatientPermission) {
|
|
|
|
|
- const patientMenu = menus.value?.find((menu) => menu.key === '/patient/history');
|
|
|
|
|
- if (patientMenu) {
|
|
|
|
|
- return [patientMenu.key];
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 如果没有患者管理权限,高亮第一个菜单
|
|
|
|
|
- if (menus.value && menus.value.length > 0) {
|
|
|
|
|
- return [menus.value[0].key];
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ const patientKey = findMenuKeyDeep(menus.value as any[], '/patient/history');
|
|
|
|
|
+ if (patientKey) return [patientKey];
|
|
|
|
|
|
|
|
- // 默认返回当前路由
|
|
|
|
|
- return [currentPath];
|
|
|
|
|
|
|
+ return [menus.value?.[0]?.key ?? '/'];
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
-const selectMenuItem = ({ item, key, keyPath }) => {
|
|
|
|
|
- router.push({ path: key }).then();
|
|
|
|
|
|
|
+const selectMenuItem: MenuProps['onClick'] = (info) => {
|
|
|
|
|
+ router.push({ path: String(info.key) }).then();
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
function handleLogout() {
|
|
function handleLogout() {
|
|
@@ -71,8 +52,6 @@ function handleLogout() {
|
|
|
router.replace({ path: '/login' });
|
|
router.replace({ path: '/login' });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const current = ref<string[]>([]);
|
|
|
|
|
-
|
|
|
|
|
const { loading: userLoading, send: loadUser } = useRequest(
|
|
const { loading: userLoading, send: loadUser } = useRequest(
|
|
|
() => accountMethod(token.value!),
|
|
() => accountMethod(token.value!),
|
|
|
|
|
|
|
@@ -89,7 +68,7 @@ async function openUserPreview() {
|
|
|
escClosable: true,
|
|
escClosable: true,
|
|
|
slots: {
|
|
slots: {
|
|
|
default() {
|
|
default() {
|
|
|
- return h(UserPreview, <any>{ data: model, request: false });
|
|
|
|
|
|
|
+ return h(UserPreview, { data: model, request: false } as any);
|
|
|
},
|
|
},
|
|
|
corner() {
|
|
corner() {
|
|
|
return h(VxeButton, {
|
|
return h(VxeButton, {
|
|
@@ -104,7 +83,7 @@ async function openUserPreview() {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function updateUserPassword(model: UserModel, index?: number) {
|
|
|
|
|
|
|
+function updateUserPassword(model: UserModel) {
|
|
|
const { userName } = model;
|
|
const { userName } = model;
|
|
|
VxeUI.modal.open({
|
|
VxeUI.modal.open({
|
|
|
title: `重置 ${userName} 登录密码`,
|
|
title: `重置 ${userName} 登录密码`,
|
|
@@ -116,10 +95,10 @@ function updateUserPassword(model: UserModel, index?: number) {
|
|
|
mask: false,
|
|
mask: false,
|
|
|
slots: {
|
|
slots: {
|
|
|
default() {
|
|
default() {
|
|
|
- return h(UserPassword, <any>{
|
|
|
|
|
|
|
+ return h(UserPassword, {
|
|
|
update: true,
|
|
update: true,
|
|
|
data: model,
|
|
data: model,
|
|
|
- onSubmit(data?: UserModel) {
|
|
|
|
|
|
|
+ onSubmit() {
|
|
|
notification.success({
|
|
notification.success({
|
|
|
message: `重置用户: ${userName} 的登录密码`,
|
|
message: `重置用户: ${userName} 的登录密码`,
|
|
|
description: '操作成功',
|
|
description: '操作成功',
|
|
@@ -128,11 +107,14 @@ function updateUserPassword(model: UserModel, index?: number) {
|
|
|
VxeUI.drawer.close();
|
|
VxeUI.drawer.close();
|
|
|
router.push({ path: '/login' });
|
|
router.push({ path: '/login' });
|
|
|
},
|
|
},
|
|
|
- });
|
|
|
|
|
|
|
+ } as any);
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
+onMounted(() => {
|
|
|
|
|
+ console.log(menus.value, '菜单权限');
|
|
|
|
|
+});
|
|
|
</script>
|
|
</script>
|
|
|
<template>
|
|
<template>
|
|
|
<div class="page-container flex flex-col h-vh w-vw">
|
|
<div class="page-container flex flex-col h-vh w-vw">
|