feat: 通道管理 todo

This commit is contained in:
jackhoo_98 2023-03-02 17:01:12 +08:00
parent 2090822bab
commit 21ae942d98
5 changed files with 2031 additions and 0 deletions

View File

@ -0,0 +1,10 @@
import server from '@/utils/request';
export const queryChannel = (type: string, data: any) =>
server.post(`/data-collect/channel/_query`, data);
export const removeChannel = (type: string, data: any) =>
server.remove(`/data-collect/channel//${id}`);
export const updateChannel = (type: string, data: any) =>
server.patch(`/data-collect/channel//${id}`, data);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,315 @@
export const Configuration = {
parserType: undefined,
port: undefined,
host: undefined,
publicPort: '',
publicHost: '',
remoteHost: '',
remotePort: '',
secure: false,
username: '',
password: '',
topicPrefix: '',
maxMessageSize: 8192,
certId: undefined,
privateKeyAlias: '',
clientId: '',
parserConfiguration: {
delimited: '',
lang: '',
script: '',
size: '',
length: '4',
offset: '0',
little: 'false',
},
};
export const FormStates = {
name: '',
type: 'UDP',
shareCluster: true,
description: '',
};
export const FormStates2 = {
serverId: undefined,
configuration: Configuration,
};
export const TCPList = [
'TCP_SERVER',
'WEB_SOCKET_SERVER',
'HTTP_SERVER',
'MQTT_SERVER',
];
export const UDPList = ['UDP', 'COAP_SERVER'];
const VisibleMost = [
'COAP_SERVER',
'MQTT_SERVER',
'WEB_SOCKET_SERVER',
'TCP_SERVER',
'UDP',
'HTTP_SERVER',
];
export const VisibleData = {
parserType: ['TCP_SERVER'],
port: VisibleMost,
host: VisibleMost,
publicPort: VisibleMost,
publicHost: VisibleMost,
serverId: ['MQTT_CLIENT'],
remoteHost: ['MQTT_CLIENT'],
remotePort: ['MQTT_CLIENT'],
secure: ['TCP_SERVER', 'UDP', 'COAP_SERVER'],
username: ['MQTT_CLIENT'],
password: ['MQTT_CLIENT'],
topicPrefix: ['MQTT_CLIENT'],
maxMessageSize: ['MQTT_SERVER', 'MQTT_CLIENT'],
clientId: ['MQTT_CLIENT'],
delimited: ['DELIMITED'],
lang: ['SCRIPT'],
script: ['SCRIPT'],
size: ['FIXED_LENGTH'],
length: ['LENGTH_FIELD'],
offset: ['LENGTH_FIELD'],
little: ['LENGTH_FIELD'],
};
export const ParserTypeOptions = [
{ value: 'DIRECT', label: '不处理' },
{ value: 'DELIMITED', label: '分隔符' },
{ value: 'SCRIPT', label: '自定义脚本' },
{ value: 'FIXED_LENGTH', label: '固定长度' },
{ value: 'LENGTH_FIELD', label: '长度字段' },
];
export const LengthOptions = [
{ value: '1', label: '1' },
{ value: '2', label: '2' },
{ value: '3', label: '3' },
{ value: '4', label: '4' },
{ value: '8', label: '8' },
];
export const LittleOptions = [
{ label: '大端', value: 'false' },
{ label: '小端', value: 'true' },
];
export const isVisible = (
LastName: string,
dependencies: string | boolean | undefined,
) => VisibleData[LastName].includes(dependencies);
export const Validator = {
regIp: new RegExp(
/((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})(\.((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})){3}/,
),
regDomain: new RegExp(
/[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+\.?/,
),
regOnlyNumber: new RegExp(/^\d+$/),
};
export const Rules = {
name: [
{
required: true,
message: '请输入名称',
},
{
max: 64,
message: '最大可输入64个字符',
},
],
type: [
{
required: true,
message: '请选择类型',
},
],
shareCluster: [
{
required: true,
message: '请选择集群',
},
],
host: [
{
required: true,
message: '请选择本地地址',
},
],
port: [
{
required: true,
message: '请选择本地端口',
},
],
publicHost: [
{
required: true,
message: '请输入公网地址',
},
{
pattern: Validator.regIp || Validator.regDomain,
message: '请输入IP或者域名',
},
],
publicPort: [
{
required: true,
message: '请输入公网端口',
},
{
pattern: Validator.regOnlyNumber,
message: '请输入1-65535之间的正整数',
},
],
remoteHost: [
{
required: true,
message: '请输入远程地址',
},
{
pattern: Validator.regIp || Validator.regDomain,
message: '请输入IP或者域名',
},
],
remotePort: [
{
required: true,
message: '输入远程端口',
},
{
pattern: Validator.regOnlyNumber,
message: '请输入1-65535之间的正整数',
},
],
clientId: [
{
required: true,
message: '请输入ClientId',
},
{
max: 64,
message: '最大可输入64个字符',
},
],
username: [
{
required: true,
message: '请输入用户名',
},
{
max: 64,
message: '最大可输入64个字符',
},
],
password: [
{
required: true,
message: '请输入密码',
},
{
max: 64,
message: '最大可输入64个字符',
},
],
topicPrefix: [
{
max: 64,
message: '最大可输入64个字符',
},
],
maxMessageSize: [
{
required: true,
message: '请输入最大消息长度',
},
],
secure: [
{
required: true,
},
],
certId: [
{
required: true,
message: '请选择证书',
},
],
privateKeyAlias: [
{
required: true,
message: '请输入私钥别名',
},
{
max: 64,
message: '最大可输入64个字符',
},
],
parserType: [
{
required: true,
message: '请选择粘拆包规则',
},
],
delimited: [
{
required: true,
message: '请输入分隔符',
},
{
max: 64,
message: '最大可输入64个字符',
},
],
lang: [
{
required: true,
message: '请选择脚本语言',
},
{
max: 64,
message: '最大可输入64个字符',
},
],
script: [
{
required: true,
message: '请输入脚本',
},
],
size: [
{
required: true,
message: '请输入长度值',
},
],
length: [
{
required: true,
message: '请选择长度',
},
],
offset: [
{
pattern: Validator.regOnlyNumber,
message: '请输入0-65535之间的正整数',
},
],
};
export const TiTlePermissionButtonStyle = {
padding: 0,
color: ' #1890ff !important',
'font-weight': 700,
'font-size': '16px',
overflow: 'hidden',
'text-overflow': 'ellipsis',
'white-space': 'nowrap',
width: 'calc(100%-100px)',
// width: '60%',
};

View File

@ -0,0 +1,336 @@
<template>
<page-container>
<div>
<Search :columns="columns" target="search" @search="handleSearch" />
<JTable
ref="tableRef"
:columns="columns"
model="CARD"
:gridColumn="3"
:request="queryChannel"
:defaultParams="{
sorts: [{ name: 'createTime', order: 'desc' }],
}"
:params="params"
>
<template #headerTitle>
<PermissionButton
type="primary"
@click="handlAdd"
hasPermission="DataCollect/Channel:add"
>
<template #icon><AIcon type="PlusOutlined" /></template>
新增通道
</PermissionButton>
</template>
<template #card="slotProps">
<CardBox
:showStatus="true"
:value="slotProps"
:actions="getActions(slotProps, 'card')"
v-bind="slotProps"
:status="slotProps.state.value"
:statusText="slotProps.state.text"
:statusNames="{
enabled: 'success',
disabled: 'error',
}"
>
<template #img>
<slot name="img">
<img :src="getImage('/network.png')" />
</slot>
</template>
<template #content>
<div class="card-item-content">
<PermissionButton
type="link"
@click="handlEye(slotProps.id)"
hasPermission="link/Type:view"
:style="TiTlePermissionButtonStyle"
>
{{ slotProps.name }}
</PermissionButton>
<a-row class="card-item-content-box">
<a-col :span="12">
<div class="card-item-content-text">
协议
</div>
<div class="card-item-content-text">
<a-tooltip>
<template #title>{{
slotProps.provider
}}</template>
{{ slotProps.provider }}
</a-tooltip>
</div>
</a-col>
<a-col :span="12">
<div class="card-item-content-text">
地址
</div>
<div class="card-item-content-text">
<a-tooltip>
<template #title>{{
slotProps.configuration
.host ||
slotProps.configuration
.endpoint
}}</template>
<span class="details-text">{{
slotProps.configuration
.host ||
slotProps.configuration
.endpoint
}}</span>
</a-tooltip>
</div>
</a-col>
</a-row>
</div>
</template>
<template #actions="item">
<PermissionButton
:disabled="item.disabled"
:popConfirm="item.popConfirm"
:tooltip="{
...item.tooltip,
}"
@click="item.onClick"
:hasPermission="'link/Type:' + item.key"
>
<AIcon
type="DeleteOutlined"
v-if="item.key === 'delete'"
/>
<template v-else>
<AIcon :type="item.icon" />
<span>{{ item?.text }}</span>
</template>
</PermissionButton>
</template>
</CardBox>
</template>
</JTable>
</div>
</page-container>
</template>
<script lang="ts" setup name="TypePage">
import type { ActionsType } from '@/components/Table/index';
import { getImage } from '@/utils/comm';
import {
queryChannel,
updateChannel,
removeChannel,
} from '@/api/data-collect/channel';
import { message } from 'ant-design-vue';
import { TiTlePermissionButtonStyle } from './data';
import { useMenuStore } from 'store/menu';
const menuStory = useMenuStore();
const tableRef = ref<Record<string, any>>({});
const params = ref<Record<string, any>>({});
const options = ref([]);
const statusMap = new Map();
statusMap.set('enabled', 'success');
statusMap.set('disabled', 'error');
const columns = [
{
title: '通道名称',
dataIndex: 'name',
key: 'name',
ellipsis: true,
fixed: 'left',
search: {
type: 'string',
},
},
{
title: '通讯协议',
dataIndex: 'provider',
key: 'provider',
ellipsis: true,
search: {
type: 'select',
options: [
{ label: 'OPC_UA', value: 'OPC_UA' },
{ label: 'MODBUS_TCP', value: 'MODBUS_TCP' },
],
},
},
{
title: '状态',
dataIndex: 'state',
key: 'state',
ellipsis: true,
scopedSlots: true,
search: {
type: 'select',
options: [
{ label: '正常', value: 'enabled' },
{ label: '禁用', value: 'disabled' },
],
},
},
{
title: '运行状态',
dataIndex: 'runningState',
key: 'runningState',
ellipsis: true,
scopedSlots: true,
search: {
type: 'select',
options: [
{ label: '运行中', value: 'running' },
{ label: '部分错误', value: 'partialError' },
{ label: '错误', value: 'failed' },
],
},
},
{
title: '说明',
dataIndex: 'description',
key: 'description',
ellipsis: true,
},
{
title: '操作',
key: 'action',
fixed: 'right',
width: 200,
scopedSlots: true,
},
];
const getActions = (
data: Partial<Record<string, any>>,
type: 'card' | 'table',
): ActionsType[] => {
if (!data) return [];
const state = data.state.value;
const stateText = state === 'enabled' ? '禁用' : '启用';
const actions = [
// {
// key: 'view',
// text: '',
// tooltip: {
// title: '',
// },
// icon: 'EyeOutlined',
// onClick: async () => {
// handlEye(data.id);
// },
// },
{
key: 'update',
text: '编辑',
tooltip: {
title: '编辑',
},
icon: 'EditOutlined',
onClick: () => {
handlEdit(data.id);
},
},
{
key: 'action',
text: stateText,
tooltip: {
title: stateText,
},
icon: state === 'enabled' ? 'StopOutlined' : 'CheckCircleOutlined',
popConfirm: {
title: `确认${stateText}?`,
onConfirm: async () => {
// let res =
// state === 'enabled'
// ? await shutdown(data.id)
// : await start(data.id);
// if (res.success) {
// message.success('');
// tableRef.value?.reload();
// } else {
// message.error('');
// }
},
},
},
{
key: 'delete',
text: '删除',
disabled: state === 'enabled',
tooltip: {
title:
state === 'enabled' ? '请先禁用该组件,再删除。' : '删除',
},
popConfirm: {
title: '确认删除?',
onConfirm: async () => {
// const res = await remove(data.id);
// if (res.success) {
// message.success('');
// tableRef.value.reload();
// } else {
// message.error('');
// }
},
},
icon: 'DeleteOutlined',
},
];
return actions;
};
const handlAdd = () => {
// menuStory.jumpPage(`link/Type/Detail`, { id: ':id' }, { view: false });
};
const handlEye = (id: string) => {
// menuStory.jumpPage(`link/Type/Detail`, { id }, { view: true });
};
const handlEdit = (id: string) => {
// menuStory.jumpPage(`link/Type/Detail`, { id }, { view: false });
};
/**
* 搜索
* @param params
*/
const handleSearch = (e: any) => {
params.value = e;
};
</script>
<style lang="less" scoped>
.card-item-content {
min-height: 100px;
.card-item-content-title-a {
// color: #000 !important;
font-weight: 700;
font-size: 16px;
overflow: hidden; //
text-overflow: ellipsis; //
white-space: nowrap; //
}
.card-item-content-box {
min-height: 50px;
}
.card-item-content-text {
margin-top: 10px;
color: rgba(0, 0, 0, 0.75);
font-size: 12px;
overflow: hidden; //
text-overflow: ellipsis; //
white-space: nowrap; //
}
}
.details-text {
font-weight: 700;
font-size: 14px;
}
</style>

38
src/views/DataCollect/Channel/type.d.ts vendored Normal file
View File

@ -0,0 +1,38 @@
export interface ConfigurationType {
parserType: string | undefined;
port: string | undefined;
host: string | undefined;;
publicPort: string;
publicHost: string;
remoteHost: string;
remotePort: string;
secure: boolean;
username: string;
password: string;
topicPrefix: string;
maxMessageSize: string | number;
certId: string | undefined;
privateKeyAlias: string;
clientId: string;
parserConfiguration: {
delimited: string;
lang: string;
script: string;
size: string;
length: string;
offset: string;
little: string | boolean | undefined;
};
}
export interface FormDataType {
name: string;
type: string;
shareCluster: boolean;
description: string;
}
export interface FormData2Type {
id?: number | string;
serverId?: string | undefined;
configuration: ConfigurationType;
}