fjrcloud-community-ui/src/views/Home/Index.vue

406 lines
12 KiB
Vue
Raw Normal View History

2026-04-20 14:30:15 +08:00
<template>
2026-04-25 14:20:16 +08:00
<div class="home-container">
<!-- 欢迎区域 -->
<el-card shadow="never" class="welcome-card">
2026-04-20 14:30:15 +08:00
<el-skeleton :loading="loading" animated>
<el-row :gutter="16" justify="space-between">
<el-col :xl="12" :lg="12" :md="12" :sm="24" :xs="24">
<div class="flex items-center">
<el-avatar :src="avatar" :size="70" class="mr-16px">
<img src="@/assets/imgs/avatar.gif" alt="" />
</el-avatar>
<div>
<div class="text-20px">
2026-04-25 14:20:16 +08:00
你好 {{ username }} 祝你开心每一天!
2026-04-20 14:30:15 +08:00
</div>
<div class="mt-10px text-14px text-gray-500">
2026-04-25 14:20:16 +08:00
今日晴20 - 32
2026-04-20 14:30:15 +08:00
</div>
</div>
</div>
</el-col>
<el-col :xl="12" :lg="12" :md="12" :sm="24" :xs="24">
<div class="h-70px flex items-center justify-end lt-sm:mt-10px">
<div class="px-8px text-right">
2026-04-25 14:20:16 +08:00
<div class="mb-16px text-14px text-gray-400">项目数</div>
2026-04-20 14:30:15 +08:00
<CountTo
class="text-20px"
:start-val="0"
:end-val="totalSate.project"
:duration="2600"
/>
</div>
<el-divider direction="vertical" />
<div class="px-8px text-right">
2026-04-25 14:20:16 +08:00
<div class="mb-16px text-14px text-gray-400">待办</div>
2026-04-20 14:30:15 +08:00
<CountTo
class="text-20px"
:start-val="0"
:end-val="totalSate.todo"
:duration="2600"
/>
</div>
<el-divider direction="vertical" border-style="dashed" />
<div class="px-8px text-right">
2026-04-25 14:20:16 +08:00
<div class="mb-16px text-14px text-gray-400">项目访问</div>
2026-04-20 14:30:15 +08:00
<CountTo
class="text-20px"
:start-val="0"
:end-val="totalSate.access"
:duration="2600"
/>
</div>
</div>
</el-col>
</el-row>
</el-skeleton>
</el-card>
2026-04-25 14:20:16 +08:00
<!-- 主要内容区域 -->
<el-row class="mt-8px" :gutter="8" justify="space-between">
<el-col :xl="16" :lg="16" :md="24" :sm="24" :xs="24" class="mb-8px">
<!-- 小区项目列表 -->
<el-card shadow="never">
<template #header>
<div class="h-3 flex justify-between">
<span>项目数</span>
<el-link type="primary" :underline="false" @click="handleMoreClick">
更多
</el-link>
</div>
</template>
<el-skeleton :loading="loading" animated>
<el-row>
<el-col
v-for="(item, index) in projects"
:key="`card-${index}`"
:xl="8"
:lg="8"
:md="8"
:sm="24"
:xs="24"
2026-04-20 14:30:15 +08:00
>
2026-04-25 14:20:16 +08:00
<el-card
shadow="hover"
class="mr-5px mt-5px cursor-pointer"
@click="handleProjectClick(item)"
>
<div class="flex items-center">
<Icon
:icon="item.icon"
:size="25"
class="mr-8px"
:style="{ color: item.color }"
/>
<span class="text-16px">{{ item.name }}</span>
</div>
<div class="mt-12px text-12px text-gray-400">{{ item.description }}</div>
<div class="mt-12px flex justify-between text-12px text-gray-400">
<span>{{ item.location }}</span>
<span>{{ formatTime(item.time, 'yyyy-MM-dd') }}</span>
</div>
</el-card>
</el-col>
</el-row>
</el-skeleton>
</el-card>
<!-- 图表区域 -->
<el-card shadow="never" class="mt-8px">
<el-skeleton :loading="loading" animated>
<el-row :gutter="20" justify="space-between">
<el-col :xl="10" :lg="10" :md="24" :sm="24" :xs="24">
<el-card shadow="hover" class="mb-8px">
<el-skeleton :loading="loading" animated>
<Echart :options="pieOptionsData" :height="280" />
</el-skeleton>
</el-card>
</el-col>
<el-col :xl="14" :lg="14" :md="24" :sm="24" :xs="24">
<el-card shadow="hover" class="mb-8px">
<el-skeleton :loading="loading" animated>
<Echart :options="barOptionsData" :height="280" />
</el-skeleton>
</el-card>
</el-col>
</el-row>
</el-skeleton>
</el-card>
</el-col>
<!-- 右侧区域 -->
<el-col :xl="8" :lg="8" :md="24" :sm="24" :xs="24" class="mb-8px">
<!-- 快捷入口 -->
<el-card shadow="never">
<template #header>
<div class="h-3 flex justify-between">
<span>快捷入口</span>
</div>
</template>
<el-skeleton :loading="loading" animated>
<el-row>
<el-col v-for="item in shortcut" :key="`team-${item.name}`" :span="8" class="mb-8px">
2026-04-20 14:30:15 +08:00
<div class="flex items-center">
2026-04-25 14:20:16 +08:00
<Icon :icon="item.icon" class="mr-8px" :style="{ color: item.color }" />
<el-link type="default" :underline="false" @click="handleShortcutClick(item.url)">
{{ item.name }}
</el-link>
2026-04-20 14:30:15 +08:00
</div>
2026-04-25 14:20:16 +08:00
</el-col>
</el-row>
</el-skeleton>
</el-card>
2026-04-20 14:30:15 +08:00
2026-04-25 14:20:16 +08:00
<!-- 通知公告 -->
<el-card shadow="never" class="mt-8px">
<template #header>
<div class="h-3 flex justify-between">
<span>通知公告</span>
<el-link type="primary" :underline="false" @click="handleNoticeMoreClick"></el-link>
</div>
</template>
<el-skeleton :loading="loading" animated>
<div v-for="(item, index) in notice" :key="`dynamics-${index}`">
<div class="flex items-start">
<el-avatar :src="avatar" :size="35" class="mr-16px">
<img src="@/assets/imgs/avatar.gif" alt="" />
</el-avatar>
<div class="flex-1">
<div class="text-14px">
<span class="text-gray-800">{{ item.type }}</span>
<span class="text-gray-600">{{ item.title }}</span>
</div>
<div class="mt-8px text-12px text-gray-400">
{{ formatTime(item.date, 'yyyy-MM-dd') }}
</div>
2026-04-20 14:30:15 +08:00
</div>
</div>
2026-04-25 14:20:16 +08:00
<el-divider v-if="index < notice.length - 1" />
2026-04-20 14:30:15 +08:00
</div>
2026-04-25 14:20:16 +08:00
</el-skeleton>
</el-card>
</el-col>
</el-row>
</div>
2026-04-20 14:30:15 +08:00
</template>
2026-04-25 14:20:16 +08:00
2026-04-20 14:30:15 +08:00
<script lang="ts" setup>
import { set } from 'lodash-es'
import { EChartsOption } from 'echarts'
import { formatTime } from '@/utils'
import { useUserStore } from '@/store/modules/user'
import type { WorkplaceTotal, Project, Notice, Shortcut } from './types'
import { pieOptions, barOptions } from './echarts-data'
import { useRouter } from 'vue-router'
2026-04-25 14:20:16 +08:00
import { CommunityApi, Community } from '@/api/community/community'
import { NoticeApi, Notice as NoticeInfo } from '@/api/community/notice'
2026-04-20 14:30:15 +08:00
defineOptions({ name: 'Index' })
const { t } = useI18n()
const router = useRouter()
const userStore = useUserStore()
const loading = ref(true)
const avatar = userStore.getUser.avatar
const username = userStore.getUser.nickname
const pieOptionsData = reactive<EChartsOption>(pieOptions) as EChartsOption
2026-04-25 14:20:16 +08:00
2026-04-20 14:30:15 +08:00
// 获取统计数
let totalSate = reactive<WorkplaceTotal>({
project: 0,
access: 0,
todo: 0
})
const getCount = async () => {
2026-04-25 14:20:16 +08:00
try {
const data = await CommunityApi.getCommunitySimpleList()
totalSate.project = data.length
totalSate.access = 2340
totalSate.todo = 10
} catch (error) {
console.error('获取小区数量失败:', error)
2026-04-20 14:30:15 +08:00
}
}
2026-04-25 14:20:16 +08:00
// 获取小区列表
2026-04-20 14:30:15 +08:00
let projects = reactive<Project[]>([])
const getProject = async () => {
2026-04-25 14:20:16 +08:00
try {
const data = await CommunityApi.getCommunityPage({
pageNo: 1,
pageSize: 100
})
projects = data.list.map((item: Community) => ({
name: item.communityName || '',
icon: 'ep:house',
description: item.streetName || item.districtName || '智慧社区',
location: item.communityAddress || '',
time: new Date(),
2026-04-20 14:30:15 +08:00
color: '#409EFF'
2026-04-25 14:20:16 +08:00
}))
} catch (error) {
console.error('获取小区列表失败:', error)
}
2026-04-20 14:30:15 +08:00
}
// 获取通知公告
let notice = reactive<Notice[]>([])
const getNotice = async () => {
2026-04-25 14:20:16 +08:00
try {
const data = await NoticeApi.getNoticePage({
pageNo: 1,
pageSize: 4,
status: 1
})
notice = data.list.map((item: NoticeInfo) => ({
title: item.title || '',
type: item.publisher || '系统通知',
keys: [item.title || ''],
date: new Date(item.createTime || '')
}))
} catch (error) {
console.error('获取通知公告失败:', error)
}
2026-04-20 14:30:15 +08:00
}
// 获取快捷入口
let shortcut = reactive<Shortcut[]>([])
const getShortcut = async () => {
const data = [
{
2026-04-25 14:20:16 +08:00
name: '社区动态',
icon: 'ep:document',
url: '/operation/post',
color: '#1677ff'
2026-04-20 14:30:15 +08:00
},
{
2026-04-25 14:20:16 +08:00
name: '通知公告',
icon: 'ep:bell',
url: '/operation/notice',
2026-04-20 14:30:15 +08:00
color: '#ff6b6b'
},
{
2026-04-25 14:20:16 +08:00
name: '知识课堂',
icon: 'ep:reading',
url: '/operation/knowledge-class',
2026-04-20 14:30:15 +08:00
color: '#7c3aed'
},
{
2026-04-25 14:20:16 +08:00
name: '小区活动',
icon: 'ep:calendar',
url: '/operation/activity',
2026-04-20 14:30:15 +08:00
color: '#3fb27f'
},
{
2026-04-25 14:20:16 +08:00
name: '小区管理',
icon: 'ep:office-building',
url: '/system/community',
2026-04-20 14:30:15 +08:00
color: '#4daf1bc9'
},
{
2026-04-25 14:20:16 +08:00
name: 'Banner管理',
icon: 'ep:picture',
url: '/system/banner',
2026-04-20 14:30:15 +08:00
color: '#1a73e8'
}
]
shortcut = Object.assign(shortcut, data)
}
2026-04-25 14:20:16 +08:00
// 用户访问来源
2026-04-20 14:30:15 +08:00
const getUserAccessSource = async () => {
const data = [
2026-04-25 14:20:16 +08:00
{ value: 335, name: '直接访问' },
{ value: 310, name: '邮件营销' },
{ value: 234, name: '联盟广告' },
{ value: 135, name: '视频广告' },
{ value: 1548, name: '搜索引擎' }
2026-04-20 14:30:15 +08:00
]
set(
pieOptionsData,
'legend.data',
2026-04-25 14:20:16 +08:00
data.map((v) => v.name)
2026-04-20 14:30:15 +08:00
)
pieOptionsData!.series![0].data = data.map((v) => {
return {
2026-04-25 14:20:16 +08:00
name: v.name,
2026-04-20 14:30:15 +08:00
value: v.value
}
})
}
2026-04-25 14:20:16 +08:00
2026-04-20 14:30:15 +08:00
const barOptionsData = reactive<EChartsOption>(barOptions) as EChartsOption
// 周活跃量
const getWeeklyUserActivity = async () => {
const data = [
2026-04-25 14:20:16 +08:00
{ value: 13253, name: '周一' },
{ value: 34235, name: '周二' },
{ value: 26321, name: '周三' },
{ value: 12340, name: '周四' },
{ value: 24643, name: '周五' },
{ value: 1322, name: '周六' },
{ value: 1324, name: '周日' }
2026-04-20 14:30:15 +08:00
]
set(
barOptionsData,
'xAxis.data',
2026-04-25 14:20:16 +08:00
data.map((v) => v.name)
2026-04-20 14:30:15 +08:00
)
set(barOptionsData, 'series', [
{
2026-04-25 14:20:16 +08:00
name: '活跃用户',
2026-04-20 14:30:15 +08:00
data: data.map((v) => v.value),
type: 'bar'
}
])
}
const getAllApi = async () => {
await Promise.all([
getCount(),
getProject(),
getNotice(),
getShortcut(),
getUserAccessSource(),
getWeeklyUserActivity()
])
loading.value = false
}
2026-04-25 14:20:16 +08:00
const handleProjectClick = (item: Project) => {
// TODO: 跳转到小区详情页
console.log('点击小区:', item.name)
2026-04-20 14:30:15 +08:00
}
const handleShortcutClick = (url: string) => {
router.push(url)
}
2026-04-25 14:20:16 +08:00
const handleMoreClick = () => {
router.push('/system/community')
}
const handleNoticeMoreClick = () => {
router.push('/operation/notice')
}
2026-04-20 14:30:15 +08:00
getAllApi()
</script>
2026-04-25 14:20:16 +08:00
<style lang="scss" scoped>
.home-container {
padding: 0;
}
.welcome-card {
:deep(.el-card__body) {
padding: 20px;
}
}
</style>