Files
Message-Push-Nest/web/src/views/tabsTools/sendLogs/sendLogs.vue
T

218 lines
6.2 KiB
Vue
Raw Normal View History

2023-12-30 17:40:20 +08:00
<template>
<div class="main-center-body">
<div class="container">
2024-01-20 16:42:56 +08:00
2023-12-30 17:40:20 +08:00
<div class="search-input-sendways">
<el-input v-model="search" size="small" placeholder="根据任务名字搜索相应日志" @change="filterFunc()" />
</div>
2024-01-20 16:42:56 +08:00
<div class="search-box">
<el-text class="refresh-time" v-if="refreshText" size="small">{{ refreshText }}</el-text>
<el-input-number class="refresh-box" v-model="refreshSec" size="small" :step="2" :min="5"
controls-position="right" />
2024-01-20 18:50:55 +08:00
<el-switch v-model="refreshSwitch" class="ml-2" width="80" inline-prompt active-text="自动刷新" inactive-text="自动刷新"
2024-01-20 16:42:56 +08:00
@click="clickFreshSwitch" />
</div>
2023-12-30 17:40:20 +08:00
<hr />
<div ref="refContainer">
2024-01-06 17:44:45 +08:00
<el-table :data="tableData" stripe empty-text="发信日志为空" :row-style="rowStyle()">
2024-01-22 11:42:24 +08:00
<el-table-column label="ID" prop="id" width="85px" />
2023-12-30 17:40:20 +08:00
<el-table-column label="任务名" prop="task_name" show-overflow-tooltip width="150px" />
<el-table-column label="发信日志" prop="log">
<template #default="scope">
2024-01-07 00:25:35 +08:00
<el-tooltip enterable placement="top">
2023-12-30 17:40:20 +08:00
<template #content>
2024-01-22 14:17:33 +08:00
<div v-html="formatLogDisplayHtml(scope)"></div>
2023-12-30 17:40:20 +08:00
</template>
<span class="log-overflow">{{ scope.row.log }}</span>
</el-tooltip>
</template>
</el-table-column>
2024-01-14 21:13:44 +08:00
<el-table-column label="发送时间" prop="created_on" width="160px" />
2024-01-18 20:18:03 +08:00
<el-table-column label="详情/状态" prop="status" width="120px" fixed="right">
2023-12-30 17:40:20 +08:00
<template #default="scope">
2024-01-07 16:17:07 +08:00
<el-button link size="small" style="margin-right: 10px;" type="primary"
2024-01-22 14:17:33 +08:00
@click="drawer = true; logText = formatLogDisplayHtml(scope)">日志</el-button>
2023-12-30 17:40:20 +08:00
<el-tag v-if="scope.row.status == 0" type="danger">失败</el-tag>
<el-tag v-if="scope.row.status == 1" type="success">成功</el-tag>
</template>
</el-table-column>
</el-table>
</div>
2024-01-07 00:25:35 +08:00
<el-drawer v-model="drawer" :with-header="false">
2024-01-22 14:17:33 +08:00
<el-text v-html="logText" size="small"></el-text>
2024-01-07 00:25:35 +08:00
</el-drawer>
2023-12-30 17:40:20 +08:00
<div class="pagination-block">
<el-pagination layout="prev, pager, next" :total="total" :page-size="pageSize" @current-change="handPageChange" />
2024-01-17 23:15:47 +08:00
<el-text class="total-tip" size="small">每页{{ pageSize }}{{ total }}</el-text>
2023-12-30 17:40:20 +08:00
</div>
</div>
</div>
</template>
<script >
2024-01-20 16:42:56 +08:00
import { reactive, toRefs, onMounted, watch, ref } from 'vue'
2023-12-30 17:40:20 +08:00
import { request } from '../../../api/api'
import { copyToClipboard } from '../../../util/clipboard.js';
2024-01-07 16:17:07 +08:00
import { useRoute } from 'vue-router';
2023-12-30 17:40:20 +08:00
import { CONSTANT } from '@/constant'
2024-01-17 23:15:47 +08:00
import { usePageState } from '@/store/page_sate.js';
2024-01-20 16:42:56 +08:00
import { CommonUtils } from "@/util/commonUtils.js";
2023-12-30 17:40:20 +08:00
export default {
components: {
},
setup() {
2024-01-17 23:15:47 +08:00
const pageState = usePageState();
2023-12-30 17:40:20 +08:00
const router = useRoute();
const state = reactive({
search: '',
2024-01-20 16:42:56 +08:00
refreshText: '',
refreshSwitch: false,
refreshSec: 20,
refreshIntervalFuncList: [],
2023-12-30 17:40:20 +08:00
optionValue: '',
2024-01-07 00:25:35 +08:00
logText: '',
drawer: false,
2023-12-30 17:40:20 +08:00
tableData: [],
total: CONSTANT.TOTAL,
2024-01-17 23:15:47 +08:00
pageSize: pageState.siteConfigData.pagesize,
2023-12-30 17:40:20 +08:00
currPage: CONSTANT.PAGE,
});
const handleDelete = async (index, row) => {
const rsp = await request.post('/sendways/delete', { id: row.id });
if (rsp.status == 200) {
state.tableData.splice(index, 1);
}
}
const TransHtml = (raw) => {
if (raw) {
return raw.replace(/\n/g, '<br />')
}
return ''
}
2024-01-22 14:17:33 +08:00
const formatLogDisplayHtml = (scope) => {
let log = TransHtml(scope.row.log);
log += '<br />\n';
if (scope.row.caller_ip) {
log += `调用来源IP${scope.row.caller_ip}`;
};
return log;
}
2023-12-30 17:40:20 +08:00
const handPageChange = async (pageNum) => {
state.currPage = pageNum;
await queryListData(pageNum, state.pageSize);
}
const rowStyle = () => {
return {
'font-size': '13px',
}
}
2024-01-20 16:42:56 +08:00
const clickFreshSwitch = () => {
if (state.refreshSwitch) {
let flag = setInterval(async function () {
await filterFunc();
state.refreshText = `自动刷新于:${CommonUtils.getCurrentTimeStr()}`;
}, state.refreshSec * 1000);
state.refreshIntervalFuncList.push(flag);
} else {
state.refreshIntervalFuncList.forEach(intervalId => {
clearInterval(intervalId);
});
state.refreshIntervalFuncList = [];
state.refreshText = '';
}
}
2023-12-30 17:40:20 +08:00
const filterFunc = async () => {
await queryListData(state.currPage, state.pageSize, state.search, state.optionValue);
}
2024-01-25 15:08:00 +08:00
const queryListData = async (page, size, name = '', taskid = '', query = '') => {
let params = { page: page, size: size, name: name, taskid: taskid, query: query };
2023-12-30 17:40:20 +08:00
const rsp = await request.get('/sendlogs/list', { params: params });
state.tableData = await rsp.data.data.lists;
state.total = await rsp.data.data.total;
}
onMounted(async () => {
state.search = router.query.name;
2024-01-25 15:08:00 +08:00
await queryListData(1, state.pageSize, router.query.name, router.query.taskid, router.query.query);
2023-12-30 17:40:20 +08:00
});
return {
2024-01-20 16:42:56 +08:00
...toRefs(state), handleDelete, TransHtml, clickFreshSwitch,
2024-01-22 14:17:33 +08:00
rowStyle, handPageChange, filterFunc, copyToClipboard, formatLogDisplayHtml
2023-12-30 17:40:20 +08:00
};
}
}
</script>
<style scoped>
hr {
color: #FAFCFF;
background-color: #FAFCFF;
border-color: #FAFCFF;
}
.container {
background-color: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);
max-width: 1000px;
width: 100%;
margin-top: -10vh;
}
2024-01-20 16:42:56 +08:00
.search-box {
float: right;
margin-top: -2px;
}
.refresh-box {
width: 80px;
margin-right: 5px;
}
.refresh-time {
margin-right: 10px;
}
2023-12-30 17:40:20 +08:00
.pagination-block {
margin-top: 30px;
display: flex;
justify-content: flex-end;
2024-01-20 16:42:56 +08:00
2023-12-30 17:40:20 +08:00
}
.total-tip {
display: inline-block;
}
.search-input-sendways {
width: 200px;
display: inline-flex;
}
.log-overflow {
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 1;
-webkit-box-orient: vertical;
}
</style>