feat: 日志管理

This commit is contained in:
TsMask
2023-09-26 14:17:45 +08:00
parent 5f5cae28d1
commit 550a19e777
6 changed files with 4324 additions and 0 deletions

View File

@@ -0,0 +1,962 @@
<script setup lang="ts">
import { useRoute } from 'vue-router';
import { reactive, ref, onMounted, toRaw } from 'vue';
import { PageContainer } from '@ant-design-vue/pro-layout';
import { Form, message, Modal } from 'ant-design-vue/lib';
import { SizeType } from 'ant-design-vue/lib/config-provider';
import { MenuInfo } from 'ant-design-vue/lib/menu/src/interface';
import { ColumnsType } from 'ant-design-vue/lib/table';
import { parseDateToStr } from '@/utils/date-utils';
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
import useI18n from '@/hooks/useI18n';
import useUserStore from '@/store/modules/user';
import useNeInfoStore from '@/store/modules/neinfo';
import {
addTraceTask,
delTraceTask,
getTraceTask,
listTraceTask,
updateTraceTask,
} from '@/api/traceManage/task';
import useDictStore from '@/store/modules/dict';
import { regExpIPv4, regExpPort } from '@/utils/regular-utils';
const { getDict } = useDictStore();
const { t } = useI18n();
const route = useRoute();
/**路由标题 */
let title = ref<string>((route.meta.title as string) ?? '标题');
/**字典数据 */
let dict: {
/**跟踪类型 */
traceType: DictType[];
} = reactive({
traceType: [],
});
/**查询参数 */
let queryParams = reactive({
/**网元类型 */
neType: '',
/**当前页数 */
pageNum: 1,
/**每页条数 */
pageSize: 20,
});
/**查询参数重置 */
function fnQueryReset() {
queryParams = Object.assign(queryParams, {
neType: '',
pageNum: 1,
pageSize: 20,
});
tablePagination.current = 1;
tablePagination.pageSize = 20;
fnGetList();
}
/**表格状态类型 */
type TabeStateType = {
/**加载等待 */
loading: boolean;
/**紧凑型 */
size: SizeType;
/**搜索栏 */
seached: boolean;
/**记录数据 */
data: object[];
/**勾选记录 */
selectedRowKeys: (string | number)[];
};
/**表格状态 */
let tableState: TabeStateType = reactive({
loading: false,
size: 'middle',
seached: true,
data: [],
selectedRowKeys: [],
});
/**表格字段列 */
let tableColumns: ColumnsType = [
{
title: t('common.rowId'),
dataIndex: 'id',
align: 'center',
},
{
title: t('views.trace.task.neType'),
dataIndex: 'neType',
align: 'center',
},
{
title: t('views.trace.task.neID'),
dataIndex: 'neId',
align: 'center',
},
{
title: t('views.trace.task.trackType'),
dataIndex: 'traceType',
key: 'traceType',
align: 'center',
},
{
title: t('views.trace.task.trackType'),
dataIndex: 'accountId',
align: 'center',
},
{
title: t('views.trace.task.startTime'),
dataIndex: 'startTime',
align: 'center',
customRender(opt) {
if (!opt.value) return '';
return parseDateToStr(opt.value);
},
},
{
title: t('views.trace.task.endTime'),
dataIndex: 'endTime',
align: 'center',
customRender(opt) {
if (!opt.value) return '';
return parseDateToStr(opt.value);
},
},
{
title: t('common.operate'),
key: 'id',
align: 'center',
},
];
/**表格分页器参数 */
let tablePagination = reactive({
/**当前页数 */
current: 1,
/**每页条数 */
pageSize: 20,
/**默认的每页条数 */
defaultPageSize: 20,
/**指定每页可以显示多少条 */
pageSizeOptions: ['10', '20', '50', '100'],
/**只有一页时是否隐藏分页器 */
hideOnSinglePage: false,
/**是否可以快速跳转至某页 */
showQuickJumper: true,
/**是否可以改变 pageSize */
showSizeChanger: true,
/**数据总数 */
total: 0,
showTotal: (total: number) => t('common.tablePaginationTotal', { total }),
onChange: (page: number, pageSize: number) => {
tablePagination.current = page;
tablePagination.pageSize = pageSize;
queryParams.pageNum = page;
queryParams.pageSize = pageSize;
fnGetList();
},
});
/**表格紧凑型变更操作 */
function fnTableSize({ key }: MenuInfo) {
tableState.size = key as SizeType;
}
/**
* 备份信息删除
* @param row 记录编号ID
*/
function fnRecordDelete(id: string) {
Modal.confirm({
title: t('views.trace.task.tipTitle'),
content: t('views.trace.task.delTaskTip', { num: id }),
onOk() {
const key = 'delTraceTask';
message.loading({ content: t('common.loading'), key });
delTraceTask(id).then(res => {
if (res.code === RESULT_CODE_SUCCESS) {
message.success({
content: t('views.trace.task.delTask', { num: id }),
key,
duration: 2,
});
fnGetList();
} else {
message.error({
content: `${res.msg}`,
key: key,
duration: 2,
});
}
});
},
});
}
/**查询信息列表 */
function fnGetList() {
if (tableState.loading) return;
tableState.loading = true;
listTraceTask(toRaw(queryParams)).then(res => {
if (res.code === RESULT_CODE_SUCCESS && Array.isArray(res.rows)) {
// 取消勾选
if (tableState.selectedRowKeys.length > 0) {
tableState.selectedRowKeys = [];
}
tablePagination.total = res.total;
tableState.data = res.rows;
}
tableState.loading = false;
});
}
/**对话框对象信息状态类型 */
type ModalStateType = {
/**详情框是否显示 */
visibleByView: boolean;
/**新增框或修改框是否显示 */
visibleByEdit: boolean;
/**标题 */
title: string;
/**网元类型设备对象 */
neType: string[];
/**网元类型设备对象接口 */
neTypeInterface: Record<string, any>[];
/**网元类型设备对象接口选择 */
neTypeInterfaceSelect: string[];
/**任务开始结束时间 */
timeRangePicker: [string, string];
/**表单数据 */
from: Record<string, any>;
/**确定按钮 loading */
confirmLoading: boolean;
};
/**对话框对象信息状态 */
let modalState: ModalStateType = reactive({
visibleByView: false,
visibleByEdit: false,
title: '',
neType: [],
neTypeInterface: [],
neTypeInterfaceSelect: [],
timeRangePicker: ['', ''],
from: {
id: '',
neType: '',
neId: '',
traceType: 'Device',
startTime: '',
endTime: '',
comment: '',
// 跟踪类型用户
imsi: '',
msisdn: '',
// 跟踪类型接口
srcIp: '',
dstIp: '',
interfaces: '',
signalPort: '',
},
confirmLoading: false,
});
/**对话框内表单属性和校验规则 */
const modalStateFrom = Form.useForm(
modalState.from,
reactive({
traceType: [
{
required: true,
message: t('views.trace.task.trackTypePlease'),
},
],
neId: [
{
required: true,
message: t('views.trace.task.neTypePlease'),
},
],
endTime: [
{
required: true,
message: t('views.trace.task.rangePickerPlease'),
},
],
// 跟踪用户
imsi: [
{
required: true,
message: t('views.trace.task.imsiPlease'),
},
],
msisdn: [
{
required: true,
message: t('views.trace.task.msisdnPlease'),
},
],
// 跟踪接口
srcIp: [
{
required: true,
pattern: regExpIPv4,
message: t('views.trace.task.srcIpPlease'),
},
],
dstIp: [
{
required: true,
pattern: regExpIPv4,
message: t('views.trace.task.dstIpPlease'),
},
],
interfaces: [
{
required: true,
message: t('views.trace.task.interfacesPlease'),
},
],
signalPort: [
{
required: true,
pattern: regExpPort,
message: t('views.trace.task.signalPortPlease'),
},
],
})
);
/**网元类型选择对应修改 */
function fnNeChange(_: any, item: any) {
modalState.from.neType = item[1].neType;
modalState.from.neId = item[1].neId;
modalState.from.interfaces = '';
modalState.neTypeInterfaceSelect = [];
if (modalState.from.traceType !== 'Interface') return;
// 网元信令接口
fnSelectInterfaceInit(item[1].neType);
}
/**开始结束时间选择对应修改 */
function fnRangePickerChange(_: any, item: any) {
modalState.from.startTime = item[0];
modalState.from.endTime = item[1];
}
/**信令接口选择对应修改 */
function fnSelectInterface(s: any, _: any) {
modalState.from.interfaces = s.join(',');
}
/**信令接口选择初始 */
function fnSelectInterfaceInit(neType: string) {
const interfaces = useNeInfoStore().traceInterfaceList;
modalState.neTypeInterface = interfaces
.filter(i => i.neType === neType)
.map(i => {
return {
value: i.interface,
label: i.interface,
};
});
}
/**
* 对话框弹出显示为 新增或者修改
* @param noticeId 网元id, 不传为新增
*/
function fnModalVisibleByVive(id: string) {
if (modalState.confirmLoading) return;
const hide = message.loading(t('common.loading'), 0);
modalState.confirmLoading = true;
getTraceTask(id).then(res => {
modalState.confirmLoading = false;
hide();
if (res.code === RESULT_CODE_SUCCESS) {
modalState.neType = [res.data.neType, res.data.neId];
modalState.timeRangePicker = [res.data.startTime, res.data.endTime];
modalState.from = Object.assign(modalState.from, res.data);
// 接口
if (res.data.traceType === 'Interface') {
if (
res.data.interfaces.length > 4 &&
res.data.interfaces.includes('[')
) {
modalState.neTypeInterfaceSelect = JSON.parse(res.data.interfaces);
}
fnSelectInterfaceInit(res.data.neType);
}
modalState.title = t('views.trace.task.viewTask');
modalState.visibleByView = true;
} else {
message.error(t('views.trace.task.errorTaskInfo'), 3);
}
});
}
/**
* 对话框弹出显示为 新增或者修改
* @param noticeId 网元id, 不传为新增
*/
function fnModalVisibleByEdit(id?: string) {
if (!id) {
modalStateFrom.resetFields();
modalState.title = t('views.trace.task.addTask');
modalState.visibleByEdit = true;
} else {
if (modalState.confirmLoading) return;
const hide = message.loading(t('common.loading'), 0);
modalState.confirmLoading = true;
getTraceTask(id).then(res => {
modalState.confirmLoading = false;
hide();
if (res.code === RESULT_CODE_SUCCESS && res.data) {
modalState.neType = [res.data.neType, res.data.neId];
modalState.timeRangePicker = [res.data.startTime, res.data.endTime];
modalState.from = Object.assign(modalState.from, res.data);
// 接口
if (res.data.traceType === 'Interface') {
if (
res.data.interfaces.length > 4 &&
res.data.interfaces.includes('[')
) {
modalState.neTypeInterfaceSelect = JSON.parse(res.data.interfaces);
}
fnSelectInterfaceInit(res.data.neType);
}
modalState.title = t('views.trace.task.editTask');
modalState.visibleByEdit = true;
} else {
message.error(t('views.trace.task.errorTaskInfo'), 3);
}
});
}
}
/**
* 对话框弹出确认执行函数
* 进行表达规则校验
*/
function fnModalOk() {
const from = toRaw(modalState.from);
let valids = ['traceType', 'neId', 'endTime'];
if (from.traceType === 'UE') {
valids = valids.concat(['imsi', 'msisdn']);
}
if (from.traceType === 'Interface') {
valids = valids.concat(['srcIp', 'dstIp', 'interfaces', 'signalPort']);
}
from.accountId = useUserStore().userName;
modalStateFrom
.validate(valids)
.then(e => {
modalState.confirmLoading = true;
const traceTask = from.id ? updateTraceTask(from) : addTraceTask(from);
const hide = message.loading(t('common.loading'), 0);
traceTask
.then(res => {
console.log(res);
if (res.code === RESULT_CODE_SUCCESS) {
message.success({
content: t('common.msgSuccess', { msg: modalState.title }),
duration: 3,
});
modalState.visibleByEdit = false;
modalStateFrom.resetFields();
} else {
message.error({
content: `${res.msg}`,
duration: 3,
});
}
})
.finally(() => {
hide();
modalState.confirmLoading = false;
fnGetList();
});
})
.catch(e => {
message.error(t('common.errorFields', { num: e.errorFields.length }), 3);
});
}
/**
* 对话框弹出关闭执行函数
* 进行表达规则校验
*/
function fnModalCancel() {
modalState.visibleByView = false;
modalState.visibleByEdit = false;
modalState.confirmLoading = false;
modalStateFrom.resetFields();
modalState.timeRangePicker = ['', ''];
modalState.neTypeInterfaceSelect = [];
modalState.neType = [];
modalState.neTypeInterface = [];
}
onMounted(() => {
// 初始字典数据
Promise.allSettled([getDict('trace_type')]).then(resArr => {
if (resArr[0].status === 'fulfilled') {
dict.traceType = resArr[0].value;
}
});
Promise.allSettled([
// 获取网元网元列表
useNeInfoStore().fnNelist(),
// 获取跟踪接口列表
useNeInfoStore().fnNeTraceInterface(),
]).finally(() => {
// 获取列表数据
fnGetList();
});
});
</script>
<template>
<PageContainer :title="title">
<a-card
v-show="tableState.seached"
:bordered="false"
:body-style="{ marginBottom: '24px', paddingBottom: 0 }"
>
<!-- 表格搜索栏 -->
<a-form :model="queryParams" name="queryParams" layout="horizontal">
<a-row :gutter="16">
<a-col :lg="6" :md="12" :xs="24">
<a-form-item :label="t('views.trace.task.neType')" name="neType ">
<a-auto-complete
v-model:value="queryParams.neType"
:options="useNeInfoStore().getNeSelectOtions"
allow-clear
:placeholder="t('views.trace.task.neTypePlease')"
/>
</a-form-item>
</a-col>
<a-col :lg="6" :md="12" :xs="24">
<a-form-item>
<a-space :size="8">
<a-button type="primary" @click.prevent="fnGetList">
<template #icon><SearchOutlined /></template>
{{ t('common.search') }}
</a-button>
<a-button type="default" @click.prevent="fnQueryReset">
<template #icon><ClearOutlined /></template>
{{ t('common.reset') }}
</a-button>
</a-space>
</a-form-item>
</a-col>
</a-row>
</a-form>
</a-card>
<a-card :bordered="false" :body-style="{ padding: '0px' }">
<!-- 插槽-卡片左侧侧 -->
<template #title>
<a-button type="primary" @click.prevent="fnModalVisibleByEdit()">
<template #icon><PlusOutlined /></template>
{{ t('common.addText') }}
</a-button>
</template>
<!-- 插槽-卡片右侧 -->
<template #extra>
<a-space :size="8" align="center">
<a-tooltip placement="topRight">
<template #title>{{ t('common.searchBarText') }}</template>
<a-switch
v-model:checked="tableState.seached"
:checked-children="t('common.switch.show')"
:un-checked-children="t('common.switch.hide')"
size="small"
/>
</a-tooltip>
<a-tooltip placement="topRight">
<template #title>{{ t('common.reloadText') }}</template>
<a-button type="text" @click.prevent="fnGetList">
<template #icon><ReloadOutlined /></template>
</a-button>
</a-tooltip>
<a-tooltip placement="topRight">
<template #title>{{ t('common.sizeText') }}</template>
<a-dropdown trigger="click" placement="bottomRight">
<a-button type="text">
<template #icon><ColumnHeightOutlined /></template>
</a-button>
<template #overlay>
<a-menu
:selected-keys="[tableState.size as string]"
@click="fnTableSize"
>
<a-menu-item key="default">{{
t('common.size.default')
}}</a-menu-item>
<a-menu-item key="middle">{{
t('common.size.middle')
}}</a-menu-item>
<a-menu-item key="small">{{
t('common.size.small')
}}</a-menu-item>
</a-menu>
</template>
</a-dropdown>
</a-tooltip>
</a-space>
</template>
<!-- 表格列表 -->
<a-table
class="table"
row-key="id"
:columns="tableColumns"
:loading="tableState.loading"
:data-source="tableState.data"
:size="tableState.size"
:pagination="tablePagination"
:scroll="{ x: true }"
>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'traceType'">
<DictTag :options="dict.traceType" :value="record.traceType" />
</template>
<template v-if="column.key === 'id'">
<a-space :size="8" align="center">
<a-tooltip>
<template #title>{{ t('common.viewText') }}</template>
<a-button
type="link"
@click.prevent="fnModalVisibleByVive(record.id)"
>
<template #icon><ProfileOutlined /></template>
</a-button>
</a-tooltip>
<a-tooltip>
<template #title>{{ t('common.editText') }}</template>
<a-button
type="link"
@click.prevent="fnModalVisibleByEdit(record.id)"
>
<template #icon><FormOutlined /></template>
</a-button>
</a-tooltip>
<a-tooltip>
<template #title>{{ t('common.deleteText') }}</template>
<a-button
type="link"
@click.prevent="fnRecordDelete(record.id)"
>
<template #icon><DeleteOutlined /></template>
</a-button>
</a-tooltip>
</a-space>
</template>
</template>
</a-table>
</a-card>
<!-- 详情框 -->
<a-modal
width="800px"
:visible="modalState.visibleByView"
:title="modalState.title"
@cancel="fnModalCancel"
>
<a-form layout="horizontal">
<a-row :gutter="16">
<a-col :lg="12" :md="12" :xs="24">
<a-form-item
:label="t('views.trace.task.trackType')"
name="traceType"
>
<DictTag
:options="dict.traceType"
:value="modalState.from.traceType"
/>
</a-form-item>
</a-col>
<a-col :lg="12" :md="12" :xs="24">
<a-form-item :label="t('views.trace.task.neType')" name="neType">
<a-cascader
:value="modalState.neType"
:options="useNeInfoStore().getNeCascaderOtions"
disabled
/>
</a-form-item>
</a-col>
</a-row>
<!-- 用户跟踪 -->
<template v-if="modalState.from.traceType === 'UE'">
<a-form-item :label="t('views.trace.task.msisdn')" name="msisdn">
{{ modalState.from.msisdn }}
</a-form-item>
<a-form-item :label="t('views.trace.task.imsi')" name="imsi">
{{ modalState.from.imsi }}
</a-form-item>
</template>
<!-- 接口跟踪 -->
<template v-if="modalState.from.traceType === 'Interface'">
<a-row :gutter="16">
<a-col :lg="12" :md="12" :xs="24">
<a-form-item :label="t('views.trace.task.srcIp')" name="srcIp">
{{ modalState.from.srcIp }}
</a-form-item>
</a-col>
<a-col :lg="12" :md="12" :xs="24">
<a-form-item :label="t('views.trace.task.dstIp')" name="dstIp">
{{ modalState.from.dstIp }}
</a-form-item>
</a-col>
</a-row>
<a-form-item :label="t('views.trace.task.interfaces')" name="endTime">
{{ modalState.neTypeInterfaceSelect }}
</a-form-item>
<a-form-item :label="t('views.trace.task.signalPort')" name="endTime">
{{ modalState.from.signalPort }}
</a-form-item>
</template>
<a-form-item :label="t('views.trace.task.rangePicker')" name="endTime">
<a-range-picker
disabled
:value="modalState.timeRangePicker"
allow-clear
bordered
:show-time="{ format: 'HH:mm:ss' }"
format="YYYY-MM-DD HH:mm:ss"
value-format="YYYY-MM-DD HH:mm:ss"
style="width: 100%"
></a-range-picker>
</a-form-item>
<a-form-item :label="t('views.trace.task.comment')" name="comment">
{{ modalState.from.comment }}
</a-form-item>
</a-form>
<template #footer>
<a-button key="cancel" @click="fnModalCancel">{{
t('common.close')
}}</a-button>
</template>
</a-modal>
<!-- 新增框或修改框 -->
<a-modal
width="800px"
:keyboard="false"
:mask-closable="false"
:visible="modalState.visibleByEdit"
:title="modalState.title"
:confirm-loading="modalState.confirmLoading"
@ok="fnModalOk"
@cancel="fnModalCancel"
>
<a-form name="modalStateFrom" layout="horizontal">
<a-row :gutter="16">
<a-col :lg="12" :md="12" :xs="24">
<a-form-item
:label="t('views.trace.task.trackType')"
name="traceType"
v-bind="modalStateFrom.validateInfos.traceType"
>
<a-select
v-model:value="modalState.from.traceType"
:placeholder="t('views.trace.task.trackTypePlease')"
:options="dict.traceType"
>
</a-select>
</a-form-item>
</a-col>
<a-col :lg="12" :md="12" :xs="24">
<a-form-item
:label="t('views.trace.task.neType')"
name="neType"
v-bind="modalStateFrom.validateInfos.neId"
>
<a-cascader
v-model:value="modalState.neType"
:options="useNeInfoStore().getNeCascaderOtions"
@change="fnNeChange"
:allow-clear="false"
:placeholder="t('views.trace.task.neTypePlease')"
/>
</a-form-item>
</a-col>
</a-row>
<!-- 用户跟踪 -->
<template v-if="modalState.from.traceType === 'UE'">
<a-form-item
:label="t('views.trace.task.msisdn')"
name="msisdn"
v-bind="modalStateFrom.validateInfos.msisdn"
>
<a-input
v-model:value="modalState.from.msisdn"
allow-clear
:placeholder="t('views.trace.task.msisdnPlease')"
>
<template #prefix>
<a-tooltip placement="topLeft">
<template #title>
<div>{{ t('views.trace.task.msisdnTip') }}</div>
</template>
<InfoCircleOutlined style="color: rgba(0, 0, 0, 0.45)" />
</a-tooltip>
</template>
</a-input>
</a-form-item>
<a-form-item
:label="t('views.trace.task.imsi')"
name="imsi"
v-bind="modalStateFrom.validateInfos.imsi"
>
<a-input
v-model:value="modalState.from.imsi"
allow-clear
:placeholder="t('views.trace.task.imsiPlease')"
>
<template #prefix>
<a-tooltip placement="topLeft">
<template #title>
<div>{{ t('views.trace.task.imsiTip') }}</div>
</template>
<InfoCircleOutlined style="color: rgba(0, 0, 0, 0.45)" />
</a-tooltip>
</template>
</a-input>
</a-form-item>
</template>
<!-- 接口跟踪 -->
<template v-if="modalState.from.traceType === 'Interface'">
<a-row :gutter="16">
<a-col :lg="12" :md="12" :xs="24">
<a-form-item
:label="t('views.trace.task.srcIp')"
name="srcIp"
v-bind="modalStateFrom.validateInfos.srcIp"
>
<a-input
v-model:value="modalState.from.srcIp"
allow-clear
placeholder="t('views.trace.task.srcIpPlease')"
>
<template #prefix>
<a-tooltip placement="topLeft">
<template #title>
<div>{{ t('views.trace.task.srcIpTip') }}</div>
</template>
<InfoCircleOutlined style="color: rgba(0, 0, 0, 0.45)" />
</a-tooltip>
</template>
</a-input>
</a-form-item>
</a-col>
<a-col :lg="12" :md="12" :xs="24">
<a-form-item
:label="t('views.trace.task.dstIp')"
name="dstIp"
v-bind="modalStateFrom.validateInfos.dstIp"
>
<a-input
v-model:value="modalState.from.dstIp"
allow-clear
:placeholder="t('views.trace.task.dstIpPlease')"
>
<template #prefix>
<a-tooltip placement="topLeft">
<template #title>
<div>{{ t('views.trace.task.dstIpTip') }}</div>
</template>
<InfoCircleOutlined style="color: rgba(0, 0, 0, 0.45)" />
</a-tooltip>
</template>
</a-input>
</a-form-item>
</a-col>
</a-row>
<a-form-item
:label="t('views.trace.task.interfaces')"
name="interfaces"
v-bind="modalStateFrom.validateInfos.interfaces"
>
<a-select
mode="multiple"
placeholder="Please select"
v-model:value="modalState.neTypeInterfaceSelect"
:options="modalState.neTypeInterface"
@change="fnSelectInterface"
>
</a-select>
</a-form-item>
<a-form-item
:label="t('views.trace.task.signalPort')"
name="signalPort"
v-bind="modalStateFrom.validateInfos.signalPort"
>
<a-input
v-model:value="modalState.from.signalPort"
allow-clear
:placeholder="t('views.trace.task.signalPortPlease')"
>
<template #prefix>
<a-tooltip placement="topLeft">
<template #title>
<div>t('views.trace.task.signalPortTip')</div>
</template>
<InfoCircleOutlined style="color: rgba(0, 0, 0, 0.45)" />
</a-tooltip>
</template>
</a-input>
</a-form-item>
</template>
<a-form-item
:label="t('views.trace.task.rangePicker')"
name="endTime"
v-bind="modalStateFrom.validateInfos.endTime"
>
<a-range-picker
v-model:value="modalState.timeRangePicker"
@change="fnRangePickerChange"
allow-clear
bordered
:show-time="{ format: 'HH:mm:ss' }"
format="YYYY-MM-DD HH:mm:ss"
value-format="YYYY-MM-DD HH:mm:ss"
:placeholder="[
t('views.trace.task.startTime'),
t('views.trace.task.endTime'),
]"
style="width: 100%"
></a-range-picker>
</a-form-item>
<a-form-item :label="t('views.trace.task.comment')" name="comment">
<a-textarea
v-model:value="modalState.from.comment"
:auto-size="{ minRows: 2, maxRows: 6 }"
:maxlength="250"
:show-count="true"
:placeholder="t('views.trace.task.commentPlease')"
/>
</a-form-item>
</a-form>
</a-modal>
</PageContainer>
</template>
<style lang="less" scoped>
.table :deep(.ant-pagination) {
padding: 0 24px;
}
</style>

