add: 网元列表

This commit is contained in:
TsMask
2023-09-06 19:36:39 +08:00
parent 7207e0812e
commit 51aa994a9e
7 changed files with 820 additions and 0 deletions

1
.gitignore vendored
View File

@@ -31,3 +31,4 @@ selenium-debug.log
package-lock.json
yarn.lock
src/typings/components.d.ts

View File

@@ -0,0 +1,113 @@
import { request } from '@/plugins/http-fetch';
/**
* 查询网元列表
* @param query 查询参数
* @returns object
*/
export async function listNeInfo(query: Record<string, any>) {
let totalSQL = 'select count(*) as total from ne_info where status=0 ';
let rowsSQL = 'select * from ne_info where status=0 ';
// 查询
let querySQL = '';
if (query.neType) {
querySQL += ` and ne_type = '${query.neType}' `;
}
// 分页
const pageNum = query.pageNum - 1;
const limtSql = ` limit ${pageNum},${query.pageSize} `;
// 发起请求
const result = await request({
url: `/databaseManagement/v1/select/omc_db/ne_info`,
method: 'get',
params: {
totalSQL: totalSQL + querySQL,
rowsSQL: rowsSQL + querySQL + limtSql,
},
});
// 解析数据
if (result.code === 1) {
const data: DataList = {
total: 0,
rows: [],
code: result.code,
msg: result.msg,
};
result.data.data.forEach((item: any) => {
const itemData = item['ne_info'];
if (Array.isArray(itemData)) {
if (itemData.length === 1 && itemData[0]['total']) {
data.total = itemData[0]['total'];
} else {
data.rows = itemData;
}
}
});
return data;
}
return result;
}
/**
* 查询网元详细
* @param menuId 网元ID
* @returns object
*/
export async function getNeInfo(id: string | number) {
// 发起请求
const result = await request({
url: `/databaseManagement/v1/select/omc_db/ne_info`,
method: 'get',
params: {
SQL: `select * from ne_info where status=0 and id = ${id}`,
},
});
// 解析数据
if (result.code === 1 && Array.isArray(result.data.data)) {
const data = result.data.data[0];
return Object.assign(result, { data: data['ne_info'][0] });
}
return result;
}
/**
* 新增网元
* @param data 网元对象
* @returns object
*/
export function addNeInfo(data: Record<string, any>) {
return request({
url: `/systemManagement/v1/elementType/${data.ne_type}/objectType/neInfo`,
method: 'post',
data: data,
});
}
/**
* 修改网元
* @param data 网元对象
* @returns object
*/
export function updateNeInfo(data: Record<string, any>) {
return request({
url: `/systemManagement/v1/elementType/${data.ne_type}/objectType/neInfo`,
method: 'put',
data: data,
});
}
/**
* 删除网元
* @param noticeId 网元ID
* @returns object
*/
export async function delNeInfo(data: Record<string, any>) {
return request({
url: `/systemManagement/v1/elementType/${data.ne_type}/objectType/neInfo?ne_id=${data.ne_id}`,
method: 'delete',
});
}

26
src/api/log.ts Normal file
View File

@@ -0,0 +1,26 @@
import { request } from '@/plugins/http-fetch';
type OperationLogType = {
account_name: string;
account_type: string; //type:int
op_ip: string;
subsys_tag: string;
op_type: string;
op_content: string;
op_result: string;
begin_time: string;
end_time: string;
vnf_flag: string; //0-物理设备 1-虚拟化设备
};
/**
* 操作日志
* @returns object
*/
export function operationLog(opt: OperationLogType) {
return request({
url: '/databaseManagement/v1/insert/omc_db/operation_log',
method: 'post',
data: [opt],
});
}

View File

@@ -9,6 +9,8 @@ export default {
desc: '',
loading: 'Please wait...',
tipTitle: 'Prompt',
msgSuccess: "Success {msg}",
errorFields: "Please fill in the required information in {num} correctly!",
},
// 全局页脚

View File

