Files
guoju0808/ry-vue3/src/views/portal/Publicity.vue
T

797 lines
21 KiB
Vue

<template>
<div class="pub-page">
<header class="top-nav" :class="topNavClass">
<a class="logo" title="返回首页" @click.prevent="goHome">
<div class="logo-icon"><img src="/logo.png" alt="logo" /></div>
<div class="logo-text">
<span class="logo-title">北京整合医学学会</span>
<span class="logo-subtitle">Beijing Association of Holistic Integrative Medicine</span>
</div>
</a>
<ul class="nav-list">
<li class="nav-item"><a class="nav-link" @click.prevent="goHome">年度项目规划</a></li>
<li class="nav-item"><span class="nav-link active">项目公示</span></li>
</ul>
<div class="top-tools">
<template v-if="!loggedIn">
<span class="login-btn" @click="goLogin">登录</span>
</template>
<template v-else>
<el-dropdown trigger="click" @command="onUserCmd">
<a class="user-link" @click.prevent>
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"/>
<circle cx="12" cy="7" r="4"/>
</svg>
<span>{{ userName }}</span>
</a>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item command="account">我的主页</el-dropdown-item>
<el-dropdown-item command="logout" divided>退出登录</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</template>
</div>
</header>
<main class="container">
<div class="page-header">
<h1 class="section-title">项目公示</h1>
</div>
<div class="filter-bar">
<input v-model="currentKeyword" @keydown.enter="applyFilter" type="text" class="filter-input" placeholder="">
<button class="filter-btn" @click="applyFilter">查询</button>
<button class="filter-btn" style="background: #fff; color: var(--brand-primary); border: 1px solid var(--brand-primary);" @click="resetFilter">重置</button>
</div>
<div class="notice-list">
<template v-if="pageItems.length === 0">
<div style="padding: 40px 0; text-align: center; color: #9ca3af; font-size: 13px;">暂无数据</div>
</template>
<template v-else>
<div class="notice-header">
<span class="notice-header-no">序号</span>
<span class="notice-header-title">项目</span>
<span class="notice-header-date">开始日期</span>
<span class="notice-header-end">截止日期</span>
</div>
<div v-for="(n, i) in pageItems" :key="n.annId || i" class="notice-item" @click="goDetail(n)">
<span class="notice-item-no">{{ String((currentPage - 1) * PAGE_SIZE + i + 1).padStart(3, '0') }}</span>
<span class="notice-title">
<span v-if="n.projectNo" style="color:#909399;margin-right:8px;font-size:13px">{{ n.projectNo }}</span>
{{ n.title }}
</span>
<span class="notice-date">{{ fmtDate(n.date) }}</span>
<span class="notice-end">{{ fmtDate(n.endTime) }}</span>
</div>
</template>
</div>
<div class="pagination">
<template v-if="total > 0">
<button class="page-btn" :disabled="currentPage === 1" @click="prevPage">上一页</button>
<template v-for="(b, idx) in pageButtons" :key="idx">
<span v-if="b === '...'" style="color: #9ca3af; padding: 0 4px;">···</span>
<button v-else class="page-btn" :class="b === currentPage ? 'active' : ''" @click="goPage(b)">{{ b }}</button>
</template>
<button class="page-btn" :disabled="currentPage === totalPages" @click="nextPage">下一页</button>
<span class="page-info"> {{ total }} / {{ totalPages }} </span>
</template>
</div>
</main>
<footer class="footer">
<div class="container">
<div class="footer-main">
<div class="footer-brand">
<div class="brand-row">
<div class="footer-logo-icon"><img src="/logo.png" alt="logo" /></div>
<div>
<div class="footer-brand-name">北京整合医学学会</div>
<div class="footer-brand-en">Beijing Association of Holistic Integrative Medicine</div>
</div>
</div>
<p class="footer-desc">依托"健康中国2030"战略,整合医学资源,推动健康科普与公益事业,助力全民健康素养提升,共建共享健康中国</p>
</div>
<div class="footer-col">
<h4>快速导航</h4>
<a @click.prevent="goHome">首页</a>
<a @click.prevent="goHome">年度项目规划</a>
<span style="display: block; font-size: 13px; color: rgba(255,255,255,0.6);">项目公示</span>
</div>
<div class="footer-col">
<h4>学会项目</h4>
<a>百姓巡常行</a>
<a>专病联盟暨全国专家智库</a>
<a>乡村幸福安康</a>
<a>临床科研资助计划</a>
</div>
<div class="footer-col">
<h4>联系方式</h4>
<p>电话: 010-82089470</p>
<p>邮箱: contactus@bahim.org.cn</p>
<p>地址: 北京市海淀区知春路1号学院国际大厦908-2</p>
<p>邮编: 100083</p>
</div>
<div class="footer-qr">
<div class="qr-image">
<img src="/qrcode_1.png" alt="公众号二维码" style="width:100%;height:100%;object-fit:contain;" />
</div>
<div class="qr-label">公众号二维码</div>
</div>
</div>
<div class="footer-bottom">
<span>© 北京整合医学学会 BAHIM</span>
<span>京ICP备2020035479号-1 &nbsp;&nbsp; 京公网安备11010802034820</span>
</div>
</div>
</footer>
</div>
</template>
<script setup>
import { ref, computed, onMounted, onBeforeUnmount } from 'vue'
import { useRouter } from 'vue-router'
import { useUserStore } from '@/store/user'
import { logout as logoutApi } from '@/api/auth'
import request from '@/utils/request'
import { bizList } from '@/api/public'
const router = useRouter()
const userStore = useUserStore()
const PAGE_SIZE = 10
const isScrolled = ref(false)
const topNavClass = computed(() => isScrolled.value ? 'is-scrolled' : '')
const loggedIn = computed(() => !!userStore.token)
const userName = computed(() => userStore.user?.userName || '用户')
const ALL_NOTICES = []
const currentKeyword = ref('')
const currentPage = ref(1)
const allRows = ref([])
const loading = ref(false)
async function load() {
loading.value = true
try {
// 项目公示 = biz_project 表中 is_published='1' 的项目
const res = await request({ url: '/business/public/announcements', method: 'get' })
const list = res.data?.data || res.data || []
allRows.value = list.map(r => {
// ann_type 来自 announcement_type 字段; URL 来自邀请函/支持函/通知/日程/公示 URL
const type = r.announcementType || '公示'
// 根据 announcementType 选择对应 URL
const urlMap = {
invitation: r.invitationUrl,
support: r.supportLetterUrl,
supportLetter: r.supportLetterUrl,
publish: r.publishUrl,
notice: r.publishUrl,
schedule: r.scheduleUrl
}
return {
annId: r.projectId,
date: r.startTime,
endTime: r.endTime,
type,
projectNo: r.projectNo || '',
projectName: r.projectName,
title: r.projectName,
fileUrl: urlMap[type] || r.invitationUrl || r.supportLetterUrl || r.publishUrl || ''
}
})
} catch (e) {
console.error('[publicity] load failed', e)
allRows.value = []
}
finally { loading.value = false }
}
load()
function detectType(title) {
if (title.includes('【邀请函】')) return '邀请函'
if (title.includes('【支持函】')) return '支持函'
if (title.includes('【通知】')) return '通知'
if (title.includes('【日程】')) return '日程'
if (title.includes('【会议通知】')) return '通知'
return '其他'
}
const filteredList = computed(() => {
let list = allRows.value.map(n => ({ ...n, type: n.type || detectType(n.title) }))
if (currentKeyword.value) {
const kw = currentKeyword.value.toLowerCase()
list = list.filter(n => n.title.toLowerCase().includes(kw))
}
return list
})
const total = computed(() => filteredList.value.length)
const totalPages = computed(() => Math.max(1, Math.ceil(total.value / PAGE_SIZE)))
const pageItems = computed(() => {
const start = (currentPage.value - 1) * PAGE_SIZE
return filteredList.value.slice(start, start + PAGE_SIZE)
})
const pageButtons = computed(() => {
const buttons = []
for (let i = 1; i <= totalPages.value; i++) {
if (i === 1 || i === totalPages.value || (i >= currentPage.value - 1 && i <= currentPage.value + 1)) {
buttons.push(i)
} else if (i === currentPage.value - 2 || i === currentPage.value + 2) {
buttons.push('...')
}
}
const result = []
for (let i = 0; i < buttons.length; i++) {
if (buttons[i] === '...' && result[result.length - 1] === '...') continue
result.push(buttons[i])
}
return result
})
function applyFilter() { currentPage.value = 1 }
function resetFilter() { currentKeyword.value = ''; currentPage.value = 1 }
function prevPage() { if (currentPage.value > 1) { currentPage.value--; window.scrollTo({ top: 0, behavior: 'smooth' }) } }
function nextPage() { if (currentPage.value < totalPages.value) { currentPage.value++; window.scrollTo({ top: 0, behavior: 'smooth' }) } }
function goPage(p) { currentPage.value = p; window.scrollTo({ top: 0, behavior: 'smooth' }) }
function goHome() { router.push('/') }
function goLogin() { router.push('/login') }
function goUser() { /* placeholder */ }
async function goLogout() { try { await logoutApi() } catch {}; userStore.logout(); router.replace('/login') }
async function onUserCmd(cmd) {
if (cmd === 'logout') return goLogout()
if (cmd === 'account') {
const r = (userStore.user?.role || '')
const map = { admin: '/admin/workbench', manager: '/manager/workbench', doctor: '/doctor/home', executor: '/executor/meetings', sponsor: '/sponsor/home' }
router.push(map[r] || '/admin/workbench')
}
}
function goDetail(n) {
if (!n || !n.annId) return
router.push({ name: 'publicity-detail', params: { projectId: n.annId } })
}
function fmtDate(d) {
if (!d) return ''
// 只显示年月日, 不显示时分秒
const date = new Date(d)
const y = date.getFullYear()
const m = String(date.getMonth() + 1).padStart(2, '0')
const day = String(date.getDate()).padStart(2, '0')
return `${y}-${m}-${day}`
}
function handleScroll() { isScrolled.value = window.scrollY > 10 }
onMounted(() => window.addEventListener('scroll', handleScroll, { passive: true }))
onBeforeUnmount(() => window.removeEventListener('scroll', handleScroll))
</script>
<style scoped>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #1f2937;
background: #ffffff;
min-width: 1354px;
line-height: 1.6;
}
a { color: inherit; text-decoration: none; }
/* ========== 顶部导航 ========== */
.top-nav {
position: sticky;
top: 0;
z-index: 1000;
height: 72px;
padding: 0 60px;
background: var(--brand-primary);
border-bottom: 1px solid rgba(255, 255, 255, 0.08);
display: flex;
align-items: center;
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
transition: box-shadow 0.3s;
}
.top-nav.is-scrolled {
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}
.logo {
display: flex;
align-items: center;
gap: 12px;
cursor: pointer;
text-decoration: none;
transition: opacity 0.2s;
}
.logo:hover { opacity: 0.85; }
.logo-icon {
width: 36px;
height: 36px;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
flex-shrink: 0;
}
.logo-icon img { width: 100%; height: 100%; object-fit: contain; display: block; }
.logo-text {
display: flex;
flex-direction: column;
line-height: 1.2;
}
.logo-title {
font-size: 16px;
font-weight: 600;
color: #fff;
letter-spacing: 0.5px;
}
.logo-subtitle {
font-size: 11px;
color: rgba(255, 255, 255, 0.6);
margin-top: 2px;
letter-spacing: 0.3px;
}
.nav-list {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
gap: 36px;
list-style: none;
}
.nav-item {
position: relative;
height: 72px;
display: flex;
align-items: center;
}
.nav-link {
font-size: 15px;
font-weight: 500;
color: rgba(255, 255, 255, 0.85);
cursor: pointer;
transition: color 0.25s;
position: relative;
height: 72px;
display: flex;
align-items: center;
}
.nav-link::after {
content: '';
position: absolute;
left: 50%;
bottom: 0;
width: 0;
height: 2px;
background: #fff;
transform: translateX(-50%);
transition: width 0.3s ease;
}
.nav-item:hover .nav-link,
.nav-link.active {
color: #fff;
}
.nav-item:hover .nav-link::after,
.nav-link.active::after {
width: 100%;
}
.top-tools {
display: flex;
align-items: center;
gap: 16px;
}
/* 已登录: 右上角人员信息 (用户名 + 头像图标) — 深色 navbar 上必须白色 */
.user-link {
display: inline-flex;
align-items: center;
gap: 6px;
color: #fff;
font-size: 14px;
font-weight: 500;
cursor: pointer;
text-decoration: none;
transition: opacity 0.2s;
}
.user-link:hover { opacity: 0.85; }
.user-link svg { stroke: currentColor; }
.login-btn {
padding: 7px 20px;
background: #fff;
color: var(--brand-primary);
font-size: 13px;
font-weight: 500;
cursor: pointer;
transition: background 0.2s;
letter-spacing: 1px;
}
.login-btn:hover {
background: #f3f4f6;
}
/* ========== 页面骨架 (sticky footer: 内容少时底部仍贴屏幕底) ========== */
.pub-page {
display: flex;
flex-direction: column;
min-height: 100vh;
}
main.container {
flex: 1 0 auto;
/* flex item 的 width:auto 会塌成 fit-content (margin:0 auto 覆盖 align-items:stretch),
导致版心宽度丢失; 显式 width:100% 配合 max-width:1354px + margin:auto 恢复居中版心 */
width: 100%;
}
/* ========== 主体容器 ========== */
.container {
max-width: 1354px;
margin: 0 auto;
padding: 0 60px;
}
/* ========== 页面标题 ========== */
.page-header {
padding: 40px 0 24px;
}
.section-title {
font-size: 20px;
font-weight: 600;
color: #1f2937;
margin-bottom: 22px;
position: relative;
padding-left: 12px;
letter-spacing: 0.5px;
}
.section-title::before {
content: '';
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
width: 3px;
height: 18px;
background: var(--brand-primary);
}
/* ========== 筛选条 ========== */
.filter-bar {
padding: 12px 0;
border-bottom: 1px solid #f3f4f6;
margin-bottom: 0;
display: flex;
align-items: center;
gap: 14px;
font-size: 13px;
}
.filter-input {
height: 30px;
padding: 0 10px;
border: 1px solid #d1d5db;
background: #fff;
font-size: 13px;
color: #1f2937;
font-family: inherit;
outline: none;
width: 220px;
transition: border-color 0.2s;
}
.filter-input:focus {
border-color: var(--brand-primary);
}
.filter-input::placeholder {
color: #9ca3af;
}
.filter-btn {
height: 30px;
padding: 0 18px;
background: var(--brand-primary);
color: #fff;
border: none;
font-size: 12px;
cursor: pointer;
font-family: inherit;
letter-spacing: 1px;
transition: background 0.2s;
}
.filter-btn:hover {
background: var(--brand-primary-deep);
}
/* ========== 公示列表 ========== */
.notice-list {
padding: 0;
}
.notice-item {
display: flex;
align-items: flex-start;
padding: 14px 0;
border-bottom: 1px solid #f3f4f6;
cursor: pointer;
transition: background 0.2s;
gap: 24px;
}
.notice-item:hover {
background: #fafbfc;
}
.notice-item:hover .notice-title {
color: var(--brand-primary);
}
.notice-date {
flex-shrink: 0;
width: 100px;
font-size: 13px;
color: #6b7280;
font-family: ui-monospace, "Courier New", monospace;
padding-top: 2px;
}
.notice-title {
flex: 1;
font-size: 14px;
color: #1f2937;
line-height: 1.7;
transition: color 0.2s;
min-width: 0;
}
/* 表头: 与 notice-item 相同的 flex + gap + 列宽, 保证列对齐 */
.notice-header {
display: flex;
align-items: center;
gap: 24px;
padding: 12px 0;
border-bottom: 1px solid #e5e7eb;
background: #f9fafb;
font-size: 13px;
font-weight: 600;
color: #4b5563;
}
.notice-header-no {
flex-shrink: 0;
width: 32px;
text-align: center;
}
.notice-header-date {
flex-shrink: 0;
width: 100px;
}
.notice-header-title {
flex: 1;
min-width: 0;
}
.notice-header-end {
flex-shrink: 0;
width: 100px;
}
/* 右侧截止时间: 等宽数字 + 灰色, 与日期列同宽对齐 */
.notice-end {
flex-shrink: 0;
width: 100px;
font-size: 13px;
color: #6b7280;
font-family: ui-monospace, "Courier New", monospace;
padding-top: 2px;
}
.notice-item-no {
flex-shrink: 0;
width: 32px;
text-align: center;
font-size: 12px;
color: #9ca3af;
font-family: ui-monospace, "Courier New", monospace;
padding-top: 2px;
}
/* ========== 分页 ========== */
.pagination {
display: flex;
align-items: center;
justify-content: center;
gap: 6px;
padding: 30px 0 60px;
}
.page-btn {
min-width: 32px;
height: 32px;
padding: 0 10px;
border: 1px solid #e5e7eb;
background: #fff;
color: #4b5563;
font-size: 13px;
cursor: pointer;
font-family: inherit;
display: inline-flex;
align-items: center;
justify-content: center;
transition: all 0.2s;
}
.page-btn:hover {
border-color: var(--brand-primary);
color: var(--brand-primary);
}
.page-btn.active {
background: var(--brand-primary);
border-color: var(--brand-primary);
color: #fff;
}
.page-btn:disabled {
opacity: 0.4;
cursor: not-allowed;
border-color: #e5e7eb;
}
.page-btn:disabled:hover {
border-color: #e5e7eb;
color: #4b5563;
}
.page-info {
font-size: 13px;
color: #6b7280;
margin-left: 12px;
}
/* ========== 底部 ========== */
.footer {
background: var(--brand-primary-darker);
color: rgba(255, 255, 255, 0.65);
padding: 48px 0 0;
}
.footer-main {
display: grid;
grid-template-columns: 1.4fr 1fr 1fr 1.2fr auto;
gap: 48px;
padding-bottom: 36px;
}
.footer-brand .brand-row {
display: flex;
align-items: center;
gap: 12px;
margin-bottom: 16px;
}
.footer-logo-icon {
width: 36px;
height: 36px;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
flex-shrink: 0;
}
.footer-logo-icon img { width: 100%; height: 100%; object-fit: contain; display: block; }
.footer-brand-name {
font-size: 16px;
font-weight: 600;
color: #fff;
letter-spacing: 1px;
}
.footer-brand-en {
font-size: 10px;
color: rgba(255, 255, 255, 0.4);
letter-spacing: 0.5px;
margin-top: 2px;
}
.footer-desc {
font-size: 13px;
line-height: 1.9;
color: rgba(255, 255, 255, 0.55);
}
.footer-col h4 {
font-size: 14px;
font-weight: 600;
color: #fff;
letter-spacing: 1px;
margin-bottom: 16px;
padding-bottom: 10px;
position: relative;
}
.footer-col h4::after {
content: '';
position: absolute;
left: 0;
bottom: 0;
width: 24px;
height: 2px;
background: #93c5fd;
}
.footer-col a,
.footer-col p {
display: block;
font-size: 13px;
color: rgba(255, 255, 255, 0.6);
line-height: 2.1;
transition: color 0.2s;
}
.footer-col a { cursor: pointer; }
.footer-col a:hover { color: #fff; }
.footer-qr {
text-align: center;
}
.qr-image {
width: 100px;
height: 100px;
background: #fff;
display: flex;
align-items: center;
justify-content: center;
color: #1f2937;
}
.qr-label {
font-size: 12px;
color: rgba(255, 255, 255, 0.5);
margin-top: 10px;
}
.footer-bottom {
border-top: 1px solid rgba(255, 255, 255, 0.12);
padding: 18px 0;
display: flex;
justify-content: space-between;
font-size: 12px;
color: rgba(255, 255, 255, 0.4);
}
</style>