View File

@@ -0,0 +1,962 @@
<script setup lang="ts">
import { useRoute } from 'vue-router';
import { reactive, ref, onMounted, toRaw } from 'vue';
import { PageContainer } from '@ant-design-vue/pro-layout';
import { Form, message, Modal } from 'ant-design-vue/lib';
import { SizeType } from 'ant-design-vue/lib/config-provider';
import { MenuInfo } from 'ant-design-vue/lib/menu/src/interface';
import { ColumnsType } from 'ant-design-vue/lib/table';
import { parseDateToStr } from '@/utils/date-utils';
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
import useI18n from '@/hooks/useI18n';
import useUserStore from '@/store/modules/user';
import useNeInfoStore from '@/store/modules/neinfo';
import {
addTraceTask,
delTraceTask,
getTraceTask,
listTraceTask,
updateTraceTask,
} from '@/api/traceManage/task';
import useDictStore from '@/store/modules/dict';
import { regExpIPv4, regExpPort } from '@/utils/regular-utils';
const { getDict } = useDictStore();
const { t } = useI18n();
const route = useRoute();
/**路由标题 */
let title = ref<string>((route.meta.title as string) ?? '标题');
/**字典数据 */
let dict: {
/**跟踪类型 */
traceType: DictType[];
} = reactive({
traceType: [],
});
/**查询参数 */
let queryParams = reactive({
/**网元类型 */
neType: '',
/**当前页数 */
pageNum: 1,
/**每页条数 */
pageSize: 20,
});
/**查询参数重置 */
function fnQueryReset() {
queryParams = Object.assign(queryParams, {
neType: '',
pageNum: 1,
pageSize: 20,
});
tablePagination.current = 1;
tablePagination.pageSize = 20;
fnGetList();
}
/**表格状态类型 */
type TabeStateType = {
/**加载等待 */
loading: boolean;
/**紧凑型 */
size: SizeType;
/**搜索栏 */
seached: boolean;
/**记录数据 */
data: object[];
/**勾选记录 */
selectedRowKeys: (string | number)[];
};
/**表格状态 */
let tableState: TabeStateType = reactive({
loading: false,
size: 'middle',
seached: true,
data: [],
selectedRowKeys: [],
});
/**表格字段列 */
let tableColumns: ColumnsType = [
{
title: t('common.rowId'),
dataIndex: 'id',
align: 'center',
},
{
title: t('views.trace.task.neType'),
dataIndex: 'neType',
align: 'center',
},
{
title: t('views.trace.task.neID'),
dataIndex: 'neId',
align: 'center',
},
{
title: t('views.trace.task.trackType'),
dataIndex: 'traceType',
key: 'traceType',
align: 'center',
},
{
title: t('views.trace.task.trackType'),
dataIndex: 'accountId',
align: 'center',
},
{
title: t('views.trace.task.startTime'),
dataIndex: 'startTime',
align: 'center',
customRender(opt) {
if (!opt.value) return '';
return parseDateToStr(opt.value);
},
},
{
title: t('views.trace.task.endTime'),
dataIndex: 'endTime',
align: 'center',
customRender(opt) {
if (!opt.value) return '';
return parseDateToStr(opt.value);
},
},
{
title: t('common.operate'),
key: 'id',
align: 'center',
},
];
/**表格分页器参数 */
let tablePagination = reactive({
/**当前页数 */
current: 1,
/**每页条数 */
pageSize: 20,
/**默认的每页条数 */
defaultPageSize: 20,
/**指定每页可以显示多少条 */
pageSizeOptions: ['10', '20', '50', '100'],
/**只有一页时是否隐藏分页器 */
hideOnSinglePage: false,
/**是否可以快速跳转至某页 */
showQuickJumper: true,
/**是否可以改变 pageSize */
showSizeChanger: true,
/**数据总数 */
total: 0,
showTotal: (total: number) => t('common.tablePaginationTotal', { total }),
onChange: (page: number, pageSize: number) => {
tablePagination.current = page;
tablePagination.pageSize = pageSize;
queryParams.pageNum = page;
queryParams.pageSize = pageSize;
fnGetList();
},
});
/**表格紧凑型变更操作 */
function fnTableSize({ key }: MenuInfo) {
tableState.size = key as SizeType;
}
/**
* 备份信息删除
* @param row 记录编号ID
*/
function fnRecordDelete(id: string) {
Modal.confirm({
title: t('views.trace.task.tipTitle'),
content: t('views.trace.task.delTaskTip', { num: id }),
onOk() {
const key = 'delTraceTask';
message.loading({ content: t('common.loading'), key });
delTraceTask(id).then(res => {
if (res.code === RESULT_CODE_SUCCESS) {
message.success({
content: t('views.trace.task.delTask', { num: id }),
key,
duration: 2,
});
fnGetList();
} else {
message.error({
content: `${res.msg}`,
key: key,
duration: 2,
});
}
});
},
});
}
/**查询信息列表 */
function fnGetList() {
if (tableState.loading) return;
tableState.loading = true;
listTraceTask(toRaw(queryParams)).then(res => {
if (res.code === RESULT_CODE_SUCCESS && Array.isArray(res.rows)) {
// 取消勾选
if (tableState.selectedRowKeys.length > 0) {
tableState.selectedRowKeys = [];
}
tablePagination.total = res.total;
tableState.data = res.rows;
}
tableState.loading = false;
});
}
/**对话框对象信息状态类型 */
type ModalStateType = {
/**详情框是否显示 */
visibleByView: boolean;
/**新增框或修改框是否显示 */
visibleByEdit: boolean;
/**标题 */
title: string;
/**网元类型设备对象 */
neType: string[];
/**网元类型设备对象接口 */
neTypeInterface: Record<string, any>[];
/**网元类型设备对象接口选择 */
neTypeInterfaceSelect: string[];
/**任务开始结束时间 */
timeRangePicker: [string, string];
/**表单数据 */
from: Record<string, any>;
/**确定按钮 loading */
confirmLoading: boolean;
};
/**对话框对象信息状态 */
let modalState: ModalStateType = reactive({
visibleByView: false,
visibleByEdit: false,
title: '',
neType: [],
neTypeInterface: [],
neTypeInterfaceSelect: [],
timeRangePicker: ['', ''],
from: {
id: '',
neType: '',
neId: '',
traceType: 'Device',
startTime: '',
endTime: '',
comment: '',
// 跟踪类型用户
imsi: '',
msisdn: '',
// 跟踪类型接口
srcIp: '',
dstIp: '',
interfaces: '',
signalPort: '',
},
confirmLoading: false,
});
/**对话框内表单属性和校验规则 */
const modalStateFrom = Form.useForm(
modalState.from,
reactive({
traceType: [
{
required: true,
message: t('views.trace.task.trackTypePlease'),
},
],
neId: [
{
required: true,
message: t('views.trace.task.neTypePlease'),
},
],
endTime: [
{
required: true,
message: t('views.trace.task.rangePickerPlease'),
},
],
// 跟踪用户
imsi: [
{
required: true,
message: t('views.trace.task.imsiPlease'),
},
],
msisdn: [
{
required: true,
message: t('views.trace.task.msisdnPlease'),
},
],
// 跟踪接口
srcIp: [
{
required: true,
pattern: regExpIPv4,
message: t('views.trace.task.srcIpPlease'),
},
],
dstIp: [
{
required: true,
pattern: regExpIPv4,
message: t('views.trace.task.dstIpPlease'),
},
],
interfaces: [
{
required: true,
message: t('views.trace.task.interfacesPlease'),
},
],
signalPort: [
{
required: true,
pattern: regExpPort,
message: t('views.trace.task.signalPortPlease'),
},
],
})
);
/**网元类型选择对应修改 */
function fnNeChange(_: any, item: any) {
modalState.from.neType = item[1].neType;
modalState.from.neId = item[1].neId;
modalState.from.interfaces = '';
modalState.neTypeInterfaceSelect = [];
if (modalState.from.traceType !== 'Interface') return;
// 网元信令接口
fnSelectInterfaceInit(item[1].neType);
}
/**开始结束时间选择对应修改 */
function fnRangePickerChange(_: any, item: any) {
modalState.from.startTime = item[0];
modalState.from.endTime = item[1];
}
/**信令接口选择对应修改 */
function fnSelectInterface(s: any, _: any) {
modalState.from.interfaces = s.join(',');
}
/**信令接口选择初始 */
function fnSelectInterfaceInit(neType: string) {
const interfaces = useNeInfoStore().traceInterfaceList;
modalState.neTypeInterface = interfaces
.filter(i => i.neType === neType)
.map(i => {
return {
value: i.interface,
label: i.interface,
};
});
}
/**
* 对话框弹出显示为 新增或者修改
* @param noticeId 网元id, 不传为新增
*/
function fnModalVisibleByVive(id: string) {
if (modalState.confirmLoading) return;
const hide = message.loading(t('common.loading'), 0);
modalState.confirmLoading = true;
getTraceTask(id).then(res => {
modalState.confirmLoading = false;
hide();
if (res.code === RESULT_CODE_SUCCESS) {
modalState.neType = [res.data.neType, res.data.neId];
modalState.timeRangePicker = [res.data.startTime, res.data.endTime];
modalState.from = Object.assign(modalState.from, res.data);
// 接口
if (res.data.traceType === 'Interface') {
if (
res.data.interfaces.length > 4 &&
res.data.interfaces.includes('[')
) {
modalState.neTypeInterfaceSelect = JSON.parse(res.data.interfaces);
}
fnSelectInterfaceInit(res.data.neType);
}
modalState.title = t('views.trace.task.viewTask');
modalState.visibleByView = true;
} else {
message.error(t('views.trace.task.errorTaskInfo'), 3);
}
});
}
/**
* 对话框弹出显示为 新增或者修改
* @param noticeId 网元id, 不传为新增
*/
function fnModalVisibleByEdit(id?: string) {
if (!id) {
modalStateFrom.resetFields();
modalState.title = t('views.trace.task.addTask');
modalState.visibleByEdit = true;
} else {
if (modalState.confirmLoading) return;
const hide = message.loading(t('common.loading'), 0);
modalState.confirmLoading = true;
getTraceTask(id).then(res => {
modalState.confirmLoading = false;
hide();
if (res.code === RESULT_CODE_SUCCESS && res.data) {
modalState.neType = [res.data.neType, res.data.neId];
modalState.timeRangePicker = [res.data.startTime, res.data.endTime];
modalState.from = Object.assign(modalState.from, res.data);
// 接口
if (res.data.traceType === 'Interface') {
if (
res.data.interfaces.length > 4 &&
res.data.interfaces.includes('[')
) {
modalState.neTypeInterfaceSelect = JSON.parse(res.data.interfaces);
}
fnSelectInterfaceInit(res.data.neType);
}
modalState.title = t('views.trace.task.editTask');
modalState.visibleByEdit = true;
} else {
message.error(t('views.trace.task.errorTaskInfo'), 3);
}
});
}
}
/**
* 对话框弹出确认执行函数
* 进行表达规则校验
*/
function fnModalOk() {
const from = toRaw(modalState.from);
let valids = ['traceType', 'neId', 'endTime'];
if (from.traceType === 'UE') {
valids = valids.concat(['imsi', 'msisdn']);
}
if (from.traceType === 'Interface') {
valids = valids.concat(['srcIp', 'dstIp', 'interfaces', 'signalPort']);
}
from.accountId = useUserStore().userName;
modalStateFrom
.validate(valids)
.then(e => {
modalState.confirmLoading = true;
const traceTask = from.id ? updateTraceTask(from) : addTraceTask(from);
const hide = message.loading(t('common.loading'), 0);
traceTask
.then(res => {
console.log(res);
if (res.code === RESULT_CODE_SUCCESS) {
message.success({
content: t('common.msgSuccess', { msg: modalState.title }),
duration: 3,
});
modalState.visibleByEdit = false;
modalStateFrom.resetFields();
} else {
message.error({
content: `${res.msg}`,
duration: 3,
});
}
})
.finally(() => {
hide();
modalState.confirmLoading = false;
fnGetList();
});
})
.catch(e => {
message.error(t('common.errorFields', { num: e.errorFields.length }), 3);
});
}
/**
* 对话框弹出关闭执行函数
* 进行表达规则校验
*/
function fnModalCancel() {
modalState.visibleByView = false;
modalState.visibleByEdit = false;
modalState.confirmLoading = false;
modalStateFrom.resetFields();
modalState.timeRangePicker = ['', ''];
modalState.neTypeInterfaceSelect = [];
modalState.neType = [];
modalState.neTypeInterface = [];
}
onMounted(() => {
// 初始字典数据
Promise.allSettled([getDict('trace_type')]).then(resArr => {
if (resArr[0].status === 'fulfilled') {
dict.traceType = resArr[0].value;
}
});
Promise.allSettled([
// 获取网元网元列表
useNeInfoStore().fnNelist(),
// 获取跟踪接口列表
useNeInfoStore().fnNeTraceInterface(),
]).finally(() => {
// 获取列表数据
fnGetList();
});
});
</script>
<template>
<PageContainer :title="title">
<a-card
v-show="tableState.seached"
:bordered="false"
:body-style="{ marginBottom: '24px', paddingBottom: 0 }"
>
<!-- 表格搜索栏 -->
<a-form :model="queryParams" name="queryParams" layout="horizontal">
<a-row :gutter="16">
<a-col :lg="6" :md="12" :xs="24">
<a-form-item :label="t('views.trace.task.neType')" name="neType ">
<a-auto-complete
v-model:value="queryParams.neType"
:options="useNeInfoStore().getNeSelectOtions"
allow-clear
:placeholder="t('views.trace.task.neTypePlease')"
/>
</a-form-item>
</a-col>
<a-col :lg="6" :md="12" :xs="24">
<a-form-item>
<a-space :size="8">
<a-button type="primary" @click.prevent="fnGetList">
<template #icon><SearchOutlined /></template>
{{ t('common.search') }}
</a-button>
<a-button type="default" @click.prevent="fnQueryReset">
<template #icon><ClearOutlined /></template>
{{ t('common.reset') }}
</a-button>
</a-space>
</a-form-item>
</a-col>
</a-row>
</a-form>
</a-card>
<a-card :bordered="false" :body-style="{ padding: '0px' }">
<!-- 插槽-卡片左侧侧 -->
<template #title>
<a-button type="primary" @click.prevent="fnModalVisibleByEdit()">
<template #icon><PlusOutlined /></template>
{{ t('common.addText') }}
</a-button>
</template>
<!-- 插槽-卡片右侧 -->
<template #extra>
<a-space :size="8" align="center">
<a-tooltip placement="topRight">
<template #title>{{ t('common.searchBarText') }}</template>
<a-switch
v-model:checked="tableState.seached"
:checked-children="t('common.switch.show')"
:un-checked-children="t('common.switch.hide')"
size="small"
/>
</a-tooltip>
<a-tooltip placement="topRight">
<template #title>{{ t('common.reloadText') }}</template>
<a-button type="text" @click.prevent="fnGetList">
<template #icon><ReloadOutlined /></template>
</a-button>
</a-tooltip>
<a-tooltip placement="topRight">
<template #title>{{ t('common.sizeText') }}</template>
<a-dropdown trigger="click" placement="bottomRight">
<a-button type="text">
<template #icon><ColumnHeightOutlined /></template>
</a-button>
<template #overlay>
<a-menu
:selected-keys="[tableState.size as string]"
@click="fnTableSize"
>
<a-menu-item key="default">{{
t('common.size.default')
}}</a-menu-item>
<a-menu-item key="middle">{{
t('common.size.middle')
}}</a-menu-item>
<a-menu-item key="small">{{
t('common.size.small')
}}</a-menu-item>
</a-menu>
</template>
</a-dropdown>
</a-tooltip>
</a-space>
</template>
<!-- 表格列表 -->
<a-table
class="table"
row-key="id"
:columns="tableColumns"
:loading="tableState.loading"
:data-source="tableState.data"
:size="tableState.size"
:pagination="tablePagination"
:scroll="{ x: true }"
>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'traceType'">
<DictTag :options="dict.traceType" :value="record.traceType" />
</template>
<template v-if="column.key === 'id'">
<a-space :size="8" align="center">
<a-tooltip>
<template #title>{{ t('common.viewText') }}</template>
<a-button
type="link"
@click.prevent="fnModalVisibleByVive(record.id)"
>
<template #icon><ProfileOutlined /></template>
</a-button>
</a-tooltip>
<a-tooltip>
<template #title>{{ t('common.editText') }}</template>
<a-button
type="link"
@click.prevent="fnModalVisibleByEdit(record.id)"
>
<template #icon><FormOutlined /></template>
</a-button>
</a-tooltip>
<a-tooltip>
<template #title>{{ t('common.deleteText') }}</template>
<a-button
type="link"
@click.prevent="fnRecordDelete(record.id)"
>
<template #icon><DeleteOutlined /></template>
</a-button>
</a-tooltip>
</a-space>
</template>
</template>
</a-table>
</a-card>
<!-- 详情框 -->
<a-modal
width="800px"
:visible="modalState.visibleByView"
:title="modalState.title"
@cancel="fnModalCancel"
>
<a-form layout="horizontal">
<a-row :gutter="16">
<a-col :lg="12" :md="12" :xs="24">
<a-form-item
:label="t('views.trace.task.trackType')"
name="traceType"
>
<DictTag
:options="dict.traceType"
:value="modalState.from.traceType"
/>
</a-form-item>
</a-col>
<a-col :lg="12" :md="12" :xs="24">
<a-form-item :label="t('views.trace.task.neType')" name="neType">
<a-cascader
:value="modalState.neType"
:options="useNeInfoStore().getNeCascaderOtions"
disabled
/>
</a-form-item>
</a-col>
</a-row>
<!-- 用户跟踪 -->
<template v-if="modalState.from.traceType === 'UE'">
<a-form-item :label="t('views.trace.task.msisdn')" name="msisdn">
{{ modalState.from.msisdn }}
</a-form-item>
<a-form-item :label="t('views.trace.task.imsi')" name="imsi">
{{ modalState.from.imsi }}
</a-form-item>
</template>
<!-- 接口跟踪 -->
<template v-if="modalState.from.traceType === 'Interface'">
<a-row :gutter="16">
<a-col :lg="12" :md="12" :xs="24">
<a-form-item :label="t('views.trace.task.srcIp')" name="srcIp">
{{ modalState.from.srcIp }}
</a-form-item>
</a-col>
<a-col :lg="12" :md="12" :xs="24">
<a-form-item :label="t('views.trace.task.dstIp')" name="dstIp">
{{ modalState.from.dstIp }}
</a-form-item>
</a-col>
</a-row>
<a-form-item :label="t('views.trace.task.interfaces')" name="endTime">
{{ modalState.neTypeInterfaceSelect }}
</a-form-item>
<a-form-item :label="t('views.trace.task.signalPort')" name="endTime">
{{ modalState.from.signalPort }}
</a-form-item>
</template>
<a-form-item :label="t('views.trace.task.rangePicker')" name="endTime">
<a-range-picker
disabled
:value="modalState.timeRangePicker"
allow-clear
bordered
:show-time="{ format: 'HH:mm:ss' }"
format="YYYY-MM-DD HH:mm:ss"
value-format="YYYY-MM-DD HH:mm:ss"
style="width: 100%"
></a-range-picker>
</a-form-item>
<a-form-item :label="t('views.trace.task.comment')" name="comment">
{{ modalState.from.comment }}
</a-form-item>
</a-form>
<template #footer>
<a-button key="cancel" @click="fnModalCancel">{{
t('common.close')
}}</a-button>
</template>
</a-modal>
<!-- 新增框或修改框 -->
<a-modal
width="800px"
:keyboard="false"
:mask-closable="false"
:visible="modalState.visibleByEdit"
:title="modalState.title"
:confirm-loading="modalState.confirmLoading"
@ok="fnModalOk"
@cancel="fnModalCancel"
>
<a-form name="modalStateFrom" layout="horizontal">
<a-row :gutter="16">
<a-col :lg="12" :md="12" :xs="24">
<a-form-item
:label="t('views.trace.task.trackType')"
name="traceType"
v-bind="modalStateFrom.validateInfos.traceType"
>
<a-select
v-model:value="modalState.from.traceType"
:placeholder="t('views.trace.task.trackTypePlease')"
:options="dict.traceType"
>
</a-select>
</a-form-item>
</a-col>
<a-col :lg="12" :md="12" :xs="24">
<a-form-item
:label="t('views.trace.task.neType')"
name="neType"
v-bind="modalStateFrom.validateInfos.neId"
>
<a-cascader
v-model:value="modalState.neType"
:options="useNeInfoStore().getNeCascaderOtions"
@change="fnNeChange"
:allow-clear="false"
:placeholder="t('views.trace.task.neTypePlease')"
/>
</a-form-item>
</a-col>
</a-row>
<!-- 用户跟踪 -->
<template v-if="modalState.from.traceType === 'UE'">
<a-form-item
:label="t('views.trace.task.msisdn')"
name="msisdn"
v-bind="modalStateFrom.validateInfos.msisdn"
>
<a-input
v-model:value="modalState.from.msisdn"
allow-clear
:placeholder="t('views.trace.task.msisdnPlease')"
>
<template #prefix>
<a-tooltip placement="topLeft">
<template #title>
<div>{{ t('views.trace.task.msisdnTip') }}</div>
</template>
<InfoCircleOutlined style="color: rgba(0, 0, 0, 0.45)" />
</a-tooltip>
</template>
</a-input>
</a-form-item>
<a-form-item
:label="t('views.trace.task.imsi')"
name="imsi"
v-bind="modalStateFrom.validateInfos.imsi"
>
<a-input
v-model:value="modalState.from.imsi"
allow-clear
:placeholder="t('views.trace.task.imsiPlease')"
>
<template #prefix>
<a-tooltip placement="topLeft">
<template #title>
<div>{{ t('views.trace.task.imsiTip') }}</div>
</template>
<InfoCircleOutlined style="color: rgba(0, 0, 0, 0.45)" />
</a-tooltip>
</template>
</a-input>
</a-form-item>
</template>
<!-- 接口跟踪 -->
<template v-if="modalState.from.traceType === 'Interface'">
<a-row :gutter="16">
<a-col :lg="12" :md="12" :xs="24">
<a-form-item
:label="t('views.trace.task.srcIp')"
name="srcIp"
v-bind="modalStateFrom.validateInfos.srcIp"
>
<a-input
v-model:value="modalState.from.srcIp"
allow-clear
placeholder="t('views.trace.task.srcIpPlease')"
>
<template #prefix>
<a-tooltip placement="topLeft">
<template #title>
<div>{{ t('views.trace.task.srcIpTip') }}</div>
</template>
<InfoCircleOutlined style="color: rgba(0, 0, 0, 0.45)" />
</a-tooltip>
</template>
</a-input>
</a-form-item>
</a-col>
<a-col :lg="12" :md="12" :xs="24">
<a-form-item
:label="t('views.trace.task.dstIp')"
name="dstIp"
v-bind="modalStateFrom.validateInfos.dstIp"
>
<a-input
v-model:value="modalState.from.dstIp"
allow-clear
:placeholder="t('views.trace.task.dstIpPlease')"
>
<template #prefix>
<a-tooltip placement="topLeft">
<template #title>
<div>{{ t('views.trace.task.dstIpTip') }}</div>
</template>
<InfoCircleOutlined style="color: rgba(0, 0, 0, 0.45)" />
</a-tooltip>
</template>
</a-input>
</a-form-item>
</a-col>
</a-row>
<a-form-item
:label="t('views.trace.task.interfaces')"
name="interfaces"
v-bind="modalStateFrom.validateInfos.interfaces"
>
<a-select
mode="multiple"
placeholder="Please select"
v-model:value="modalState.neTypeInterfaceSelect"
:options="modalState.neTypeInterface"
@change="fnSelectInterface"
>
</a-select>
</a-form-item>
<a-form-item
:label="t('views.trace.task.signalPort')"
name="signalPort"
v-bind="modalStateFrom.validateInfos.signalPort"
>
<a-input
v-model:value="modalState.from.signalPort"
allow-clear
:placeholder="t('views.trace.task.signalPortPlease')"
>
<template #prefix>
<a-tooltip placement="topLeft">
<template #title>
<div>t('views.trace.task.signalPortTip')</div>
</template>
<InfoCircleOutlined style="color: rgba(0, 0, 0, 0.45)" />
</a-tooltip>
</template>
</a-input>
</a-form-item>
</template>
<a-form-item
:label="t('views.trace.task.rangePicker')"
name="endTime"
v-bind="modalStateFrom.validateInfos.endTime"
>
<a-range-picker
v-model:value="modalState.timeRangePicker"
@change="fnRangePickerChange"
allow-clear
bordered
:show-time="{ format: 'HH:mm:ss' }"
format="YYYY-MM-DD HH:mm:ss"
value-format="YYYY-MM-DD HH:mm:ss"
:placeholder="[
t('views.trace.task.startTime'),
t('views.trace.task.endTime'),
]"
style="width: 100%"
></a-range-picker>
</a-form-item>
<a-form-item :label="t('views.trace.task.comment')" name="comment">
<a-textarea
v-model:value="modalState.from.comment"
:auto-size="{ minRows: 2, maxRows: 6 }"
:maxlength="250"
:show-count="true"
:placeholder="t('views.trace.task.commentPlease')"
/>
</a-form-item>
</a-form>
</a-modal>
</PageContainer>
</template>
<style lang="less" scoped>
.table :deep(.ant-pagination) {
padding: 0 24px;
}
</style>