@@ -9,6 +9,8 @@ export default {
desc: '',
loading: '请稍等...',
tipTitle: '提示',
msgSuccess: "成功 {msg}",
errorFields: "请正确填写 {num} 处必填信息!",
},
// 全局页脚

7
src/typings/request.d.ts vendored Normal file
View File

@@ -0,0 +1,7 @@
/**数据列表 */
type DataList = {
code: number;
msg: string;
total: number;
rows: Record<string, any>;
};

View File

@@ -0,0 +1,669 @@
<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, Form } 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 {
listNotice,
getNotice,
delNotice,
addNotice,
updateNotice,
} from '@/api/system/notice';
import {
listNeInfo,
getNeInfo,
addNeInfo,
updateNeInfo,
delNeInfo,
} from '@/api/configuration/net-ele';
import { parseDateToStr } from '@/utils/date-utils';
import useDictStore from '@/store/modules/dict';
import useI18n from '@/hooks/useI18n';
const { t } = useI18n();
const { getDict } = useDictStore();
const route = useRoute();
/**路由标题 */
let title = ref<string>(route.meta.title ?? '标题');
/**字典数据 */
let dict: {
/**网元类型 */
sysNoticeType: DictType[];
/**网元状态 */
sysNoticeStatus: DictType[];
} = reactive({
sysNoticeType: [],
sysNoticeStatus: [],
});
/**查询参数 */
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;
/**斑马纹 */
striped: boolean;
/**搜索栏 */
seached: boolean;
/**记录数据 */
data: object[];
/**勾选记录 */
selectedRowKeys: (string | number)[];
};
/**表格状态 */
let tableState: TabeStateType = reactive({
loading: false,
size: 'middle',
striped: false,
seached: true,
data: [],
selectedRowKeys: [],
});
/**表格字段列 */
let tableColumns: ColumnsType = [
{
title: '网元类型',
dataIndex: 'ne_type',
align: 'center',
},
{
title: '网元内部标识',
dataIndex: 'ne_id',
align: 'center',
},
{
title: '资源唯一标识',
dataIndex: 'rm_uid',
align: 'center',
},
{
title: '网元名称',
dataIndex: 'ne_name',
align: 'center',
},
{
title: 'IP地址',
dataIndex: 'ip',
align: 'center',
},
{
title: '网元地址',
dataIndex: 'ne_address',
align: 'center',
},
{
title: '端口',
dataIndex: 'port',
align: 'center',
},
{
title: '网元虚拟化标识',
dataIndex: 'pv_flag',
align: 'center',
},
{
title: '网元所在省份',
dataIndex: 'province',
align: 'center',
},
{
title: '厂商名称',
dataIndex: 'vendor_name',
align: 'center',
},
{
title: '网络标识',
dataIndex: 'dn',
align: 'center',
},
{
title: '修改时间',
dataIndex: 'update_time',
align: 'center',
customRender(opt) {
if (!opt.value) return '';
return parseDateToStr(opt.value);
},
},
{
title: '操作',
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) => `总共 ${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 fnTableStriped(_record: unknown, index: number) {
return tableState.striped && index % 2 === 1 ? 'table-striped' : undefined;
}
/**表格多选 */
function fnTableSelectedRowKeys(keys: (string | number)[]) {
tableState.selectedRowKeys = keys;
}
/**对话框对象信息状态类型 */
type ModalStateType = {
/**详情框是否显示 */
visibleByView: boolean;
/**新增框或修改框是否显示 */
visibleByEdit: boolean;
/**标题 */
title: string;
/**表单数据 */
from: Record<string, any>;
/**确定按钮 loading */
confirmLoading: boolean;
};
/**对话框对象信息状态 */
let modalState: ModalStateType = reactive({
visibleByView: false,
visibleByEdit: false,
title: '网元',
from: {},
confirmLoading: false,
});
/**对话框内表单属性和校验规则 */
const modalStateFrom = Form.useForm(
modalState.from,
reactive({
noticeTitle: [
{ required: true, min: 2, max: 50, message: '请正确输入网元标题' },
],
noticeType: [{ required: true, message: '请选择网元类型' }],
noticeContent: [
{
required: true,
min: 2,
max: 3000,
message: '请正确输入网元内容限10-3000个字符',
},
],
})
);
/**
* 对话框弹出显示为 查看
* @param noticeId 网元id
*/
function fnModalVisibleByVive(noticeId: string | number) {
if (!noticeId) {
message.error(`网元记录存在错误`, 2);
return;
}
if (modalState.confirmLoading) return;
const hide = message.loading('正在打开...', 0);
modalState.confirmLoading = true;
getNotice(noticeId).then(res => {
modalState.confirmLoading = false;
hide();
if (res.code === 200) {
modalState.from = Object.assign(modalState.from, res.data);
modalState.title = '网元信息';
modalState.visibleByView = true;
} else {
message.error(`获取网元信息失败`, 2);
}
});
}
/**
* 对话框弹出显示为 新增或者修改
* @param noticeId 网元id, 不传为新增
*/
function fnModalVisibleByEdit(row: Record<string, any>) {
if (!row) {
modalStateFrom.resetFields();
modalState.title = '添加网元';
modalState.visibleByEdit = true;
} else {
if (modalState.confirmLoading) return;
const hide = message.loading('正在打开...', 0);
modalState.confirmLoading = true;
getNeInfo(row.id).then(res => {
modalState.confirmLoading = false;
hide();
if (res.code === 1) {
modalState.from = Object.assign(modalState.from, res.data);
modalState.title = '修改网元';
modalState.visibleByEdit = true;
} else {
message.error(`获取网元信息失败`, 2);
}
});
}
}
/**
* 对话框弹出确认执行函数
* 进行表达规则校验
*/
function fnModalOk() {
modalStateFrom
.validate()
.then(() => {
modalState.confirmLoading = true;
const from = toRaw(modalState.from);
const notice = from.noticeId ? updateNeInfo(from) : addNeInfo(from);
const hide = message.loading({ content: t('loading') });
notice
.then(res => {
if (res.code === 200) {
message.success({
content: t('msgSuccess', { msg: modalState.title }),
duration: 2,
});
modalState.visibleByEdit = false;
modalStateFrom.resetFields();
fnGetList();
} else {
message.error({
content: `${res.msg}`,
duration: 2,
});
}
})
.finally(() => {
hide();
modalState.confirmLoading = false;
});
})
.catch(e => {
message.error(t('errorFields', { num: e.errorFields.length }), 2);
});
}
/**
* 对话框弹出关闭执行函数
* 进行表达规则校验
*/
function fnModalCancel() {
modalState.visibleByEdit = false;
modalState.visibleByView = false;
modalStateFrom.resetFields();
}
/**
* 网元删除
* @param row 网元编号ID
*/
function fnRecordDelete(row: Record<string, any>) {
Modal.confirm({
title: '提示',
content: `确认删除网元编号为 【${row.id}】 的数据项?`,
onOk() {
const key = 'delNotice';
message.loading({ content: '请稍等...', key });
delNeInfo(row).then(res => {
if (res.code === 200) {
message.success({
content: `删除成功`,
key,
duration: 2,
});
fnGetList();
} else {
message.error({
content: `${res.msg}`,
key: key,
duration: 2,
});
}
});
},
});
}
/**查询网元列表 */
function fnGetList() {
if (tableState.loading) return;
tableState.loading = true;
listNeInfo(toRaw(queryParams)).then(res => {
if (res.code === 1 && Array.isArray(res.rows)) {
// 取消勾选
if (tableState.selectedRowKeys.length > 0) {
tableState.selectedRowKeys = [];
}
tablePagination.total = res.total;
tableState.data = res.rows;
}
tableState.loading = false;
});
}
onMounted(() => {
// 初始字典数据
Promise.allSettled([
getDict('sys_notice_type'),
getDict('sys_notice_status'),
]).then(resArr => {
if (resArr[0].status === 'fulfilled') {
dict.sysNoticeType = resArr[0].value;
}
if (resArr[1].status === 'fulfilled') {
dict.sysNoticeStatus = resArr[1].value;
}
});
// 获取列表数据
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="网元类型" name="neType ">
<a-input
v-model:value="queryParams.neType"
allow-clear
placeholder="请输入网元类型"
></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>
搜索</a-button
>
<a-button type="default" @click.prevent="fnQueryReset">
<template #icon><ClearOutlined /></template>
重置</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-space :size="8" align="center">
<a-button type="primary" @click.prevent="fnModalVisibleByEdit()">
<template #icon><PlusOutlined /></template>
添加
</a-button>
</a-space>
</template>
<!-- 插槽-卡片右侧 -->
<template #extra>
<a-space :size="8" align="center">
<a-tooltip>
<template #title>搜索栏</template>
<a-switch
v-model:checked="tableState.seached"
checked-children=""
un-checked-children=""
size="small"
/>
</a-tooltip>
<a-tooltip>
<template #title>表格斑马纹</template>
<a-switch
v-model:checked="tableState.striped"
checked-children=""
un-checked-children=""
size="small"
/>
</a-tooltip>
<a-tooltip>
<template #title>刷新</template>
<a-button type="text" @click.prevent="fnGetList">
<template #icon><ReloadOutlined /></template>
</a-button>
</a-tooltip>
<a-tooltip>
<template #title>密度</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">默认</a-menu-item>
<a-menu-item key="middle">中等</a-menu-item>
<a-menu-item key="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"
:row-class-name="fnTableStriped"
: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="fnModalVisibleByEdit(record)"
>
<template #icon><FormOutlined /></template>
</a-button>
</a-tooltip>
<a-tooltip>
<template #title>删除</template>
<a-button type="link" @click.prevent="fnRecordDelete(record)">
<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="网元标题" name="noticeTitle">
{{ modalState.from.noticeTitle }}
</a-form-item>
</a-col>
<a-col :lg="6" :md="6" :xs="24">
<a-form-item label="网元类型" name="noticeType">
<DictTag
:options="dict.sysNoticeType"
:value="modalState.from.noticeType"
/>
</a-form-item>
</a-col>
<a-col :lg="6" :md="6" :xs="24">
<a-form-item label="网元状态" name="status">
<DictTag
:options="dict.sysNoticeStatus"
:value="modalState.from.status"
/>
</a-form-item>
</a-col>
</a-row>
<a-form-item label="网元内容" name="noticeContent">
{{ modalState.from.noticeContent }}
</a-form-item>
</a-form>
<template #footer>
<a-button key="cancel" @click="fnModalCancel">关闭</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="网元标题"
name="noticeTitle"
v-bind="modalStateFrom.validateInfos.noticeTitle"
>
<a-input
v-model:value="modalState.from.noticeTitle"
allow-clear
placeholder="请输入网元标题"
></a-input>
</a-form-item>
</a-col>
<a-col :lg="6" :md="6" :xs="24">
<a-form-item
label="网元类型"
name="noticeType"
v-bind="modalStateFrom.validateInfos.noticeType"
>
<a-select
v-model:value="modalState.from.noticeType"
default-value="1"
placeholder="网元类型"
:options="dict.sysNoticeType"
>
</a-select>
</a-form-item>
</a-col>
<a-col :lg="6" :md="6" :xs="24">
<a-form-item label="网元状态" name="status">
<a-select
v-model:value="modalState.from.status"
default-value="0"
placeholder="网元状态"
:options="dict.sysNoticeStatus"
>
</a-select>
</a-form-item>
</a-col>
</a-row>
<a-form-item
label="网元内容"
name="noticeContent"
v-bind="modalStateFrom.validateInfos.noticeContent"
>
<a-textarea
v-model:value="modalState.from.noticeContent"
:auto-size="{ minRows: 4, maxRows: 14 }"
:maxlength="3000"
:show-count="true"
placeholder="请输入网元内容"
/>
</a-form-item>
</a-form>
</a-modal>
</PageContainer>
</template>
<style lang="less" scoped>
.table :deep(.table-striped) td {
background-color: #fafafa;
}
.table :deep(.ant-pagination) {
padding: 0 24px;
}
</style>