huangyinfeng
6 天以前 a9a03d64cf190188d3db04d14970fc0908b03491
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<template>
  <PageWrapper dense contentFullHeight fixedHeight>
    <div>
      <div class="header-container">
        <span class="button-group">
          <a-button shape="circle" size="large">
            <MailOutlined />
          </a-button>
          <a-button shape="circle" size="large">
            <UserOutlined />
          </a-button>
        </span>
        <a-button
          class="write-button"
          type="primary"
          size="large"
          shape="round"
          @click="$router.push('/email/edit')"
        >
          写信
        </a-button>
      </div>
 
      <div class="menu-container">
        <a-menu
          id="email-left-nav"
          v-model:open-keys="openKeys"
          v-model:selected-keys="selectedKeys"
          mode="inline"
          :popupClassName="popupClassName"
        >
          <template v-for="item in menuItems" :key="item.key">
            <render-menu-item :item="item" @click="handleClick" />
          </template>
        </a-menu>
        <a-divider />
        <a-menu
          id="email-left-nav2"
          v-model:open-keys="openKeys"
          v-model:selected-keys="selectedKeys"
          mode="inline"
          :popupClassName="popupClassName"
        >
          <template v-for="item in menuItems2" :key="item.key">
            <render-menu-item :item="item" @click="handleClick" />
          </template>
        </a-menu>
      </div>
    </div>
  </PageWrapper>
</template>
 
<script lang="ts" setup>
import { ref, onMounted, computed } from 'vue';
import { PageWrapper } from '@/components/Page';
import { MailOutlined, UserOutlined } from '@ant-design/icons-vue';
import { getEmailModuleApi, getEmailModuleBelowApi } from '@/api/email/userList';
import { useRouter } from 'vue-router';
 
interface MenuItem {
  key: string;
  title: string;
  total?: number;
  children?: MenuItem[];
}
 
const selectedKeys = ref<string[]>(['Index']);
const openKeys = ref<string[]>(['Inbox']);
const items = ref<MenuItem[]>([]);
const items2 = ref<MenuItem[]>([]);
 
const fetchEmailModules = async () => {
  try {
    const [res, res2] = await Promise.all([getEmailModuleApi(), getEmailModuleBelowApi()]);
    items.value = convertRoutesToMenuItems(res.data);
    items2.value = convertRoutesToMenuItems2(res2.data);
  } catch (error) {
    console.error('获取邮箱模块失败:', error);
  }
};
 
const convertRoutesToMenuItems = (routes: any[]): MenuItem[] => {
  return routes
    .map(route => ({
      key: route.key,
      title: route.mailName,
      total: route.total,
      children: route.children ? convertRoutesToMenuItems(route.children) : undefined,
    }))
    .filter(Boolean) as MenuItem[];
};
 
const convertRoutesToMenuItems2 = (routes: any[]): MenuItem[] => {
  return routes
    .map(route => ({
      key: route.key,
      title: route.name,
      total: route.number,
      children: route.list ? convertRoutesToMenuItems2(route.list) : undefined,
    }))
    .filter(Boolean) as MenuItem[];
};
 
onMounted(fetchEmailModules);
 
const routesConfig = {
  InboxPage1: '/email/index',
  receiver: '/email/Inbox/list',
  sender: '/email/outbox/list',
  IndexPage1: '/email/outbox',
};
 
const router = useRouter();
const handleClick = (item: MenuItem) => {
  const routePath = routesConfig[item.key] || router.getRoutes().find(r => r.name === item.key)?.path;
  if (routePath) {
    router.push(routePath);
  } else {
    console.warn(`Unknown key: ${item.key}`);
  }
};
 
const popupClassName = {
  display: 'flex',
  'align-items': 'center',
  'justify-content': 'space-between',
};
</script>
 
<style lang="less" scoped>
.header-container {
  height: 15vh;
  padding: 20px 40px;
  text-align: center;
}
 
.button-group {
  display: flex;
  justify-content: space-around;
}
 
.write-button {
  width: 100%;
  margin-top: 10px;
  padding: 0 30px;
}
 
.menu-container {
  height: 70vh;
  overflow: auto;
}
 
.my-display {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
 
.my-left {
  margin-left: 5px;
}
</style>