View File

@@ -0,0 +1,432 @@
<script lang="ts" setup>
import { onMounted, reactive, toRaw } from 'vue';
import { PageContainer } from '@ant-design-vue/pro-layout';
import saveAs from 'file-saver';
import useNeInfoStore from '@/store/modules/neinfo';
import {
RESULT_CODE_ERROR,
RESULT_CODE_SUCCESS,
} from '@/constants/result-constants';
import useI18n from '@/hooks/useI18n';
import { message, Form } from 'ant-design-vue/lib';
import {
tcpdumpNeTask,
tcpdumpNeUPFTask,
tcpdumpPcapDownload,
} from '@/api/traceManage/pcap';
import { ref } from 'vue';
const { t } = useI18n();
/**对话框对象信息状态类型 */
type ModalStateType = {
/**网元类型 */
neType: string[];
/**表单数据 */
from: Record<string, any>;
/**确定按钮 loading */
confirmLoading: boolean;
/**执行日志 */
execLogMsg: string;
/**文件名 */
fileName: string;
/**下载文件按钮 */
downBtn: boolean;
};
/**对话框对象信息状态 */
let modalState: ModalStateType = reactive({
neType: [],
from: {
ip: '',
cmd: 'sctp or tcp port 8080 or 8088',
timeout: 60,
upfStart: 'pcap dispatch trace on max 100000',
upfStop: 'pcap dispatch trace off',
},
confirmLoading: false,
execLogMsg: '',
fileName: '',
downBtn: false,
});
/**网元类型选择对应修改 */
function fnNeChange(_: any, item: any) {
modalState.from.ip = item[1].ip;
modalState.execLogMsg = '';
modalState.fileName = '';
modalState.downBtn = false;
runTime.value = 0;
}
/**对话框内表单属性和校验规则 */
const modalStateFrom = Form.useForm(
modalState.from,
reactive({
cmd: [{ required: true, message: 'tcpdump any 参数!' }],
timeout: [{ required: true, message: '执行时长,单位是秒!' }],
upfStart: [{ required: true, message: 'upf start pacp 命令!' }],
upfStop: [{ required: true, message: 'upf stop pacp 命令!' }],
})
);
// 创建 AbortController 实例
let controller = new AbortController();
let timeoutId: any = 0;
let runTime = ref<number>(0);
/**普通抓包执行 */
function fnStart() {
modalStateFrom
.validate(['cmd', 'timeout'])
.then(() => {
modalState.confirmLoading = true;
const from = toRaw(modalState.from);
const hide = message.loading('正在执行...', 0);
controller = new AbortController();
const signal = controller.signal;
timeoutId = setInterval(() => {
runTime.value++;
if (runTime.value > from.timeout + 5) {
clearInterval(timeoutId);
runTime.value = 0;
message.warning({
content: `执行超时`,
duration: 2,
});
// 超时终止请求
controller.abort();
}
}, 1000);
tcpdumpNeTask(signal, {
neType: modalState.neType[0],
neId: modalState.neType[1],
timeout: from.timeout,
cmd: from.cmd,
})
.then(res => {
if (res.code === RESULT_CODE_SUCCESS) {
message.success({
content: `执行完成`,
duration: 3,
});
let logmsg = res.data.cmd + '\n\n' + res.data.msg;
logmsg = logmsg.replace(' \n', '\n\n');
modalState.execLogMsg = logmsg;
modalState.fileName = res.data.fileName;
modalState.downBtn = true;
} else if (
res.code === RESULT_CODE_ERROR &&
res.msg.includes('timeout')
) {
message.warning({
content: `中断执行`,
duration: 3,
});
} else {
message.error({
content: `执行失败`,
duration: 3,
});
}
})
.finally(() => {
hide();
clearInterval(timeoutId);
runTime.value = 0;
modalState.confirmLoading = false;
});
})
.catch(e => {
message.error(t('common.errorFields', { num: e.errorFields.length }), 3);
});
}
/**普通抓包中断 */
function fnStop() {
controller.abort(); // 终止请求
clearInterval(timeoutId);
runTime.value = 0;
}
/**下载PCAP文件 */
function fnDownPCAP() {
if (!modalState.fileName) {
message.warning({
content: `无效文件名`,
duration: 2,
});
return;
}
const key = 'tcpdumpPcapDownload';
message.loading({ content: '请稍等...', key });
tcpdumpPcapDownload({
neType: modalState.neType[0],
neId: modalState.neType[1],
fileName: modalState.fileName,
}).then(res => {
if (res.code === RESULT_CODE_SUCCESS) {
message.success({
content: `已完成`,
key,
duration: 2,
});
saveAs(res.data, modalState.fileName);
} else {
message.error({
content: `${res.msg}`,
key,
duration: 2,
});
}
});
}
/**UPF抓包执行 */
function fnUPF(runType: 'start' | 'stop') {
let validateArr = ['upfStop'];
if (runType === 'start') {
validateArr = ['upfStart'];
}
modalStateFrom
.validate(validateArr)
.then(() => {
modalState.confirmLoading = true;
const from = toRaw(modalState.from);
const hide = message.loading('请稍等...', 0);
tcpdumpNeUPFTask({
neType: modalState.neType[0],
neId: modalState.neType[1],
runType: runType,
cmd: from.upfStart,
})
.then(res => {
if (res.code === RESULT_CODE_SUCCESS) {
let logmsg = res.data.cmd + '\n\n' + res.data.msg;
logmsg = logmsg.replace(' \n', '\n\n');
modalState.execLogMsg = logmsg;
modalState.fileName = res.data.fileName;
if (runType === 'start') {
if (res.data.msg.includes('already')) {
message.warning({
content: `已经执行, 请根据情况停止抓包`,
duration: 10,
});
} else {
message.success({
content: `执行成功, 请根据情况停止抓包`,
duration: 10,
});
}
}
if (runType === 'stop') {
if (res.data.msg.includes('already')) {
message.warning({
content: `已经停止, 请根据情况开始抓包`,
duration: 10,
});
} else {
message.success({
content: `执行成功, 抓包已停止`,
duration: 10,
});
modalState.downBtn = true;
}
}
} else {
message.error({
content: `执行失败`,
duration: 3,
});
}
})
.finally(() => {
hide();
modalState.confirmLoading = false;
});
})
.catch(e => {
message.error(t('common.errorFields', { num: e.errorFields.length }), 3);
});
}
onMounted(() => {
// 获取网元网元列表
useNeInfoStore()
.fnNelist()
.then(res => {
if (res.code === RESULT_CODE_SUCCESS && Array.isArray(res.data)) {
if (res.data.length > 0) {
const info = res.data[0];
modalState.neType = [info.neType, info.neId];
modalState.from.ip = info.ip;
}
} else {
message.warning({
content: `暂无网元列表数据`,
duration: 2,
});
}
});
});
</script>
<template>
<PageContainer>
<a-card :title="t('views.trace.pcap.cardTitle')">
<a-row :gutter="16">
<a-col :lg="12" :md="12" :xs="24">
<a-form
name="modalState"
:model="modalState"
layout="horizontal"
autocomplete="off"
:label-col="{ span: 5 }"
labelWrap
>
<a-form-item :label="t('views.trace.pcap.neType')" name="neType">
<a-cascader
v-model:value="modalState.neType"
:options="useNeInfoStore().getNeCascaderOtions"
@change="fnNeChange"
:allow-clear="false"
placeholder="请选择网元"
/>
</a-form-item>
<a-form-item :label="t('views.trace.pcap.neIp')" name="ip">
<span style="font-weight: bold">{{ modalState.from.ip }}</span>
</a-form-item>
<template v-if="modalState.neType[0] === 'UPF'">
<a-form-item
:label="t('views.trace.pcap.capStart')"
name="upfStart"
v-bind="modalStateFrom.validateInfos.upfStart"
>
<a-input-group compact>
<a-input
v-model:value="modalState.from.upfStart"
allow-clear
placeholder="upf pacp 命令"
style="width: 75%"
/>
<a-button
type="primary"
style="width: 25%"
:disabled="modalState.confirmLoading"
:loading="modalState.confirmLoading"
@click.prevent="fnUPF('start')"
>
{{ t('views.trace.pcap.runText') }}
</a-button>
</a-input-group>
</a-form-item>
<a-form-item
:label="t('views.trace.pcap.capStop')"
name="upfStop"
v-bind="modalStateFrom.validateInfos.upfStop"
>
<a-input-group compact>
<a-input
v-model:value="modalState.from.upfStop"
allow-clear
placeholder="upf pacp 命令"
style="width: 75%"
/>
<a-button
type="primary"
style="width: 25%"
:disabled="modalState.confirmLoading"
:loading="modalState.confirmLoading"
@click.prevent="fnUPF('stop')"
>
{{ t('views.trace.pcap.runText') }}
</a-button>
</a-input-group>
</a-form-item>
</template>
<template v-else>
<a-form-item
:label="t('views.trace.pcap.capArg')"
name="cmd"
v-bind="modalStateFrom.validateInfos.cmd"
>
<a-input
v-model:value="modalState.from.cmd"
allow-clear
placeholder="tcpdump any 参数"
>
</a-input>
</a-form-item>
<a-form-item
:label="t('views.trace.pcap.capTime')"
name="timeout"
v-bind="modalStateFrom.validateInfos.timeout"
>
<a-input-number
v-model:value="modalState.from.timeout"
placeholder="单位是秒's"
:min="5"
:max="120"
/>
</a-form-item>
<a-form-item :wrapperCol="{ offset: 5 }">
<a-space :size="8">
<a-button
type="primary"
:disabled="modalState.confirmLoading"
:loading="modalState.confirmLoading"
@click.prevent="fnStart"
>
<template #icon><ApiOutlined /></template>
{{
runTime != 0
? t('views.trace.pcap.runTimeText', { s: runTime })
: t('views.trace.pcap.runText')
}}
</a-button>
<a-button
type="dashed"
danger
:disabled="!modalState.confirmLoading"
@click.prevent="fnStop"
>
{{ t('views.trace.pcap.stopText') }}
</a-button>
</a-space>
</a-form-item>
</template>
</a-form>
</a-col>
<a-col :offset="2" :lg="10" :md="10" :xs="24">
<a-form layout="vertical" autocomplete="off">
<a-form-item
:label="t('views.trace.pcap.capLog')"
name="execLogMsg"
v-show="!!modalState.execLogMsg"
>
<a-textarea
v-model:value="modalState.execLogMsg"
:auto-size="{ minRows: 10, maxRows: 15 }"
:disabled="true"
placeholder="输出执行日志..."
/>
</a-form-item>
<a-form-item v-show="modalState.downBtn">
<a-button
type="primary"
:title="modalState.fileName"
@click.prevent="fnDownPCAP"
>
<template #icon><DownloadOutlined /></template>
{{ t('views.trace.pcap.capDownText') }}
</a-button>
</a-form-item>
</a-form>
</a-col>
</a-row>
</a-card>
</PageContainer>
</template>
<style lang="less" scoped></style>

