张田田 пре 8 месеци
родитељ
комит
3a1d5c9db8
3 измењених фајлова са 47 додато и 51 уклоњено
  1. 25 43
      src/pages/index.vue
  2. 9 7
      src/pages/index/care/issueService.vue
  3. 13 1
      src/stores/account.store.ts

+ 25 - 43
src/pages/index.vue

@@ -8,10 +8,13 @@ import { LogoutOutlined } from '@ant-design/icons-vue';
 import { useElementSize } from '@vueuse/core';
 import { useRequest } from 'alova/client';
 import { notification } from 'ant-design-vue';
+import type { MenuProps } from 'ant-design-vue';
 
 import { storeToRefs } from 'pinia';
 import { VxeButton, VxeUI } from 'vxe-pc-ui';
 
+defineOptions({ name: 'IndexPage' });
+
 const title = import.meta.env.SIX_TITLE;
 const Account = useAccountStore();
 const { local, menus, token } = storeToRefs(Account);
@@ -20,50 +23,28 @@ const titleRef = ref();
 const { width } = useElementSize(titleRef, void 0, { box: 'border-box' });
 
 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 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() {
@@ -71,8 +52,6 @@ function handleLogout() {
   router.replace({ path: '/login' });
 }
 
-const current = ref<string[]>([]);
-
 const { loading: userLoading, send: loadUser } = useRequest(
   () => accountMethod(token.value!),
 
@@ -89,7 +68,7 @@ async function openUserPreview() {
     escClosable: true,
     slots: {
       default() {
-        return h(UserPreview, <any>{ data: model, request: false });
+        return h(UserPreview, { data: model, request: false } as any);
       },
       corner() {
         return h(VxeButton, {
@@ -104,7 +83,7 @@ async function openUserPreview() {
   });
 }
 
-function updateUserPassword(model: UserModel, index?: number) {
+function updateUserPassword(model: UserModel) {
   const { userName } = model;
   VxeUI.modal.open({
     title: `重置 ${userName} 登录密码`,
@@ -116,10 +95,10 @@ function updateUserPassword(model: UserModel, index?: number) {
     mask: false,
     slots: {
       default() {
-        return h(UserPassword, <any>{
+        return h(UserPassword, {
           update: true,
           data: model,
-          onSubmit(data?: UserModel) {
+          onSubmit() {
             notification.success({
               message: `重置用户: ${userName} 的登录密码`,
               description: '操作成功',
@@ -128,11 +107,14 @@ function updateUserPassword(model: UserModel, index?: number) {
             VxeUI.drawer.close();
             router.push({ path: '/login' });
           },
-        });
+        } as any);
       },
     },
   });
 }
+onMounted(() => {
+  console.log(menus.value, '菜单权限');
+});
 </script>
 <template>
   <div class="page-container flex flex-col h-vh w-vw">

+ 9 - 7
src/pages/index/care/issueService.vue

@@ -166,9 +166,9 @@ async function getCpRecordDetail(id: string) {
     form.detailAddress = res?.detailAddress;
     form.phone = res?.phone;
     form.healthAnalysisReport = res?.healthAnalysisReport;
-    selectedProvince.value=res?.provinceCode;
-    selectedCity.value=res?.cityCode;
-    selectedArea.value=res?.areaCode
+    selectedProvince.value = res?.provinceCode;
+    selectedCity.value = res?.cityCode;
+    selectedArea.value = res?.areaCode;
   });
 }
 function getPatientList(id: string) {
@@ -192,7 +192,6 @@ onMounted(async () => {
     } else {
       currentPatient.value = res[0];
     }
-   
   }
   if (currentPatient.value?.patientId) {
     // 获取患者列表
@@ -345,6 +344,11 @@ watch(displayTableData, (newValue, oldValue) => {
     isShowDelivery.value = newValue.some((item) => {
       return item.conditioningProgramDetail?.isDelivery === 'Y';
     });
+    if (isShowDelivery.value) {
+      deliveryChecked.value = true;
+    } else {
+      deliveryChecked.value = false;
+    }
     newValue.forEach((row: any) => {
       row.frequencyTypeing = row.frequencyType ? [row.frequencyType] : [];
     });
@@ -610,8 +614,6 @@ function isValidPhone(phone: string): boolean {
   return phoneRegex.test(phone);
 }
 async function handleSubmit() {
-  console.log(deliveryChecked.value, 'deliveryChecked');
-  return;
   if (!currentPatient.value) {
     message.error('请选择患者');
     return;
@@ -621,7 +623,7 @@ async function handleSubmit() {
       delete item.id;
     });
   }
-  form.isDelivery = isShowDelivery.value ? 'Y' : 'N';
+  form.isDelivery = deliveryChecked.value ? 'Y' : 'N';
   form.id = Number(currentPatient.value.id);
   form.patientId = currentPatient.value.patientId;
   form.patientName = currentPatient.value.patientName;

+ 13 - 1
src/stores/account.store.ts

@@ -28,7 +28,9 @@ export const useAccountStore = defineStore('account', () => {
     local.value = data.local;
     menus.value = data.menus;
     permission.value = data.permission;
-    return getFirstMenu(menus.value) ?? '/';
+    // 初次进入:若有患者管理权限,优先进入患者管理;否则进入第一个菜单
+    const preferred = findMenuByKey(menus.value, '/patient/history');
+    return preferred ?? getFirstMenu(menus.value) ?? '/';
   };
 
   const $reset = () => {
@@ -45,3 +47,13 @@ function getFirstMenu(menus?: AccountModel['menus']): string | void {
   const { key, children = [] } = menus?.[ 0 ] ?? {};
   return getFirstMenu(children) ?? key;
 }
+
+function findMenuByKey(menus?: AccountModel['menus'], target?: string): string | void {
+  if (!menus?.length || !target) return void 0;
+  for (const item of menus) {
+    if (item?.key === target) return item.key;
+    const hit = findMenuByKey(item?.children as any, target);
+    if (hit) return hit;
+  }
+  return void 0;
+}