106 lines
4.1 KiB
Vue
106 lines
4.1 KiB
Vue
<template>
|
|
<div class="page-card">
|
|
<div class="breadcrumb">首页 / 消息通知</div>
|
|
|
|
<ul class="notice-list">
|
|
<li v-for="n in rows" :key="n.id" class="notice-item" :class="{ read: n.read }">
|
|
<div class="dot"></div>
|
|
<div class="body" @click="openDetail(n)">
|
|
<div class="title"><span class="cat" :class="catClass(n.category)">{{ n.category }}</span>{{ n.title }}</div>
|
|
<div class="text">{{ n.text }}</div>
|
|
</div>
|
|
<span class="time">{{ n.time }}</span>
|
|
</li>
|
|
<li v-if="!rows.length" class="empty">暂无消息</li>
|
|
</ul>
|
|
|
|
<el-dialog v-model="detailOpen" :title="detail.title || '消息详情'" width="520px">
|
|
<div class="detail-body">
|
|
<div class="meta">
|
|
<span class="cat" :class="catClass(detail.category)">{{ detail.category }}</span>
|
|
<span class="time">{{ detail.time }}</span>
|
|
</div>
|
|
<div class="text">{{ detail.text || '-' }}</div>
|
|
</div>
|
|
<template #footer><el-button @click="detailOpen=false">关闭</el-button></template>
|
|
</el-dialog>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { ref, onMounted } from 'vue'
|
|
import { bizList, listMyMessages } from '@/api/public'
|
|
|
|
const rows = ref([])
|
|
const detail = ref({})
|
|
const detailOpen = ref(false)
|
|
|
|
async function load() {
|
|
try {
|
|
const r = await listMyMessages({ limit: 50 }); const list = (r.data && r.data.rows) || r.rows || []
|
|
rows.value = list.map(a => ({
|
|
id: a.id,
|
|
category: a.category,
|
|
title: a.title,
|
|
text: a.text,
|
|
time: a.time,
|
|
read: a.read
|
|
}))
|
|
} catch (e) { rows.value = [] }
|
|
}
|
|
|
|
function mapCategory(t) {
|
|
if (t === 'system') return '系统通知'
|
|
if (t === 'audit') return '审核结果'
|
|
if (t === 'project') return '项目动态'
|
|
if (t === 'meeting') return '会议提醒'
|
|
return '通知'
|
|
}
|
|
|
|
function catClass(c) {
|
|
if (c === '系统通知') return 'sys'
|
|
if (c === '审核结果') return 'audit'
|
|
if (c === '项目动态') return 'proj'
|
|
if (c === '会议提醒') return 'meet'
|
|
return ''
|
|
}
|
|
|
|
function formatAgo(t) {
|
|
const diff = (Date.now() - new Date(t).getTime()) / 1000
|
|
if (diff < 3600) return `${Math.floor(diff / 60)} 分钟前`
|
|
if (diff < 86400) return `${Math.floor(diff / 3600)} 小时前`
|
|
if (diff < 604800) return `${Math.floor(diff / 86400)} 天前`
|
|
return new Date(t).toLocaleDateString('zh-CN')
|
|
}
|
|
|
|
function openDetail(n) {
|
|
detail.value = n
|
|
detailOpen.value = true
|
|
}
|
|
|
|
onMounted(load)
|
|
</script>
|
|
|
|
<style scoped>
|
|
.page-card { background: #fff; padding: 16px 20px; border-radius: 6px; border: 1px solid #f0f0f0; }
|
|
.breadcrumb { font-size: 13px; color: #8c8c8c; margin-bottom: 12px; }
|
|
.notice-list { list-style: none; }
|
|
.notice-item { padding: 14px 0; border-bottom: 1px solid #f0f0f0; display: flex; align-items: center; gap: 12px; }
|
|
.notice-item:last-child { border-bottom: none; }
|
|
.notice-item .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--brand-primary); flex-shrink: 0; }
|
|
.notice-item.read .dot { background: transparent; border: 1px solid #d9d9d9; }
|
|
.notice-item .body { flex: 1; min-width: 0; cursor: pointer; }
|
|
.notice-item .title { font-size: 13px; color: #1a1a1a; display: flex; align-items: center; gap: 8px; }
|
|
.notice-item.read .title { color: #8c8c8c; }
|
|
.notice-item .text { font-size: 12px; color: #595959; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
.notice-item .time { font-size: 12px; color: #bfbfbf; flex-shrink: 0; }
|
|
.notice-item:hover .title { color: var(--brand-primary); }
|
|
.cat { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 2px; background: #f0f0f0; color: #595959; }
|
|
.cat.sys { background: #e6f7ff; color: var(--brand-primary); }
|
|
.cat.audit { background: #f9f0ff; color: #722ed1; }
|
|
.cat.proj { background: #fff7e6; color: #fa8c16; }
|
|
.cat.meet { background: #f6ffed; color: #52c41a; }
|
|
.empty { padding: 24px; text-align: center; color: #bfbfbf; font-size: 13px; }
|
|
.detail-body .meta { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
|
|
.detail-body .text { font-size: 14px; color: #1a1a1a; line-height: 1.6; white-space: pre-wrap; }
|
|
</style> |