View File

@@ -0,0 +1,503 @@
<script setup lang="ts">
import { useRoute } from 'vue-router';
import { reactive, ref, onMounted, toRaw } from 'vue';
import { PageContainer } from '@ant-design-vue/pro-layout';
import { message, Modal } from 'ant-design-vue/lib';
import { SizeType } from 'ant-design-vue/lib/config-provider';
import { MenuInfo } from 'ant-design-vue/lib/menu/src/interface';
import { ColumnsType } from 'ant-design-vue/lib/table';
import { parseDateToStr } from '@/utils/date-utils';
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
import { saveAs } from 'file-saver';
import useI18n from '@/hooks/useI18n';
import { getTraceRawInfo, listTraceData } from '@/api/traceManage/analysis';
const { t } = useI18n();
const route = useRoute();
/**路由标题 */
let title = ref<string>((route.meta.title as string) ?? '标题');
/**查询参数 */
let queryParams = reactive({
/**移动号 */
imsi: '',
/**移动号 */
msisdn: '',
/**当前页数 */
pageNum: 1,
/**每页条数 */
pageSize: 20,
});
/**查询参数重置 */
function fnQueryReset() {
queryParams = Object.assign(queryParams, {
imsi: '',
pageNum: 1,
pageSize: 20,
});
tablePagination.current = 1;
tablePagination.pageSize = 20;
fnGetList();
}
/**表格状态类型 */
type TabeStateType = {
/**加载等待 */
loading: boolean;
/**紧凑型 */
size: SizeType;
/**搜索栏 */
seached: boolean;
/**记录数据 */
data: object[];
};
/**表格状态 */
let tableState: TabeStateType = reactive({
loading: false,
size: 'middle',
seached: true,
data: [],
});
/**表格字段列 */
let tableColumns: ColumnsType = [
{
title: t('views.trace.analysis.trackTaskId'),
dataIndex: 'taskId',
align: 'center',
},
{
title: t('views.trace.analysis.imsi'),
dataIndex: 'imsi',
align: 'center',
},
{
title: t('views.trace.analysis.msisdn'),
dataIndex: 'msisdn',
align: 'center',
},
{
title: t('views.trace.analysis.srcIp'),
dataIndex: 'srcAddr',
align: 'center',
},
{
title: t('views.trace.analysis.dstIp'),
dataIndex: 'dstAddr',
align: 'center',
},
{
title: t('views.trace.analysis.signalType'),
dataIndex: 'ifType',
align: 'center',
},
{
title: t('views.trace.analysis.msgType'),
dataIndex: 'msgType',
align: 'center',
},
{
title: t('views.trace.analysis.msgDirect'),
dataIndex: 'msgDirect',
align: 'center',
},
{
title: t('views.trace.analysis.rowTime'),
dataIndex: 'timestamp',
align: 'center',
customRender(opt) {
if (!opt.value) return '';
return parseDateToStr(opt.value);
},
},
{
title: t('common.operate'),
key: 'id',
align: 'center',
},
];
/**表格分页器参数 */
let tablePagination = reactive({
/**当前页数 */
current: 1,
/**每页条数 */
pageSize: 20,
/**默认的每页条数 */
defaultPageSize: 20,
/**指定每页可以显示多少条 */
pageSizeOptions: ['10', '20', '50', '100'],
/**只有一页时是否隐藏分页器 */
hideOnSinglePage: false,
/**是否可以快速跳转至某页 */
showQuickJumper: true,
/**是否可以改变 pageSize */
showSizeChanger: true,
/**数据总数 */
total: 0,
showTotal: (total: number) => t('common.tablePaginationTotal', { total }),
onChange: (page: number, pageSize: number) => {
tablePagination.current = page;
tablePagination.pageSize = pageSize;
queryParams.pageNum = page;
queryParams.pageSize = pageSize;
fnGetList();
},
});
/**表格紧凑型变更操作 */
function fnTableSize({ key }: MenuInfo) {
tableState.size = key as SizeType;
}
/**查询备份信息列表 */
function fnGetList() {
if (tableState.loading) return;
tableState.loading = true;
listTraceData(toRaw(queryParams)).then(res => {
console.log(res);
if (res.code === RESULT_CODE_SUCCESS && Array.isArray(res.rows)) {
tablePagination.total = res.total;
tableState.data = res.rows;
}
tableState.loading = false;
});
}
/**抽屉对象信息状态类型 */
type ModalStateType = {
/**抽屉框是否显示 */
visible: boolean;
/**标题 */
title: string;
/**表单数据 */
from: Record<string, any>;
};
/**抽屉对象信息状态 */
let modalState: ModalStateType = reactive({
visible: false,
title: '',
from: {
rawData: '',
rawDataHTML: '',
downBtn: false,
},
});
/**
* 对话框弹出显示
* @param row 记录信息
*/
function fnModalVisible(row: Record<string, any>) {
// 进制转数据
const hexString = parseBase64Data(row.rawMsg);
const rawData = convertToReadableFormat(hexString);
modalState.from.rawData = rawData;
// RAW解析HTML
getTraceRawInfo(row.id).then(res => {
if (res.code === RESULT_CODE_SUCCESS) {
const htmlString = res.msg;
// 删除所有 <a> 标签
const withoutATags = htmlString.replace(/<a\b[^>]*>(.*?)<\/a>/gi, '');
// 删除所有 <script> 标签
const withoutScriptTags = withoutATags.replace(
/<script\b[^>]*>([\s\S]*?)<\/script>/gi,
''
);
// 默认全展开
const withoutHiddenElements = withoutScriptTags.replace(
/style="display:none"/gi,
'style="background:#ffffff"'
);
modalState.from.rawDataHTML = withoutHiddenElements;
modalState.from.downBtn = true;
} else {
modalState.from.rawDataHTML = t('views.trace.analysis.noData');
}
});
modalState.title = t('views.trace.analysis.taskTitle', { num: row.imsi });
modalState.visible = true;
}
/**
* 对话框弹出关闭
*/
function fnModalVisibleClose() {
modalState.visible = false;
modalState.from.downBtn = false;
modalState.from.rawDataHTML = '';
modalState.from.rawData = '';
}
// 将Base64编码解码为字节数组
function parseBase64Data(hexData: string) {
// 将Base64编码解码为字节数组
const byteString = atob(hexData);
const byteArray = new Uint8Array(byteString.length);
for (let i = 0; i < byteString.length; i++) {
byteArray[i] = byteString.charCodeAt(i);
}
// 将每一个字节转换为2位16进制数表示并拼接起来
let hexString = '';
for (let i = 0; i < byteArray.length; i++) {
const hex = byteArray[i].toString(16);
hexString += hex.length === 1 ? '0' + hex : hex;
}
return hexString;
}
// 转换十六进制字节流为可读格式和ASCII码表示
function convertToReadableFormat(hexString: string) {
let result = '';
let asciiResult = '';
let arr = [];
let row = 100;
for (let i = 0; i < hexString.length; i += 2) {
const hexChars = hexString.substring(i, i + 2);
const decimal = parseInt(hexChars, 16);
const asciiChar =
decimal >= 32 && decimal <= 126 ? String.fromCharCode(decimal) : '.';
result += hexChars + ' ';
asciiResult += asciiChar;
if ((i + 2) % 32 === 0) {
arr.push({
row: row,
code: result,
asciiText: asciiResult,
});
result = '';
asciiResult = '';
row += 10;
}
if (2 + i == hexString.length) {
arr.push({
row: row,
code: result,
asciiText: asciiResult,
});
result = '';
asciiResult = '';
row += 10;
}
}
return arr;
}
/**信息文件下载 */
function fnDownloadFile() {
Modal.confirm({
title: t('common.tipTitle'),
content: t('views.trace.analysis.taskDownTip'),
onOk() {
const blob = new Blob([modalState.from.rawDataHTML], {
type: 'text/plain',
});
saveAs(blob, `${modalState.title}_${Date.now()}.html`);
},
});
}
onMounted(() => {
// 获取列表数据
fnGetList();
});
</script>
<template>
<PageContainer :title="title">
<a-card
v-show="tableState.seached"
:bordered="false"
:body-style="{ marginBottom: '24px', paddingBottom: 0 }"
>
<!-- 表格搜索栏 -->
<a-form :model="queryParams" name="queryParams" layout="horizontal">
<a-row :gutter="16">
<a-col :lg="6" :md="12" :xs="24">
<a-form-item
:placeholder="t('views.trace.analysis.imsi')"
name="imsi"
>
<a-input
v-model:value="queryParams.imsi"
:allow-clear="true"
:placeholder="t('views.trace.analysis.imsiPlease')"
></a-input>
</a-form-item>
</a-col>
<a-col :lg="6" :md="12" :xs="24">
<a-form-item
:placeholder="t('views.trace.analysis.msisdn')"
name="imsi"
>
<a-input
v-model:value="queryParams.msisdn"
:allow-clear="true"
:placeholder="t('views.trace.analysis.msisdnPlease')"
></a-input>
</a-form-item>
</a-col>
<a-col :lg="6" :md="12" :xs="24">
<a-form-item>
<a-space :size="8">
<a-button type="primary" @click.prevent="fnGetList">
<template #icon><SearchOutlined /></template>
{{ t('common.search') }}
</a-button>
<a-button type="default" @click.prevent="fnQueryReset">
<template #icon><ClearOutlined /></template>
{{ t('common.reset') }}
</a-button>
</a-space>
</a-form-item>
</a-col>
</a-row>
</a-form>
</a-card>
<a-card :bordered="false" :body-style="{ padding: '0px' }">
<!-- 插槽-卡片左侧侧 -->
<template #title> </template>
<!-- 插槽-卡片右侧 -->
<template #extra>
<a-space :size="8" align="center">
<a-tooltip>
<template #title>{{ t('common.searchBarText') }}</template>
<a-switch
v-model:checked="tableState.seached"
:checked-children="t('common.switch.show')"
:un-checked-children="t('common.switch.hide')"
size="small"
/>
</a-tooltip>
<a-tooltip>
<template #title>{{ t('common.reloadText') }}</template>
<a-button type="text" @click.prevent="fnGetList">
<template #icon><ReloadOutlined /></template>
</a-button>
</a-tooltip>
<a-tooltip>
<template #title>{{ t('common.sizeText') }}</template>
<a-dropdown trigger="click">
<a-button type="text">
<template #icon><ColumnHeightOutlined /></template>
</a-button>
<template #overlay>
<a-menu
:selected-keys="[tableState.size as string]"
@click="fnTableSize"
>
<a-menu-item key="default">{{
t('common.size.default')
}}</a-menu-item>
<a-menu-item key="middle">{{
t('common.size.middle')
}}</a-menu-item>
<a-menu-item key="small">{{
t('common.size.small')
}}</a-menu-item>
</a-menu>
</template>
</a-dropdown>
</a-tooltip>
</a-space>
</template>
<!-- 表格列表 -->
<a-table
class="table"
row-key="id"
:columns="tableColumns"
:loading="tableState.loading"
:data-source="tableState.data"
:size="tableState.size"
:pagination="tablePagination"
:scroll="{ x: true }"
>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'id'">
<a-space :size="8" align="center">
<a-tooltip>
<template #title>查看详情</template>
<a-button type="link" @click.prevent="fnModalVisible(record)">
<template #icon><ProfileOutlined /></template>
</a-button>
</a-tooltip>
</a-space>
</template>
</template>
</a-table>
</a-card>
<!-- 详情框 -->
<a-modal
width="800px"
:title="modalState.title"
:visible="modalState.visible"
@cancel="fnModalVisibleClose"
>
<div class="raw-title">{{ t('views.trace.analysis.signalData') }}</div>
<a-row
class="raw"
:gutter="16"
v-for="v in modalState.from.rawData"
:key="v.row"
>
<a-col class="num" :span="2">{{ v.row }}</a-col>
<a-col class="code" :span="12">{{ v.code }}</a-col>
<a-col class="txt" :span="10">{{ v.asciiText }}</a-col>
</a-row>
<a-divider />
<div class="raw-title">
{{ t('views.trace.analysis.signalDetail') }}
<a-button
type="dashed"
size="small"
@click.prevent="fnDownloadFile"
v-if="modalState.from.downBtn"
>
<template #icon>
<DownloadOutlined />
</template>
{{ t('views.trace.analysis.taskDownText') }}
</a-button>
</div>
<div class="raw-html" v-html="modalState.from.rawDataHTML"></div>
</a-modal>
</PageContainer>
</template>
<style lang="less" scoped>
.table :deep(.ant-pagination) {
padding: 0 24px;
}
.raw {
&-title {
color: #000000d9;
font-size: 24px;
line-height: 1.8;
}
.num {
background-color: #e5e5e5;
}
.code {
background-color: #e7e6ff;
}
.txt {
background-color: #ffe3e5;
}
&-html {
max-height: 300px;
overflow-y: scroll;
}
}
</style>

