| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- <template>
- <div class="home-page">
- <!-- Header -->
- <div class="header">
- <div class="logo">
- <img src="@/assets/images/home/logo@2x.png" alt="STORLEAD" />
- </div>
- <div class="user-info">
- <img src="@/assets/images/home/Group@2x.png" alt="User" class="user-avatar" />
- <span class="username">{{ userName }}</span>
-
- </div>
- </div>
- <!-- Main Content -->
- <div class="main-content">
- <div class="section" v-for="app in appList" :key="app.appId">
- <h2 class="section-title">{{ app.appName }}</h2>
- <div class="icon-grid">
- <div class="icon-item" v-for="page in app.appPages" :key="page.pageId" @click="handleClick(page)">
- <div class="icon-wrapper">
- <img :src="getIconPath(page.pageIcon || page.appName)" :alt="page.appName" />
- </div>
- <span class="icon-label">{{ page.appName }}</span>
- </div>
- </div>
- </div>
- </div>
- </div>
- </template>
- <script setup name="Index" lang="ts">
- import { ref, onMounted, computed } from 'vue';
- import { storeToRefs } from 'pinia';
- import { getHomeApp, jumpToPage } from '@/api/app';
- import useUserStore from '@/store/modules/user';
- interface AppPage {
- pageId: number;
- appName: string;
- pageIcon?: string;
- }
- interface AppInfo {
- appId: number;
- appName: string;
- appPages: AppPage[];
- }
- const appList = ref<AppInfo[]>([]);
- const userStore = useUserStore();
- const { userInfo, nickname } = storeToRefs(userStore);
- // 获取用户姓名,优先显示真实姓名,如果没有则显示用户名
- const userName = computed(() => {
- return userInfo.value?.realName || nickname.value || '用户';
- });
- // Helper to get icon path
- const getIconPath = (name: string) => {
- if (!name) {
- return '';
- }
- console.log('name', name);
- return new URL(`/src/assets/homeIcon/${name}@2x.png`, import.meta.url).href;
- };
- const handleClick = async (item: AppPage) => {
- console.log('Clicked:', item.appName, item.pageId);
- try {
- const res = await jumpToPage(item.pageId);
- if (res.result) {
- window.open(res.result, '_blank');
- }
- } catch (error) {
- console.error('Jump to page failed:', error);
- }
- };
- const initData = async () => {
- try {
- const res = await getHomeApp();
- if (res.result) {
- appList.value = res.result;
- }
- } catch (error) {
- console.error('Failed to get home app list:', error);
- }
- };
- onMounted(() => {
- initData();
- });
- </script>
- <style scoped lang="scss">
- .home-page {
- min-height: 100vh;
- background: linear-gradient(180deg, #F5F7FA 0%, #FFFFFF 100%);
- overflow-y: scroll;
- }
- .header {
- position: fixed;
- top: 0;
- left: 0;
- right: 0;
- z-index: 100;
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 20px 40px;
- background: linear-gradient(90deg, #1E88E5 0%, #42A5F5 100%);
- box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
- .logo {
- img {
- height: 32px;
- }
- }
- .user-info {
- display: flex;
- align-items: center;
- gap: 12px;
- color: white;
- cursor: pointer;
- .user-avatar {
- width: 32px;
- height: 32px;
- border-radius: 50%;
- border: 2px solid rgba(255, 255, 255, 0.3);
- }
- .username {
- font-size: 14px;
- font-weight: 500;
- }
- }
- }
- .main-content {
- max-width: 1400px;
- margin: 0 auto;
- padding: 92px 20px 40px 20px; // 72px header height + 20px spacing
- }
- .section {
- margin-bottom: 48px;
- .section-title {
- font-size: 18px;
- font-weight: 600;
- color: #333;
- margin-bottom: 24px;
- padding-left: 12px;
- border-left: 4px solid #1E88E5;
- }
- .icon-grid {
- display: grid;
- grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
- gap: 32px 24px;
- background: white;
- padding: 32px;
- border-radius: 12px;
- box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
- @media (max-width: 768px) {
- grid-template-columns: repeat(4, 1fr);
- gap: 24px 16px;
- padding: 24px;
- }
- @media (max-width: 480px) {
- grid-template-columns: repeat(3, 1fr);
- gap: 20px 12px;
- padding: 20px;
- }
- }
- .icon-item {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: 12px;
- cursor: pointer;
- transition: transform 0.2s ease;
- &:hover {
- transform: translateY(-4px);
- }
- .icon-wrapper {
- width: 64px;
- height: 64px;
- border-radius: 16px;
- display: flex;
- align-items: center;
- justify-content: center;
- transition: all 0.3s ease;
- img {
- width: 64px;
- height: 64px;
- object-fit: contain;
- }
- }
- .icon-label {
- font-size: 14px;
- color: #666;
- text-align: center;
- font-weight: 500;
- white-space: nowrap;
- }
- }
- }
- </style>
|