284 lines
11 KiB
HTML
284 lines
11 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;">
|
|
<el-button @click="resetFilters">重置筛选</el-button>
|
|
</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>
|
|
<el-button type="primary" @click="editNews(currentImage)">编辑</el-button>
|
|
<el-button type="danger" @click="deleteNews(currentImage)">删除</el-button>
|
|
</template>
|
|
</el-dialog>
|
|
|
|
<!-- 编辑对话框 -->
|
|
<el-dialog v-model="editDialogVisible" title="编辑喜报信息" width="500px">
|
|
<el-form :model="editForm" label-width="100px">
|
|
<el-form-item label="项目名称">
|
|
<el-input v-model="editForm.project_name"></el-input>
|
|
</el-form-item>
|
|
<el-form-item label="签单点数">
|
|
<el-input-number v-model="editForm.points"></el-input-number>
|
|
</el-form-item>
|
|
<el-form-item label="代表处">
|
|
<el-select v-model="editForm.office">
|
|
<el-option
|
|
v-for="office in offices"
|
|
:key="office"
|
|
:label="office"
|
|
:value="office">
|
|
</el-option>
|
|
</el-select>
|
|
</el-form-item>
|
|
</el-form>
|
|
<template #footer>
|
|
<el-button @click="editDialogVisible = false">取消</el-button>
|
|
<el-button type="primary" @click="submitEdit">确定</el-button>
|
|
</template>
|
|
</el-dialog>
|
|
</div>
|
|
</el-main>
|
|
</el-container>
|
|
</div>
|
|
|
|
<script>
|
|
const { createApp, ref, computed } = Vue
|
|
|
|
const app = createApp({
|
|
setup() {
|
|
const news = ref([])
|
|
const filterMonth = ref('')
|
|
const filterOffice = ref('')
|
|
const offices = ref([])
|
|
const imageDialogVisible = ref(false)
|
|
const editDialogVisible = ref(false)
|
|
const currentImage = ref({})
|
|
const editForm = 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 resetFilters = () => {
|
|
filterMonth.value = ''
|
|
filterOffice.value = ''
|
|
}
|
|
|
|
|
|
|
|
const showImageDetail = (item) => {
|
|
currentImage.value = item
|
|
imageDialogVisible.value = true
|
|
}
|
|
|
|
const editNews = (item) => {
|
|
editForm.value = { ...item }
|
|
imageDialogVisible.value = false
|
|
editDialogVisible.value = true
|
|
}
|
|
|
|
const submitEdit = async () => {
|
|
try {
|
|
const response = await fetch(`/api/news/${editForm.value.id}`, {
|
|
method: 'PUT',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify(editForm.value)
|
|
})
|
|
if (response.ok) {
|
|
ElMessage.success('更新成功')
|
|
editDialogVisible.value = false
|
|
fetchNews()
|
|
} else {
|
|
throw new Error('更新失败')
|
|
}
|
|
} catch (error) {
|
|
ElMessage.error('更新失败')
|
|
}
|
|
}
|
|
|
|
const deleteNews = async (item) => {
|
|
try {
|
|
const response = await fetch(`/api/news/${item.id}`, {
|
|
method: 'DELETE'
|
|
})
|
|
if (response.ok) {
|
|
ElMessage.success('删除成功')
|
|
imageDialogVisible.value = false
|
|
fetchNews()
|
|
} else {
|
|
throw new Error('删除失败')
|
|
}
|
|
} catch (error) {
|
|
ElMessage.error('删除失败')
|
|
}
|
|
}
|
|
|
|
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,
|
|
editDialogVisible,
|
|
currentImage,
|
|
editForm,
|
|
filteredNews,
|
|
handleManageClick,
|
|
handleFilterChange,
|
|
resetFilters,
|
|
showImageDetail,
|
|
editNews,
|
|
submitEdit,
|
|
deleteNews,
|
|
formatDate
|
|
}
|
|
}
|
|
})
|
|
|
|
app.use(ElementPlus)
|
|
app.mount('#app')
|
|
</script>
|
|
</body>
|
|
</html> |