仰望星辰工作室

better-staridc-MNBT

better-staridc-MNBT/ templates/tdesign/spa/src/user/views/NoticeView.vue 5.5 KB · 184 行 原始文件
Z zfhsh first commit 2 个月前
1<template>
2 <div class="td-page">
3 <div class="td-page-head">
4 <div>
5 <h3 class="td-page-title"><i class="mdi mdi-bell-outline"></i>通知日志</h3>
6 <p class="td-page-subtitle">查看系统发送的通知记录</p>
7 </div>
8 </div>
9
10 <div class="td-table-wrap">
11 <div class="td-toolbar">
12 <t-select v-model="filter.type" style="width: 140px" placeholder="全部类型" clearable @change="onFilterChange">
13 <t-option value="email" label="邮件" />
14 <t-option value="sms" label="短信" />
15 <t-option value="system" label="系统" />
16 </t-select>
17 <div class="td-toolbar-spacer"></div>
18 <t-button theme="default" variant="text" @click="load">
19 <i class="mdi mdi-refresh"></i> 刷新
20 </t-button>
21 </div>
22
23 <t-table
24 row-key="id"
25 :data="rows"
26 :columns="columns"
27 :loading="loading"
28 :pagination="pagination"
29 table-layout="auto"
30 stripe
31 bordered
32 @page-change="onPageChange"
33 >
34 <template #empty>
35 <div class="td-empty">
36 <i class="mdi mdi-bell-off-outline"></i>
37 暂无通知日志
38 </div>
39 </template>
40 <template #time="{ row }">{{ fmtTime(row.time || row.data || row.created_at) }}</template>
41 <template #type="{ row }">
42 <span :class="typeClass(row.type || row.leixing)">
43 {{ typeText(row.type || row.leixing) }}
44 </span>
45 </template>
46 <template #content="{ row }">
47 <span class="cell-clip" :title="row.content || row.nr || row.text">{{ row.content || row.nr || row.text || '-' }}</span>
48 </template>
49 <template #status="{ row }">
50 <span :class="statusClass(row.status || row.qk)">
51 {{ statusText(row.status || row.qk) }}
52 </span>
53 </template>
54 </t-table>
55 </div>
56 </div>
57</template>
58
59<script setup>
60import { ref, reactive, onMounted } from 'vue'
61import { MessagePlugin } from 'tdesign-vue-next'
62import { listNoticeLog } from '@/user/api/monitor'
63
64const loading = ref(false)
65const rows = ref([])
66
67const pagination = reactive({
68 current: 1,
69 pageSize: 15,
70 total: 0,
71 showJumper: true,
72})
73
74const filter = reactive({
75 type: '',
76})
77
78const columns = [
79 { colKey: 'id', title: 'ID', width: 70 },
80 { colKey: 'time', title: '时间', width: 160 },
81 { colKey: 'type', title: '类型', width: 100 },
82 { colKey: 'content', title: '内容', minWidth: 280, ellipsis: true },
83 { colKey: 'status', title: '状态', width: 100 },
84]
85
86function fmtTime(v) {
87 if (!v) return '-'
88 const d = new Date(v)
89 if (isNaN(d.getTime())) return String(v)
90 return d.toLocaleString('zh-CN', { hour12: false })
91}
92
93function typeClass(v) {
94 if (v === 'email' || v === '邮件' || v === 'mail') return 'td-chip td-chip-info'
95 if (v === 'sms' || v === '短信' || v === 'message') return 'td-chip td-chip-warning'
96 if (v === 'system' || v === '系统' || v === 'sys') return 'td-chip td-chip-default'
97 return 'td-chip td-chip-default'
98}
99
100function typeText(v) {
101 if (v === 'email' || v === '邮件' || v === 'mail') return '邮件'
102 if (v === 'sms' || v === '短信' || v === 'message') return '短信'
103 if (v === 'system' || v === '系统' || v === 'sys') return '系统'
104 return v || '-'
105}
106
107function statusClass(v) {
108 if (v === true || v === 'true' || v === 1 || v === '1' || v === 'success' || v === 'ok') return 'td-chip td-chip-success'
109 if (v === false || v === 'false' || v === 0 || v === '0' || v === 'fail' || v === 'error') return 'td-chip td-chip-danger'
110 if (v === 'pending' || v === 'wait' || v === 'waiting') return 'td-chip td-chip-warning'
111 return 'td-chip td-chip-default'
112}
113
114function statusText(v) {
115 if (v === true || v === 'true' || v === 1 || v === '1' || v === 'success' || v === 'ok') return '已发送'
116 if (v === false || v === 'false' || v === 0 || v === '0' || v === 'fail' || v === 'error') return '失败'
117 if (v === 'pending' || v === 'wait' || v === 'waiting') return '待发送'
118 return v || '-'
119}
120
121function onFilterChange() {
122 pagination.current = 1
123 load()
124}
125
126async function load() {
127 loading.value = true
128 const r = await listNoticeLog(pagination.current, pagination.pageSize)
129 loading.value = false
130 if (r.ok && r.data) {
131 const d = r.data
132 let list = Array.isArray(d) ? d : (d.rows || d.list || d.data || [])
133 if (filter.type) {
134 list = list.filter((row) => typeMatch(row.type || row.leixing, filter.type))
135 }
136 rows.value = list
137 pagination.total = d.total || list.length
138 } else {
139 rows.value = []
140 pagination.total = 0
141 if (!r.ok) MessagePlugin.error(r.message || '加载失败')
142 }
143}
144
145function typeMatch(v, target) {
146 if (target === 'email') return v === 'email' || v === '邮件' || v === 'mail'
147 if (target === 'sms') return v === 'sms' || v === '短信' || v === 'message'
148 if (target === 'system') return v === 'system' || v === '系统' || v === 'sys'
149 return false
150}
151
152function onPageChange(p) {
153 pagination.current = p.current
154 pagination.pageSize = p.pageSize
155 load()
156}
157
158onMounted(load)
159</script>
160
161<style scoped>
162.td-empty {
163 text-align: center;
164 padding: 36px 16px;
165 color: var(--td-text-placeholder);
166 font-size: 13px;
167}
168.td-empty i {
169 font-size: 36px;
170 display: block;
171 margin-bottom: 8px;
172 color: #cbd5e1;
173}
174.cell-clip {
175 display: inline-block;
176 max-width: 100%;
177 color: var(--td-text);
178 font-size: 12px;
179 line-height: 1.5;
180 white-space: nowrap;
181 overflow: hidden;
182 text-overflow: ellipsis;
183}
184</style>