View File

@@ -0,0 +1,962 @@
<script setup lang="ts">
import { useRoute } from 'vue-router';
import { reactive, ref, onMounted, toRaw } from 'vue';
import { PageContainer } from '@ant-design-vue/pro-layout';
import { Form, message, Modal } from 'ant-design-vue/lib';
import { SizeType } from 'ant-design-vue/lib/config-provider';
import { MenuInfo } from 'ant-design-vue/lib/menu/src/interface';
import { ColumnsType } from 'ant-design-vue/lib/table';
import { parseDateToStr } from '@/utils/date-utils';
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
import useI18n from '@/hooks/useI18n';
import useUserStore from '@/store/modules/user';
import useNeInfoStore from '@/store/modules/neinfo';
import {
addTraceTask,
delTraceTask,
getTraceTask,
listTraceTask,
updateTraceTask,
} from '@/api/traceManage/task';
import useDictStore from '@/store/modules/dict';
import { regExpIPv4, regExpPort } from '@/utils/regular-utils';
const { getDict } = useDictStore();
const { t } = useI18n();
const route = useRoute();
/**路由标题 */
let title = ref<string>((route.meta.title as string) ?? '标题');
/**字典数据 */
let dict: {
/**跟踪类型 */
traceType: DictType[];
} = reactive({
traceType: [],
});
/**查询参数 */
let queryParams = reactive({
/**网元类型 */
neType: '',
/**当前页数 */
pageNum: 1,
/**每页条数 */
pageSize: 20,
});
/**查询参数重置 */
function fnQueryReset() {
queryParams = Object.assign(queryParams, {
neType: '',
pageNum: 1,
pageSize: 20,
});
tablePagination.current = 1;
tablePagination.pageSize = 20;
fnGetList();
}
/**表格状态类型 */
type TabeStateType = {
/**加载等待 */
loading: boolean;
/**紧凑型 */
size: SizeType;
/**搜索栏 */
seached: boolean;
/**记录数据 */
data: object[];
/**勾选记录 */
selectedRowKeys: (string | number)[];
};
/**表格状态 */
let tableState: TabeStateType = reactive({
loading: false,
size: 'middle',
seached: true,
data: [],
selectedRowKeys: [],
});
/**表格字段列 */
let tableColumns: ColumnsType = [
{
title: t('common.rowId'),
dataIndex: 'id',
align: 'center',
},
{
title: t('views.trace.task.neType'),
dataIndex: 'neType',
align: 'center',
},
{
title: t('views.trace.task.neID'),
dataIndex: 'neId',
align: 'center',
},
{
title: t('views.trace.task.trackType'),
dataIndex: 'traceType',
key: 'traceType',
align: 'center',
},
{
title: t('views.trace.task.trackType'),
dataIndex: 'accountId',
align: 'center',
},
{
title: t('views.trace.task.startTime'),
dataIndex: 'startTime',
align: 'center',
customRender(opt) {
if (!opt.value) return '';
return parseDateToStr(opt.value);
},
},
{
title: t('views.trace.task.endTime'),
dataIndex: 'endTime',
align: 'center',
customRender(opt) {
if (!opt.value) return '';
return parseDateToStr(opt.value);
},
},
{
title: t('common.operate'),
key: 'id',
align: 'center',
},
];
/**表格分页器参数 */
let tablePagination = reactive({
/**当前页数 */
current: 1,
/**每页条数 */
pageSize: 20,
/**默认的每页条数 */
defaultPageSize: 20,
/**指定每页可以显示多少条 */
pageSizeOptions: ['10', '20', '50', '100'],
/**只有一页时是否隐藏分页器 */
hideOnSinglePage: false,
/**是否可以快速跳转至某页 */
showQuickJumper: true,
/**是否可以改变 pageSize */
showSizeChanger: true,
/**数据总数 */
total: 0,
showTotal: (total: number) => t('common.tablePaginationTotal', { total }),
onChange: (page: number, pageSize: number) => {
tablePagination.current = page;
tablePagination.pageSize = pageSize;
queryParams.pageNum = page;
queryParams.pageSize = pageSize;
fnGetList();
},
});
/**表格紧凑型变更操作 */
function fnTableSize({ key }: MenuInfo) {
tableState.size = key as SizeType;
}
/**
* 备份信息删除
* @param row 记录编号ID
*/
function fnRecordDelete(id: string) {
Modal.confirm({
title: t('views.trace.task.tipTitle'),
content: t('views.trace.task.delTaskTip', { num: id }),
onOk() {
const key = 'delTraceTask';
message.loading({ content: t('common.loading'), key });
delTraceTask(id).then(res => {
if (res.code === RESULT_CODE_SUCCESS) {
message.success({
content: t('views.trace.task.delTask', { num: id }),
key,
duration: 2,
});
fnGetList();
} else {
message.error({
content: `${res.msg}`,
key: key,
duration: 2,
});
}
});
},
});
}
/**查询信息列表 */
function fnGetList() {
if (tableState.loading) return;
tableState.loading = true;
listTraceTask(toRaw(queryParams)).then(res => {
if (res.code === RESULT_CODE_SUCCESS && Array.isArray(res.rows)) {
// 取消勾选
if (tableState.selectedRowKeys.length > 0) {
tableState.selectedRowKeys = [];
}
tablePagination.total = res.total;
tableState.data = res.rows;
}
tableState.loading = false;
});
}
/**对话框对象信息状态类型 */
type ModalStateType = {
/**详情框是否显示 */
visibleByView: boolean;
/**新增框或修改框是否显示 */
visibleByEdit: boolean;
/**标题 */
title: string;
/**网元类型设备对象 */
neType: string[];
/**网元类型设备对象接口 */
neTypeInterface: Record<string, any>[];
/**网元类型设备对象接口选择 */
neTypeInterfaceSelect: string[];
/**任务开始结束时间 */
timeRangePicker: [string, string];
/**表单数据 */
from: Record<string, any>;
/**确定按钮 loading */
confirmLoading: boolean;
};
/**对话框对象信息状态 */
let modalState: ModalStateType = reactive({
visibleByView: false,
visibleByEdit: false,
title: '',
neType: [],
neTypeInterface: [],
neTypeInterfaceSelect: [],
timeRangePicker: ['', ''],
from: {
id: '',
neType: '',
neId: '',
traceType: 'Device',
startTime: '',
endTime: '',
comment: '',
// 跟踪类型用户
imsi: '',
msisdn: '',
// 跟踪类型接口
srcIp: '',
dstIp: '',
interfaces: '',
signalPort: '',
},
confirmLoading: false,
});
/**对话框内表单属性和校验规则 */
const modalStateFrom = Form.useForm(
modalState.from,
reactive({
traceType: [
{
required: true,
message: t('views.trace.task.trackTypePlease'),
},
],
neId: [
{
required: true,
message: t('views.trace.task.neTypePlease'),
},
],
endTime: [
{
required: true,
message: t('views.trace.task.rangePickerPlease'),
},
],
// 跟踪用户
imsi: [
{
required: true,
message: t('views.trace.task.imsiPlease'),
},
],
msisdn: [
{
required: true,
message: t('views.trace.task.msisdnPlease'),
},
],
// 跟踪接口
srcIp: [
{
required: true,
pattern: regExpIPv4,
message: t('views.trace.task.srcIpPlease'),
},
],
dstIp: [
{
required: true,
pattern: regExpIPv4,
message: t('views.trace.task.dstIpPlease'),
},
],
interfaces: [
{
required: true,
message: t('views.trace.task.interfacesPlease'),
},
],
signalPort: [
{
required: true,
pattern: regExpPort,
message: t('views.trace.task.signalPortPlease'),
},
],
})
);
/**网元类型选择对应修改 */
function fnNeChange(_: any, item: any) {
modalState.from.neType = item[1].neType;
modalState.from.neId = item[1].neId;
modalState.from.interfaces = '';
modalState.neTypeInterfaceSelect = [];
if (modalState.from.traceType !== 'Interface') return;
// 网元信令接口
fnSelectInterfaceInit(item[1].neType);
}
/**开始结束时间选择对应修改 */
function fnRangePickerChange(_: any, item: any) {
modalState.from.startTime = item[0];
modalState.from.endTime = item[1];
}
/**信令接口选择对应修改 */
function fnSelectInterface(s: any, _: any) {
modalState.from.interfaces = s.join(',');
}
/**信令接口选择初始 */
function fnSelectInterfaceInit(neType: string) {
const interfaces = useNeInfoStore().traceInterfaceList;
modalState.neTypeInterface = interfaces
.filter(i => i.neType === neType)
.map(i => {
return {
value: i.interface,
label: i.interface,
};
});
}
/**
* 对话框弹出显示为 新增或者修改
* @param noticeId 网元id, 不传为新增
*/
function fnModalVisibleByVive(id: string) {
if (modalState.confirmLoading) return;
const hide = message.loading(t('common.loading'), 0);
modalState.confirmLoading = true;
getTraceTask(id).then(res => {
modalState.confirmLoading = false;
hide();
if (res.code === RESULT_CODE_SUCCESS) {
modalState.neType = [res.data.neType, res.data.neId];
modalState.timeRangePicker = [res.data.startTime, res.data.endTime];
modalState.from = Object.assign(modalState.from, res.data);
// 接口
if (res.data.traceType === 'Interface') {
if (
res.data.interfaces.length > 4 &&
res.data.interfaces.includes('[')
) {
modalState.neTypeInterfaceSelect = JSON.parse(res.data.interfaces);
}
fnSelectInterfaceInit(res.data.neType);
}
modalState.title = t('views.trace.task.viewTask');
modalState.visibleByView = true;
} else {
message.error(t('views.trace.task.errorTaskInfo'), 3);
}
});
}
/**
* 对话框弹出显示为 新增或者修改
* @param noticeId 网元id, 不传为新增
*/
function fnModalVisibleByEdit(id?: string) {
if (!id) {
modalStateFrom.resetFields();
modalState.title = t('views.trace.task.addTask');
modalState.visibleByEdit = true;
} else {
if (modalState.confirmLoading) return;
const hide = message.loading(t('common.loading'), 0);
modalState.confirmLoading = true;
getTraceTask(id).then(res => {
modalState.confirmLoading = false;
hide();
if (res.code === RESULT_CODE_SUCCESS && res.data) {
modalState.neType = [res.data.neType, res.data.neId];
modalState.timeRangePicker = [res.data.startTime, res.data.endTime];
modalState.from = Object.assign(modalState.from, res.data);
// 接口
if (res.data.traceType === 'Interface') {
if (
res.data.interfaces.length > 4 &&
res.data.interfaces.includes('[')
) {
modalState.neTypeInterfaceSelect = JSON.parse(res.data.interfaces);
}
fnSelectInterfaceInit(res.data.neType);
}
modalState.title = t('views.trace.task.editTask');
modalState.visibleByEdit = true;
} else {
message.error(t('views.trace.task.errorTaskInfo'), 3);
}
});
}
}
/**
* 对话框弹出确认执行函数
* 进行表达规则校验
*/
function fnModalOk() {
const from = toRaw(modalState.from);
let valids = ['traceType', 'neId', 'endTime'];
if (from.traceType === 'UE') {
valids = valids.concat(['imsi', 'msisdn']);
}
if (from.traceType === 'Interface') {
valids = valids.concat(['srcIp', 'dstIp', 'interfaces', 'signalPort']);
}
from.accountId = useUserStore().userName;
modalStateFrom
.validate(valids)
.then(e => {
modalState.confirmLoading = true;
const traceTask = from.id ? updateTraceTask(from) : addTraceTask(from);
const hide = message.loading(t('common.loading'), 0);
traceTask
.then(res => {
console.log(res);
if (res.code === RESULT_CODE_SUCCESS) {
message.success({
content: t('common.msgSuccess', { msg: modalState.title }),
duration: 3,
});
modalState.visibleByEdit = false;
modalStateFrom.resetFields();
} else {
message.error({
content: `${res.msg}`,
duration: 3,
});
}
})
.finally(() => {
hide();
modalState.confirmLoading = false;
fnGetList();
});
})
.catch(e => {
message.error(t('common.errorFields', { num: e.errorFields.length }), 3);
});
}
/**
* 对话框弹出关闭执行函数
* 进行表达规则校验
*/
function fnModalCancel() {
modalState.visibleByView = false;
modalState.visibleByEdit = false;
modalState.confirmLoading = false;
modalStateFrom.resetFields();
modalState.timeRangePicker = ['', ''];
modalState.neTypeInterfaceSelect = [];
modalState.neType = [];
modalState.neTypeInterface = [];
}
onMounted(() => {
// 初始字典数据
Promise.allSettled([getDict('trace_type')]).then(resArr => {
if (resArr[0].status === 'fulfilled') {
dict.traceType = resArr[0].value;
}
});
Promise.allSettled([
// 获取网元网元列表
useNeInfoStore().fnNelist(),
// 获取跟踪接口列表
useNeInfoStore().fnNeTraceInterface(),
]).finally(() => {
// 获取列表数据
fnGetList();
});
});
</script>
<template>
<PageContainer :title="title">
<a-card
v-show="tableState.seached"
:bordered="false"
:body-style="{ marginBottom: '24px', paddingBottom: 0 }"
>
<!-- 表格搜索栏 -->
<a-form :model="queryParams" name="queryParams" layout="horizontal">
<a-row :gutter="16">
<a-col :lg="6" :md="12" :xs="24">
<a-form-item :label="t('views.trace.task.neType')" name="neType ">
<a-auto-complete
v-model:value="queryParams.neType"
:options="useNeInfoStore().getNeSelectOtions"
allow-clear
:placeholder="t('views.trace.task.neTypePlease')"
/>
</a-form-item>
</a-col>
<a-col :lg="6" :md="12" :xs="24">
<a-form-item>
<a-space :size="8">
<a-button type="primary" @click.prevent="fnGetList">
<template #icon><SearchOutlined /></template>
{{ t('common.search') }}
</a-button>
<a-button type="default" @click.prevent="fnQueryReset">
<template #icon><ClearOutlined /></template>
{{ t('common.reset') }}
</a-button>
</a-space>
</a-form-item>
</a-col>
</a-row>
</a-form>
</a-card>
<a-card :bordered="false" :body-style="{ padding: '0px' }">
<!-- 插槽-卡片左侧侧 -->
<template #title>
<a-button type="primary" @click.prevent="fnModalVisibleByEdit()">
<template #icon><PlusOutlined /></template>
{{ t('common.addText') }}
</a-button>
</template>
<!-- 插槽-卡片右侧 -->
<template #extra>
<a-space :size="8" align="center">
<a-tooltip placement="topRight">
<template #title>{{ t('common.searchBarText') }}</template>
<a-switch
v-model:checked="tableState.seached"
:checked-children="t('common.switch.show')"
:un-checked-children="t('common.switch.hide')"
size="small"
/>
</a-tooltip>
<a-tooltip placement="topRight">
<template #title>{{ t('common.reloadText') }}</template>
<a-button type="text" @click.prevent="fnGetList">
<template #icon><ReloadOutlined /></template>
</a-button>
</a-tooltip>
<a-tooltip placement="topRight">
<template #title>{{ t('common.sizeText') }}</template>
<a-dropdown trigger="click" placement="bottomRight">
<a-button type="text">
<template #icon><ColumnHeightOutlined /></template>
</a-button>
<template #overlay>
<a-menu
:selected-keys="[tableState.size as string]"
@click="fnTableSize"
>
<a-menu-item key="default">{{
t('common.size.default')
}}</a-menu-item>
<a-menu-item key="middle">{{
t('common.size.middle')
}}</a-menu-item>
<a-menu-item key="small">{{
t('common.size.small')
}}</a-menu-item>
</a-menu>
</template>
</a-dropdown>
</a-tooltip>
</a-space>
</template>
<!-- 表格列表 -->
<a-table
class="table"
row-key="id"
:columns="tableColumns"
:loading="tableState.loading"
:data-source="tableState.data"
:size="tableState.size"
:pagination="tablePagination"
:scroll="{ x: true }"
>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'traceType'">
<DictTag :options="dict.traceType" :value="record.traceType" />
</template>
<template v-if="column.key === 'id'">
<a-space :size="8" align="center">
<a-tooltip>
<template #title>{{ t('common.viewText') }}</template>
<a-button
type="link"
@click.prevent="fnModalVisibleByVive(record.id)"
>
<template #icon><ProfileOutlined /></template>
</a-button>
</a-tooltip>
<a-tooltip>
<template #title>{{ t('common.editText') }}</template>
<a-button
type="link"
@click.prevent="fnModalVisibleByEdit(record.id)"
>
<template #icon><FormOutlined /></template>
</a-button>
</a-tooltip>
<a-tooltip>
<template #title>{{ t('common.deleteText') }}</template>
<a-button
type="link"
@click.prevent="fnRecordDelete(record.id)"
>
<template #icon><DeleteOutlined /></template>
</a-button>
</a-tooltip>
</a-space>
</template>
</template>
</a-table>
</a-card>
<!-- 详情框 -->
<a-modal
width="800px"
:visible="modalState.visibleByView"
:title="modalState.title"
@cancel="fnModalCancel"
>
<a-form layout="horizontal">
<a-row :gutter="16">
<a-col :lg="12" :md="12" :xs="24">
<a-form-item
:label="t('views.trace.task.trackType')"
name="traceType"
>
<DictTag
:options="dict.traceType"
:value="modalState.from.traceType"
/>
</a-form-item>
</a-col>
<a-col :lg="12" :md="12" :xs="24">
<a-form-item :label="t('views.trace.task.neType')" name="neType">
<a-cascader
:value="modalState.neType"
:options="useNeInfoStore().getNeCascaderOtions"
disabled
/>
</a-form-item>
</a-col>
</a-row>
<!-- 用户跟踪 -->
<template v-if="modalState.from.traceType === 'UE'">
<a-form-item :label="t('views.trace.task.msisdn')" name="msisdn">
{{ modalState.from.msisdn }}
</a-form-item>
<a-form-item :label="t('views.trace.task.imsi')" name="imsi">
{{ modalState.from.imsi }}
</a-form-item>
</template>
<!-- 接口跟踪 -->
<template v-if="modalState.from.traceType === 'Interface'">
<a-row :gutter="16">
<a-col :lg="12" :md="12" :xs="24">
<a-form-item :label="t('views.trace.task.srcIp')" name="srcIp">
{{ modalState.from.srcIp }}
</a-form-item>
</a-col>
<a-col :lg="12" :md="12" :xs="24">
<a-form-item :label="t('views.trace.task.dstIp')" name="dstIp">
{{ modalState.from.dstIp }}
</a-form-item>
</a-col>
</a-row>
<a-form-item :label="t('views.trace.task.interfaces')" name="endTime">
{{ modalState.neTypeInterfaceSelect }}
</a-form-item>
<a-form-item :label="t('views.trace.task.signalPort')" name="endTime">
{{ modalState.from.signalPort }}
</a-form-item>
</template>
<a-form-item :label="t('views.trace.task.rangePicker')" name="endTime">
<a-range-picker
disabled
:value="modalState.timeRangePicker"
allow-clear
bordered
:show-time="{ format: 'HH:mm:ss' }"
format="YYYY-MM-DD HH:mm:ss"
value-format="YYYY-MM-DD HH:mm:ss"
style="width: 100%"
></a-range-picker>
</a-form-item>
<a-form-item :label="t('views.trace.task.comment')" name="comment">
{{ modalState.from.comment }}
</a-form-item>
</a-form>
<template #footer>
<a-button key="cancel" @click="fnModalCancel">{{
t('common.close')
}}</a-button>
</template>
</a-modal>
<!-- 新增框或修改框 -->
<a-modal
width="800px"
:keyboard="false"
:mask-closable="false"
:visible="modalState.visibleByEdit"
:title="modalState.title"
:confirm-loading="modalState.confirmLoading"
@ok="fnModalOk"
@cancel="fnModalCancel"
>
<a-form name="modalStateFrom" layout="horizontal">
<a-row :gutter="16">
<a-col :lg="12" :md="12" :xs="24">
<a-form-item
:label="t('views.trace.task.trackType')"
name="traceType"
v-bind="modalStateFrom.validateInfos.traceType"
>
<a-select
v-model:value="modalState.from.traceType"
:placeholder="t('views.trace.task.trackTypePlease')"
:options="dict.traceType"
>
</a-select>
</a-form-item>
</a-col>
<a-col :lg="12" :md="12" :xs="24">
<a-form-item
:label="t('views.trace.task.neType')"
name="neType"
v-bind="modalStateFrom.validateInfos.neId"
>
<a-cascader
v-model:value="modalState.neType"
:options="useNeInfoStore().getNeCascaderOtions"
@change="fnNeChange"
:allow-clear="false"
:placeholder="t('views.trace.task.neTypePlease')"
/>
</a-form-item>
</a-col>
</a-row>
<!-- 用户跟踪 -->
<template v-if="modalState.from.traceType === 'UE'">
<a-form-item
:label="t('views.trace.task.msisdn')"
name="msisdn"
v-bind="modalStateFrom.validateInfos.msisdn"
>
<a-input
v-model:value="modalState.from.msisdn"
allow-clear
:placeholder="t('views.trace.task.msisdnPlease')"
>
<template #prefix>
<a-tooltip placement="topLeft">
<template #title>
<div>{{ t('views.trace.task.msisdnTip') }}</div>
</template>
<InfoCircleOutlined style="color: rgba(0, 0, 0, 0.45)" />
</a-tooltip>
</template>
</a-input>
</a-form-item>
<a-form-item
:label="t('views.trace.task.imsi')"
name="imsi"
v-bind="modalStateFrom.validateInfos.imsi"
>
<a-input
v-model:value="modalState.from.imsi"
allow-clear
:placeholder="t('views.trace.task.imsiPlease')"
>
<template #prefix>
<a-tooltip placement="topLeft">
<template #title>
<div>{{ t('views.trace.task.imsiTip') }}</div>
</template>
<InfoCircleOutlined style="color: rgba(0, 0, 0, 0.45)" />
</a-tooltip>
</template>
</a-input>
</a-form-item>
</template>
<!-- 接口跟踪 -->
<template v-if="modalState.from.traceType === 'Interface'">
<a-row :gutter="16">
<a-col :lg="12" :md="12" :xs="24">
<a-form-item
:label="t('views.trace.task.srcIp')"
name="srcIp"
v-bind="modalStateFrom.validateInfos.srcIp"
>
<a-input
v-model:value="modalState.from.srcIp"
allow-clear
placeholder="t('views.trace.task.srcIpPlease')"
>
<template #prefix>
<a-tooltip placement="topLeft">
<template #title>
<div>{{ t('views.trace.task.srcIpTip') }}</div>
</template>
<InfoCircleOutlined style="color: rgba(0, 0, 0, 0.45)" />
</a-tooltip>
</template>
</a-input>
</a-form-item>
</a-col>
<a-col :lg="12" :md="12" :xs="24">
<a-form-item
:label="t('views.trace.task.dstIp')"
name="dstIp"
v-bind="modalStateFrom.validateInfos.dstIp"
>
<a-input
v-model:value="modalState.from.dstIp"
allow-clear
:placeholder="t('views.trace.task.dstIpPlease')"
>
<template #prefix>
<a-tooltip placement="topLeft">
<template #title>
<div>{{ t('views.trace.task.dstIpTip') }}</div>
</template>
<InfoCircleOutlined style="color: rgba(0, 0, 0, 0.45)" />
</a-tooltip>
</template>
</a-input>
</a-form-item>
</a-col>
</a-row>
<a-form-item
:label="t('views.trace.task.interfaces')"
name="interfaces"
v-bind="modalStateFrom.validateInfos.interfaces"
>
<a-select
mode="multiple"
placeholder="Please select"
v-model:value="modalState.neTypeInterfaceSelect"
:options="modalState.neTypeInterface"
@change="fnSelectInterface"
>
</a-select>
</a-form-item>
<a-form-item
:label="t('views.trace.task.signalPort')"
name="signalPort"
v-bind="modalStateFrom.validateInfos.signalPort"
>
<a-input
v-model:value="modalState.from.signalPort"
allow-clear
:placeholder="t('views.trace.task.signalPortPlease')"
>
<template #prefix>
<a-tooltip placement="topLeft">
<template #title>
<div>t('views.trace.task.signalPortTip')</div>
</template>
<InfoCircleOutlined style="color: rgba(0, 0, 0, 0.45)" />
</a-tooltip>
</template>
</a-input>
</a-form-item>
</template>
<a-form-item
:label="t('views.trace.task.rangePicker')"
name="endTime"
v-bind="modalStateFrom.validateInfos.endTime"
>
<a-range-picker
v-model:value="modalState.timeRangePicker"
@change="fnRangePickerChange"
allow-clear
bordered
:show-time="{ format: 'HH:mm:ss' }"
format="YYYY-MM-DD HH:mm:ss"
value-format="YYYY-MM-DD HH:mm:ss"
:placeholder="[
t('views.trace.task.startTime'),
t('views.trace.task.endTime'),
]"
style="width: 100%"
></a-range-picker>
</a-form-item>
<a-form-item :label="t('views.trace.task.comment')" name="comment">
<a-textarea
v-model:value="modalState.from.comment"
:auto-size="{ minRows: 2, maxRows: 6 }"
:maxlength="250"
:show-count="true"
:placeholder="t('views.trace.task.commentPlease')"
/>
</a-form-item>
</a-form>
</a-modal>
</PageContainer>
</template>
<style lang="less" scoped>
.table :deep(.ant-pagination) {
padding: 0 24px;
}
</style>

