notice-board.vue
2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<template>
<workbench-card title="通知公告" subtitle="最新系统公告" icon="el-icon-message-solid" tone="purple" :loading="loading">
<template #extra>
<el-button type="text" size="mini" @click="goMore">更多</el-button>
</template>
<div v-if="list.length" class="wb-list">
<div
v-for="item in list"
:key="item.id"
class="wb-list-item"
@click="openDetail(item)"
>
<div class="wb-list-item__left">
<span class="wb-list-item__dot" style="background:#8b5cf6" />
<span class="wb-list-item__title">{{ item.fullName || item.title || '无' }}</span>
</div>
<span class="wb-list-item__meta">{{ formatTime(item.creatorTime || item.lastModifyTime) }}</span>
</div>
</div>
<div v-else class="wb-empty">
<div class="wb-empty__circle" style="background:#f5f3ff;color:#8b5cf6">
<i class="el-icon-bell" />
</div>
<div class="wb-empty__title">暂无公告</div>
<div class="wb-empty__desc">有新通知时会显示在这里</div>
</div>
<notice-detail-dialog ref="detailDialog" />
</workbench-card>
</template>
<script>
import { getNotice } from '@/api/home'
import WorkbenchCard from '../workbench-card.vue'
import NoticeDetailDialog from './notice-detail-dialog.vue'
export default {
name: 'WidgetNoticeBoard',
components: { WorkbenchCard, NoticeDetailDialog },
data() {
return { loading: false, list: [] }
},
mounted() {
this.load()
},
methods: {
formatTime(val) {
if (!val) return '无'
const d = new Date(typeof val === 'number' ? val : val)
if (Number.isNaN(d.getTime())) return '无'
const y = d.getFullYear()
const m = `${d.getMonth() + 1}`.padStart(2, '0')
const day = `${d.getDate()}`.padStart(2, '0')
return `${y}-${m}-${day}`
},
async load() {
this.loading = true
try {
const res = await getNotice()
const rows = (res.data && res.data.list) || res.data || []
// 兜底:若后端未过滤,前端也排除草稿(enabledMark=0)
this.list = (Array.isArray(rows) ? rows : [])
.filter(x => x.enabledMark == null || x.enabledMark === 1 || x.EnabledMark === 1)
.slice(0, 5)
} catch (e) {
this.list = []
} finally {
this.loading = false
}
},
openDetail(item) {
const id = item && (item.id || item.Id)
if (!id) return
this.$refs.detailDialog && this.$refs.detailDialog.open(id)
},
goMore() {
this.$router.push('/messageRecord').catch(() => {})
}
}
}
</script>
<style lang="scss" scoped>
@import '../widget-common.scss';
</style>