good-news/templates/index.html

208 lines
7.6 KiB
HTML

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>喜报管理系统</title>
<link rel="stylesheet" href="//unpkg.com/element-plus/dist/index.css">
<script src="//unpkg.com/vue@3"></script>
<script src="//unpkg.com/element-plus"></script>
<style>
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
.waterfall {
column-count: 3;
column-gap: 20px;
}
@media (max-width: 768px) {
.waterfall {
column-count: 2;
}
}
@media (max-width: 480px) {
.waterfall {
column-count: 1;
}
}
.waterfall-item {
break-inside: avoid;
margin-bottom: 20px;
}
.waterfall-item img {
width: 100%;
border-radius: 8px;
cursor: pointer;
transition: transform 0.3s;
}
.waterfall-item img:hover {
transform: scale(1.02);
}
.header {
margin-bottom: 20px;
}
.filter-section {
margin-bottom: 20px;
}
</style>
</head>
<body>
<div id="app">
<el-container>
<el-main>
<div class="container">
<div class="header">
<el-row :gutter="20" justify="space-between" align="middle">
<el-col :span="16">
<h1>喜报管理系统</h1>
</el-col>
<el-col :span="8" style="text-align: right;">
<el-button type="primary" @click="handleManageClick">管理喜报</el-button>
</el-col>
</el-row>
</div>
<div class="filter-section">
<el-row :gutter="20">
<el-col :span="8">
<el-date-picker
v-model="filterMonth"
type="month"
placeholder="选择月份"
format="YYYY年MM月"
value-format="YYYY-MM"
@change="handleFilterChange">
</el-date-picker>
</el-col>
<el-col :span="8">
<el-select v-model="filterOffice" placeholder="选择代表处" @change="handleFilterChange" clearable>
<el-option
v-for="office in offices"
:key="office"
:label="office"
:value="office">
</el-option>
</el-select>
</el-col>
<el-col :span="8" style="text-align: right;">
<div><span style="color: red;">{{ filteredNews.length }}</span> 条,总计 <span style="color: red;">{{ totalPoints }}</span></div>
</el-col>
</el-row>
</div>
<div class="waterfall">
<div v-for="item in filteredNews" :key="item.id" class="waterfall-item">
<el-card>
<img :src="item.image_url" @click="showImageDetail(item)">
<div style="padding: 10px;">
<h3>{{ item.project_name }}</h3>
<p>签单点数: {{ item.points }}</p>
<p>代表处: {{ item.office }}</p>
<p>上传时间: {{ formatDate(item.upload_time) }}</p>
</div>
</el-card>
</div>
</div>
<!-- 图片详情对话框 -->
<el-dialog v-model="imageDialogVisible" width="80%">
<img :src="currentImage.image_url" style="width: 100%;">
<template #footer>
<el-button @click="imageDialogVisible = false">关闭</el-button>
</template>
</el-dialog>
</div>
</el-main>
</el-container>
</div>
<script>
const { createApp, ref, computed } = Vue
const app = createApp({
components: {
// 注册所需的Element Plus组件
ElMessage: ElementPlus.ElMessage,
},
setup() {
const news = ref([])
const filterMonth = ref('')
const filterOffice = ref('')
const offices = ref([])
const imageDialogVisible = ref(false)
const currentImage = ref({})
const filteredNews = computed(() => {
return news.value.filter(item => {
const monthMatch = !filterMonth.value || item.upload_time.startsWith(filterMonth.value)
const officeMatch = !filterOffice.value || item.office === filterOffice.value
return monthMatch && officeMatch
})
})
const handleManageClick = () => {
window.location.href = '/manage'
}
const fetchNews = async () => {
try {
const response = await fetch('/api/news')
const data = await response.json()
news.value = data
// 提取所有代表处
offices.value = [...new Set(data.map(item => item.office))]
} catch (error) {
ElMessage.error('获取数据失败')
}
}
const handleFilterChange = () => {
// 筛选会自动通过computed属性完成
}
const totalPoints = computed(() => {
return filteredNews.value.reduce((sum, item) => sum + item.points, 0)
})
const showImageDetail = (item) => {
currentImage.value = item
imageDialogVisible.value = true
}
const formatDate = (dateString) => {
if (!dateString) return ''
const date = new Date(dateString)
return `${date.getFullYear()}${date.getMonth() + 1}${date.getDate()}`
}
// 初始化时获取数据
fetchNews()
return {
news,
filterMonth,
filterOffice,
offices,
imageDialogVisible,
currentImage,
filteredNews,
handleManageClick,
handleFilterChange,
totalPoints,
showImageDetail,
formatDate
}
}
})
app.use(ElementPlus)
app.mount('#app')
</script>
</body>
</html>