View File

@@ -0,0 +1,503 @@
<script setup lang="ts">
import { useRoute } from 'vue-router';
import { reactive, ref, onMounted, toRaw } from 'vue';
import { PageContainer } from '@ant-design-vue/pro-layout';
import { message, Modal } from 'ant-design-vue/lib';
import { SizeType } from 'ant-design-vue/lib/config-provider';
import { MenuInfo } from 'ant-design-vue/lib/menu/src/interface';
import { ColumnsType } from 'ant-design-vue/lib/table';
import { parseDateToStr } from '@/utils/date-utils';
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
import { saveAs } from 'file-saver';
import useI18n from '@/hooks/useI18n';
import { getTraceRawInfo, listTraceData } from '@/api/traceManage/analysis';
const { t } = useI18n();
const route = useRoute();
/**路由标题 */
let title = ref<string>((route.meta.title as string) ?? '标题');
/**查询参数 */
let queryParams = reactive({
/**移动号 */
imsi: '',
/**移动号 */
msisdn: '',
/**当前页数 */
pageNum: 1,
/**每页条数 */
pageSize: 20,
});
/**查询参数重置 */
function fnQueryReset() {
queryParams = Object.assign(queryParams, {
imsi: '',
pageNum: 1,
pageSize: 20,
});
tablePagination.current = 1;
tablePagination.pageSize = 20;
fnGetList();
}
/**表格状态类型 */
type TabeStateType = {
/**加载等待 */
loading: boolean;
/**紧凑型 */
size: SizeType;
/**搜索栏 */
seached: boolean;
/**记录数据 */
data: object[];
};
/**表格状态 */
let tableState: TabeStateType = reactive({
loading: false,
size: 'middle',
seached: true,
data: [],
});
/**表格字段列 */
let tableColumns: ColumnsType = [
{
title: t('views.trace.analysis.trackTaskId'),
dataIndex: 'taskId',
align: 'center',
},
{
title: t('views.trace.analysis.imsi'),
dataIndex: 'imsi',
align: 'center',
},
{
title: t('views.trace.analysis.msisdn'),
dataIndex: 'msisdn',
align: 'center',
},
{
title: t('views.trace.analysis.srcIp'),
dataIndex: 'srcAddr',
align: 'center',
},
{
title: t('views.trace.analysis.dstIp'),
dataIndex: 'dstAddr',
align: 'center',
},
{
title: t('views.trace.analysis.signalType'),
dataIndex: 'ifType',
align: 'center',
},
{
title: t('views.trace.analysis.msgType'),
dataIndex: 'msgType',
align: 'center',
},
{
title: t('views.trace.analysis.msgDirect'),
dataIndex: 'msgDirect',
align: 'center',
},
{
title: t('views.trace.analysis.rowTime'),
dataIndex: 'timestamp',
align: 'center',
customRender(opt) {
if (!opt.value) return '';
return parseDateToStr(opt.value);
},
},
{
title: t('common.operate'),
key: 'id',
align: 'center',
},
];
/**表格分页器参数 */
let tablePagination = reactive({
/**当前页数 */
current: 1,
/**每页条数 */
pageSize: 20,
/**默认的每页条数 */
defaultPageSize: 20,
/**指定每页可以显示多少条 */
pageSizeOptions: ['10', '20', '50', '100'],
/**只有一页时是否隐藏分页器 */
hideOnSinglePage: false,
/**是否可以快速跳转至某页 */
showQuickJumper: true,
/**是否可以改变 pageSize */
showSizeChanger: true,
/**数据总数 */
total: 0,
showTotal: (total: number) => t('common.tablePaginationTotal', { total }),
onChange: (page: number, pageSize: number) => {
tablePagination.current = page;
tablePagination.pageSize = pageSize;
queryParams.pageNum = page;
queryParams.pageSize = pageSize;
fnGetList();
},
});
/**表格紧凑型变更操作 */
function fnTableSize({ key }: MenuInfo) {
tableState.size = key as SizeType;
}
/**查询备份信息列表 */
function fnGetList() {
if (tableState.loading) return;
tableState.loading = true;
listTraceData(toRaw(queryParams)).then(res => {
console.log(res);
if (res.code === RESULT_CODE_SUCCESS && Array.isArray(res.rows)) {
tablePagination.total = res.total;
tableState.data = res.rows;
}
tableState.loading = false;
});
}
/**抽屉对象信息状态类型 */
type ModalStateType = {
/**抽屉框是否显示 */
visible: boolean;
/**标题 */
title: string;
/**表单数据 */
from: Record<string, any>;
};
/**抽屉对象信息状态 */
let modalState: ModalStateType = reactive({
visible: false,
title: '',
from: {
rawData: '',
rawDataHTML: '',
downBtn: false,
},
});
/**
* 对话框弹出显示
* @param row 记录信息
*/
function fnModalVisible(row: Record<string, any>) {
// 进制转数据
const hexString = parseBase64Data(row.rawMsg);
const rawData = convertToReadableFormat(hexString);
modalState.from.rawData = rawData;
// RAW解析HTML
getTraceRawInfo(row.id).then(res => {
if (res.code === RESULT_CODE_SUCCESS) {
const htmlString = res.msg;
// 删除所有 <a> 标签
const withoutATags = htmlString.replace(/<a\b[^>]*>(.*?)<\/a>/gi, '');
// 删除所有 <script> 标签
const withoutScriptTags = withoutATags.replace(
/<script\b[^>]*>([\s\S]*?)<\/script>/gi,
''
);
// 默认全展开
const withoutHiddenElements = withoutScriptTags.replace(
/style="display:none"/gi,
'style="background:#ffffff"'
);
modalState.from.rawDataHTML = withoutHiddenElements;
modalState.from.downBtn = true;
} else {
modalState.from.rawDataHTML = t('views.trace.analysis.noData');
}
});
modalState.title = t('views.trace.analysis.taskTitle', { num: row.imsi });
modalState.visible = true;
}
/**
* 对话框弹出关闭
*/
function fnModalVisibleClose() {
modalState.visible = false;
modalState.from.downBtn = false;
modalState.from.rawDataHTML = '';
modalState.from.rawData = '';
}
// 将Base64编码解码为字节数组
function parseBase64Data(hexData: string) {
// 将Base64编码解码为字节数组
const byteString = atob(hexData);
const byteArray = new Uint8Array(byteString.length);
for (let i = 0; i < byteString.length; i++) {
byteArray[i] = byteString.charCodeAt(i);
}
// 将每一个字节转换为2位16进制数表示并拼接起来
let hexString = '';
for (let i = 0; i < byteArray.length; i++) {
const hex = byteArray[i].toString(16);
hexString += hex.length === 1 ? '0' + hex : hex;
}
return hexString;
}
// 转换十六进制字节流为可读格式和ASCII码表示
function convertToReadableFormat(hexString: string) {
let result = '';
let asciiResult = '';
let arr = [];
let row = 100;
for (let i = 0; i < hexString.length; i += 2) {
const hexChars = hexString.substring(i, i + 2);
const decimal = parseInt(hexChars, 16);
const asciiChar =
decimal >= 32 && decimal <= 126 ? String.fromCharCode(decimal) : '.';
result += hexChars + ' ';
asciiResult += asciiChar;
if ((i + 2) % 32 === 0) {
arr.push({
row: row,
code: result,
asciiText: asciiResult,
});
result = '';
asciiResult = '';
row += 10;
}
if (2 + i == hexString.length) {
arr.push({
row: row,
code: result,
asciiText: asciiResult,
});
result = '';
asciiResult = '';
row += 10;
}
}
return arr;
}
/**信息文件下载 */
function fnDownloadFile() {
Modal.confirm({
title: t('common.tipTitle'),
content: t('views.trace.analysis.taskDownTip'),
onOk() {
const blob = new Blob([modalState.from.rawDataHTML], {
type: 'text/plain',
});
saveAs(blob, `${modalState.title}_${Date.now()}.html`);
},
});
}
onMounted(() => {
// 获取列表数据
fnGetList();
});
</script>
<template>
<PageContainer :title="title">
<a-card
v-show="tableState.seached"
:bordered="false"
:body-style="{ marginBottom: '24px', paddingBottom: 0 }"
>
<!-- 表格搜索栏 -->
<a-form :model="queryParams" name="queryParams" layout="horizontal">
<a-row :gutter="16">
<a-col :lg="6" :md="12" :xs="24">
<a-form-item
:placeholder="t('views.trace.analysis.imsi')"
name="imsi"
>
<a-input
v-model:value="queryParams.imsi"
:allow-clear="true"
:placeholder="t('views.trace.analysis.imsiPlease')"
></a-input>
</a-form-item>
</a-col>
<a-col :lg="6" :md="12" :xs="24">
<a-form-item
:placeholder="t('views.trace.analysis.msisdn')"
name="imsi"
>
<a-input
v-model:value="queryParams.msisdn"
:allow-clear="true"
:placeholder="t('views.trace.analysis.msisdnPlease')"
></a-input>
</a-form-item>
</a-col>
<a-col :lg="6" :md="12" :xs="24">
<a-form-item>
<a-space :size="8">
<a-button type="primary" @click.prevent="fnGetList">
<template #icon><SearchOutlined /></template>
{{ t('common.search') }}
</a-button>
<a-button type="default" @click.prevent="fnQueryReset">
<template #icon><ClearOutlined /></template>
{{ t('common.reset') }}
</a-button>
</a-space>
</a-form-item>
</a-col>
</a-row>
</a-form>
</a-card>
<a-card :bordered="false" :body-style="{ padding: '0px' }">
<!-- 插槽-卡片左侧侧 -->
<template #title> </template>
<!-- 插槽-卡片右侧 -->
<template #extra>
<a-space :size="8" align="center">
<a-tooltip>
<template #title>{{ t('common.searchBarText') }}</template>
<a-switch
v-model:checked="tableState.seached"
:checked-children="t('common.switch.show')"
:un-checked-children="t('common.switch.hide')"
size="small"
/>
</a-tooltip>
<a-tooltip>
<template #title>{{ t('common.reloadText') }}</template>
<a-button type="text" @click.prevent="fnGetList">
<template #icon><ReloadOutlined /></template>
</a-button>
</a-tooltip>
<a-tooltip>
<template #title>{{ t('common.sizeText') }}</template>
<a-dropdown trigger="click">
<a-button type="text">
<template #icon><ColumnHeightOutlined /></template>
</a-button>
<template #overlay>
<a-menu
:selected-keys="[tableState.size as string]"
@click="fnTableSize"
>
<a-menu-item key="default">{{
t('common.size.default')
}}</a-menu-item>
<a-menu-item key="middle">{{
t('common.size.middle')
}}</a-menu-item>
<a-menu-item key="small">{{
t('common.size.small')
}}</a-menu-item>
</a-menu>
</template>
</a-dropdown>
</a-tooltip>
</a-space>
</template>
<!-- 表格列表 -->
<a-table
class="table"
row-key="id"
:columns="tableColumns"
:loading="tableState.loading"
:data-source="tableState.data"
:size="tableState.size"
:pagination="tablePagination"
:scroll="{ x: true }"
>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'id'">
<a-space :size="8" align="center">
<a-tooltip>
<template #title>查看详情</template>
<a-button type="link" @click.prevent="fnModalVisible(record)">
<template #icon><ProfileOutlined /></template>
</a-button>
</a-tooltip>
</a-space>
</template>
</template>
</a-table>
</a-card>
<!-- 详情框 -->
<a-modal
width="800px"
:title="modalState.title"
:visible="modalState.visible"
@cancel="fnModalVisibleClose"
>
<div class="raw-title">{{ t('views.trace.analysis.signalData') }}</div>
<a-row
class="raw"
:gutter="16"
v-for="v in modalState.from.rawData"
:key="v.row"
>
<a-col class="num" :span="2">{{ v.row }}</a-col>
<a-col class="code" :span="12">{{ v.code }}</a-col>
<a-col class="txt" :span="10">{{ v.asciiText }}</a-col>
</a-row>
<a-divider />
<div class="raw-title">
{{ t('views.trace.analysis.signalDetail') }}
<a-button
type="dashed"
size="small"
@click.prevent="fnDownloadFile"
v-if="modalState.from.downBtn"
>
<template #icon>
<DownloadOutlined />
</template>
{{ t('views.trace.analysis.taskDownText') }}
</a-button>
</div>
<div class="raw-html" v-html="modalState.from.rawDataHTML"></div>
</a-modal>
</PageContainer>
</template>
<style lang="less" scoped>
.table :deep(.ant-pagination) {
padding: 0 24px;
}
.raw {
&-title {
color: #000000d9;
font-size: 24px;
line-height: 1.8;
}
.num {
background-color: #e5e5e5;
}
.code {
background-color: #e7e6ff;
}
.txt {
background-color: #ffe3e5;
}
&-html {
max-height: 300px;
overflow-y: scroll;
}
}
</style>