Files

194 lines
3.9 KiB
Vue

<template>
<view class="page">
<view class="toolbar">
<u-search
v-model="keyword"
placeholder="搜索公告标题"
:show-action="false"
shape="round"
bg-color="#f1f5f9"
color="#0f172a"
@search="loadNotices"
@clear="clearSearch"
/>
</view>
<scroll-view class="list-scroll" scroll-y :show-scrollbar="false">
<view v-if="loading" class="state-box">
<text class="state-text">加载中...</text>
</view>
<u-empty
v-else-if="list.length === 0"
mode="list"
:icon-size="80"
:text="keyword ? '未找到相关公告' : '暂无公告'"
/>
<view v-else class="notice-list">
<view v-for="item in list" :key="item.id" class="notice-card" @tap="openDetail(item.id)">
<view class="notice-head">
<u-tag v-if="item.is_top" text="置顶" type="error" size="mini" />
<u-tag :text="getNoticeLevelLabel(item.level)" :type="levelTagType(item.level)" size="mini" plain />
<text class="notice-title">{{ item.title }}</text>
</view>
<text v-if="item.summary" class="notice-summary">{{ item.summary }}</text>
<view class="notice-meta">
<text class="meta-type">{{ getNoticeTypeLabel(item.notice_type) }}</text>
<text>{{ item.publisher_name || '系统' }}</text>
<text>·</text>
<text>{{ item.publish_time || '-' }}</text>
<text>·</text>
<text>阅读 {{ item.read_count || 0 }}</text>
</view>
</view>
</view>
<view class="bottom-space" />
</scroll-view>
</view>
</template>
<script setup>
import { ref, onMounted } from 'vue'
import { fetchNotices, getNoticeTypeLabel, getNoticeLevelLabel } from '@/api/oa.js'
import { isLoggedIn } from '@/utils/auth.js'
const keyword = ref('')
const list = ref([])
const loading = ref(false)
onMounted(() => {
if (!isLoggedIn()) {
uni.reLaunch({ url: '/pages/login/login' })
return
}
loadNotices()
})
async function loadNotices() {
loading.value = true
try {
const res = await fetchNotices({ keyword: keyword.value, pageSize: 50 })
list.value = res.list
} catch (e) {
uni.showToast({ title: '加载失败', icon: 'none' })
} finally {
loading.value = false
}
}
function clearSearch() {
keyword.value = ''
loadNotices()
}
/** 公告级别 → uview tag 类型 */
function levelTagType(level) {
const n = Number(level)
if (n === 1) return 'warning'
if (n === 2) return 'error'
return 'info'
}
function openDetail(id) {
uni.navigateTo({ url: `/pages/oa/notice/detail?id=${id}` })
}
</script>
<style lang="scss" scoped>
@import '@/src/styles/page-common.scss';
.page {
min-height: 100vh;
background: $color-bg-page;
display: flex;
flex-direction: column;
}
.toolbar {
flex-shrink: 0;
padding: 20rpx $page-padding-x;
background: $color-card;
box-shadow: $shadow-header;
}
.list-scroll {
flex: 1;
height: 0;
}
.notice-list {
padding: 24rpx $page-padding-x 0;
}
.notice-card {
@include card;
padding: 26rpx 24rpx;
margin-bottom: 20rpx;
&:active {
background: $color-bg-page;
}
}
.notice-head {
display: flex;
align-items: flex-start;
gap: 10rpx;
}
.notice-title {
flex: 1;
min-width: 0;
font-size: 30rpx;
font-weight: 500;
line-height: 1.45;
color: $color-text;
}
.notice-summary {
display: block;
margin-top: 12rpx;
font-size: 26rpx;
line-height: 1.5;
color: $color-text-secondary;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
overflow: hidden;
}
.notice-meta {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 8rpx;
margin-top: 16rpx;
font-size: 22rpx;
color: $color-text-muted;
}
.meta-type {
color: $color-primary;
background: $color-primary-bg;
padding: 2rpx 12rpx;
border-radius: $radius-sm;
}
.state-box {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 160rpx 48rpx;
gap: 20rpx;
}
.state-text {
font-size: 26rpx;
color: $color-text-muted;
text-align: center;
}
.bottom-space {
height: 40rpx;
}
</style>