From af0a5039eb988b7dd572dece0e8b3453c0ef5fd8 Mon Sep 17 00:00:00 2001 From: cc Date: Tue, 26 Dec 2023 03:01:12 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/infoApi.js | 20 +-- src/proto/com.proto | 32 ++--- src/proto/data.proto | 30 ++++ src/proto/data/pd.js | 293 ++++++++++++++++++++++++++++++++++++++- src/proto/info.proto | 106 +++++++------- src/proto/net.proto | 38 ++--- src/proto/post.proto | 7 + src/proto/response.proto | 14 +- src/proto/rule.proto | 4 +- src/proto/sb.proto | 41 ++++++ src/proto/tx.proto | 67 +++++++++ src/proto/user.proto | 41 +++--- src/views/Rules.vue | 6 +- vite.config.js | 4 +- 14 files changed, 563 insertions(+), 140 deletions(-) create mode 100644 src/proto/data.proto create mode 100644 src/proto/post.proto create mode 100644 src/proto/sb.proto create mode 100644 src/proto/tx.proto diff --git a/src/api/infoApi.js b/src/api/infoApi.js index 2ed5796..265dc7b 100644 --- a/src/api/infoApi.js +++ b/src/api/infoApi.js @@ -130,29 +130,13 @@ const infoApi = { delSc(params) { return deleteRequest("/sb", params); }, - // 获取规则列表 + // 规则查询 getRules(params) { return getRequest('/rule', params); }, - // 新增规则 + // 规则操作 addRules(params) { return postJsonRequest('/rule', params) }, - // 编辑规则 - editRule(params) { - return putRequest('/rule', params) - }, - // 删除规则 - delRules(params) { - return deleteRequest('/rule', params) - }, - // 规则启用 - startStatus(params) { - return postJsonRequest('/enable', params); - }, - // 规则停用 - stopStatus(params) { - return postJsonRequest('/disable', params); - }, }; export default infoApi; diff --git a/src/proto/com.proto b/src/proto/com.proto index 86277cb..2cfd411 100644 --- a/src/proto/com.proto +++ b/src/proto/com.proto @@ -1,17 +1,17 @@ -syntax = "proto3"; -option go_package = "data/"; - -message com_list{ - repeated com_info com = 1; -} - -message com_info{ - string name = 1; - string path = 2; - bool used = 3; - int32 baud_rate = 4; - int32 data_bits = 5; - int32 stop_bits = 6; - string parity = 7; - int32 timeout = 8; +syntax = "proto3"; +option go_package = "data/"; + +message com_list{ + repeated com_info com = 1; +} + +message com_info{ + string name = 1; + string path = 2; + bool used = 3; + int32 baud_rate = 4; + int32 data_bits = 5; + int32 stop_bits = 6; + string parity = 7; + int32 timeout = 8; } \ No newline at end of file diff --git a/src/proto/data.proto b/src/proto/data.proto new file mode 100644 index 0000000..f1c9ff9 --- /dev/null +++ b/src/proto/data.proto @@ -0,0 +1,30 @@ +syntax = "proto3"; +option go_package = "data/"; + +message m_properties{ + string name = 1; + string value = 2; +} + +message m_point_list{ + repeated m_point points = 1; +} + +message m_point{ + string name = 1; + string path = 2; + string value = 3; + repeated m_properties properties = 4; +} + +message m_device_list{ + repeated m_device devices = 1; +} + +message m_device{ + string name = 1; + string value = 2; + string path = 3; + repeated m_properties properties = 4; + repeated m_point points = 5; +} \ No newline at end of file diff --git a/src/proto/data/pd.js b/src/proto/data/pd.js index 03607e6..ae76c06 100644 --- a/src/proto/data/pd.js +++ b/src/proto/data/pd.js @@ -4550,6 +4550,242 @@ export const dns_info = $root.dns_info = (() => { return dns_info; })(); +export const post = $root.post = (() => { + + /** + * Properties of a post. + * @exports Ipost + * @interface Ipost + * @property {number|null} [cmd] post cmd + * @property {Uint8Array|null} [data] post data + */ + + /** + * Constructs a new post. + * @exports post + * @classdesc Represents a post. + * @implements Ipost + * @constructor + * @param {Ipost=} [properties] Properties to set + */ + function post(properties) { + if (properties) + for (let keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * post cmd. + * @member {number} cmd + * @memberof post + * @instance + */ + post.prototype.cmd = 0; + + /** + * post data. + * @member {Uint8Array} data + * @memberof post + * @instance + */ + post.prototype.data = $util.newBuffer([]); + + /** + * Creates a new post instance using the specified properties. + * @function create + * @memberof post + * @static + * @param {Ipost=} [properties] Properties to set + * @returns {post} post instance + */ + post.create = function create(properties) { + return new post(properties); + }; + + /** + * Encodes the specified post message. Does not implicitly {@link post.verify|verify} messages. + * @function encode + * @memberof post + * @static + * @param {Ipost} message post message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + post.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.cmd != null && Object.hasOwnProperty.call(message, "cmd")) + writer.uint32(/* id 1, wireType 0 =*/8).int32(message.cmd); + if (message.data != null && Object.hasOwnProperty.call(message, "data")) + writer.uint32(/* id 2, wireType 2 =*/18).bytes(message.data); + return writer; + }; + + /** + * Encodes the specified post message, length delimited. Does not implicitly {@link post.verify|verify} messages. + * @function encodeDelimited + * @memberof post + * @static + * @param {Ipost} message post message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + post.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a post message from the specified reader or buffer. + * @function decode + * @memberof post + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {post} post + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + post.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + let end = length === undefined ? reader.len : reader.pos + length, message = new $root.post(); + while (reader.pos < end) { + let tag = reader.uint32(); + switch (tag >>> 3) { + case 1: { + message.cmd = reader.int32(); + break; + } + case 2: { + message.data = reader.bytes(); + break; + } + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a post message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof post + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {post} post + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + post.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a post message. + * @function verify + * @memberof post + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + post.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.cmd != null && message.hasOwnProperty("cmd")) + if (!$util.isInteger(message.cmd)) + return "cmd: integer expected"; + if (message.data != null && message.hasOwnProperty("data")) + if (!(message.data && typeof message.data.length === "number" || $util.isString(message.data))) + return "data: buffer expected"; + return null; + }; + + /** + * Creates a post message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof post + * @static + * @param {Object.} object Plain object + * @returns {post} post + */ + post.fromObject = function fromObject(object) { + if (object instanceof $root.post) + return object; + let message = new $root.post(); + if (object.cmd != null) + message.cmd = object.cmd | 0; + if (object.data != null) + if (typeof object.data === "string") + $util.base64.decode(object.data, message.data = $util.newBuffer($util.base64.length(object.data)), 0); + else if (object.data.length >= 0) + message.data = object.data; + return message; + }; + + /** + * Creates a plain object from a post message. Also converts values to other types if specified. + * @function toObject + * @memberof post + * @static + * @param {post} message post + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + post.toObject = function toObject(message, options) { + if (!options) + options = {}; + let object = {}; + if (options.defaults) { + object.cmd = 0; + if (options.bytes === String) + object.data = ""; + else { + object.data = []; + if (options.bytes !== Array) + object.data = $util.newBuffer(object.data); + } + } + if (message.cmd != null && message.hasOwnProperty("cmd")) + object.cmd = message.cmd; + if (message.data != null && message.hasOwnProperty("data")) + object.data = options.bytes === String ? $util.base64.encode(message.data, 0, message.data.length) : options.bytes === Array ? Array.prototype.slice.call(message.data) : message.data; + return object; + }; + + /** + * Converts this post to JSON. + * @function toJSON + * @memberof post + * @instance + * @returns {Object.} JSON object + */ + post.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for post + * @function getTypeUrl + * @memberof post + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + post.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/post"; + }; + + return post; +})(); + export const response = $root.response = (() => { /** @@ -5041,6 +5277,8 @@ export const rule_info = $root.rule_info = (() => { * @interface Irule_info * @property {string|null} [id] rule_info id * @property {string|null} [label] rule_info label + * @property {string|null} [info] rule_info info + * @property {Uint8Array|null} [nodes] rule_info nodes * @property {boolean|null} [disabled] rule_info disabled */ @@ -5075,6 +5313,22 @@ export const rule_info = $root.rule_info = (() => { */ rule_info.prototype.label = ""; + /** + * rule_info info. + * @member {string} info + * @memberof rule_info + * @instance + */ + rule_info.prototype.info = ""; + + /** + * rule_info nodes. + * @member {Uint8Array} nodes + * @memberof rule_info + * @instance + */ + rule_info.prototype.nodes = $util.newBuffer([]); + /** * rule_info disabled. * @member {boolean} disabled @@ -5111,8 +5365,12 @@ export const rule_info = $root.rule_info = (() => { writer.uint32(/* id 1, wireType 2 =*/10).string(message.id); if (message.label != null && Object.hasOwnProperty.call(message, "label")) writer.uint32(/* id 2, wireType 2 =*/18).string(message.label); + if (message.info != null && Object.hasOwnProperty.call(message, "info")) + writer.uint32(/* id 3, wireType 2 =*/26).string(message.info); + if (message.nodes != null && Object.hasOwnProperty.call(message, "nodes")) + writer.uint32(/* id 4, wireType 2 =*/34).bytes(message.nodes); if (message.disabled != null && Object.hasOwnProperty.call(message, "disabled")) - writer.uint32(/* id 3, wireType 0 =*/24).bool(message.disabled); + writer.uint32(/* id 5, wireType 0 =*/40).bool(message.disabled); return writer; }; @@ -5156,6 +5414,14 @@ export const rule_info = $root.rule_info = (() => { break; } case 3: { + message.info = reader.string(); + break; + } + case 4: { + message.nodes = reader.bytes(); + break; + } + case 5: { message.disabled = reader.bool(); break; } @@ -5200,6 +5466,12 @@ export const rule_info = $root.rule_info = (() => { if (message.label != null && message.hasOwnProperty("label")) if (!$util.isString(message.label)) return "label: string expected"; + if (message.info != null && message.hasOwnProperty("info")) + if (!$util.isString(message.info)) + return "info: string expected"; + if (message.nodes != null && message.hasOwnProperty("nodes")) + if (!(message.nodes && typeof message.nodes.length === "number" || $util.isString(message.nodes))) + return "nodes: buffer expected"; if (message.disabled != null && message.hasOwnProperty("disabled")) if (typeof message.disabled !== "boolean") return "disabled: boolean expected"; @@ -5222,6 +5494,13 @@ export const rule_info = $root.rule_info = (() => { message.id = String(object.id); if (object.label != null) message.label = String(object.label); + if (object.info != null) + message.info = String(object.info); + if (object.nodes != null) + if (typeof object.nodes === "string") + $util.base64.decode(object.nodes, message.nodes = $util.newBuffer($util.base64.length(object.nodes)), 0); + else if (object.nodes.length >= 0) + message.nodes = object.nodes; if (object.disabled != null) message.disabled = Boolean(object.disabled); return message; @@ -5243,12 +5522,24 @@ export const rule_info = $root.rule_info = (() => { if (options.defaults) { object.id = ""; object.label = ""; + object.info = ""; + if (options.bytes === String) + object.nodes = ""; + else { + object.nodes = []; + if (options.bytes !== Array) + object.nodes = $util.newBuffer(object.nodes); + } object.disabled = false; } if (message.id != null && message.hasOwnProperty("id")) object.id = message.id; if (message.label != null && message.hasOwnProperty("label")) object.label = message.label; + if (message.info != null && message.hasOwnProperty("info")) + object.info = message.info; + if (message.nodes != null && message.hasOwnProperty("nodes")) + object.nodes = options.bytes === String ? $util.base64.encode(message.nodes, 0, message.nodes.length) : options.bytes === Array ? Array.prototype.slice.call(message.nodes) : message.nodes; if (message.disabled != null && message.hasOwnProperty("disabled")) object.disabled = message.disabled; return object; diff --git a/src/proto/info.proto b/src/proto/info.proto index aebd8bc..243aed4 100644 --- a/src/proto/info.proto +++ b/src/proto/info.proto @@ -1,54 +1,54 @@ -syntax = "proto3"; -option go_package = "data/"; - -message info{ - Basicinfo basicinfo = 1; - Hostinfo hostinfo = 2; - Meminfo meminfo = 3; - repeated Diskinfo diskinfo = 4; - repeated Netinfo netinfo = 5; -} - -// 基本信息 -message Basicinfo{ - string model = 1; // 设备型号 - string sn = 2; // 设备SN - string first_time = 3; // 初次激活时间 -} - -// 主机信息 -message Hostinfo{ - int32 cpu = 1; // cpu核数 - string uptime = 2; // 开机时长 - string boottime = 3; // 开机时间 -} - -// 内存信息 -message Meminfo{ - double total = 1; // 总大小 - double available = 2; // 可用 - double used = 3; // 已用 - double used_percent = 4; // 已用占比 - double free = 5; // 空闲 - double buffers = 6; // 缓冲区 - double cached = 7; // 缓存 -} - -// 存储信息 -message Diskinfo{ - string name = 1; // 名称 - string path = 2; // 路径 - double total = 3; // 总大小 - double free = 4; // 空闲 - double used = 5; // 已用 - double used_percent = 6; // 已用占比 -} - -// 网络信息 -message Netinfo{ - string name = 1; // 网卡名称 - uint64 bytesSent = 2; // number of bytes sent - uint64 bytesRecv = 3; // number of bytes received - uint64 packetsSent = 4; // number of packets sent - uint64 packetsRecv = 5; // number of packets received +syntax = "proto3"; +option go_package = "data/"; + +message info{ + Basicinfo basicinfo = 1; + Hostinfo hostinfo = 2; + Meminfo meminfo = 3; + repeated Diskinfo diskinfo = 4; + repeated Netinfo netinfo = 5; +} + +// 基本信息 +message Basicinfo{ + string model = 1; // 设备型号 + string sn = 2; // 设备SN + string first_time = 3; // 初次激活时间 +} + +// 主机信息 +message Hostinfo{ + int32 cpu = 1; // cpu核数 + string uptime = 2; // 开机时长 + string boottime = 3; // 开机时间 +} + +// 内存信息 +message Meminfo{ + double total = 1; // 总大小 + double available = 2; // 可用 + double used = 3; // 已用 + double used_percent = 4; // 已用占比 + double free = 5; // 空闲 + double buffers = 6; // 缓冲区 + double cached = 7; // 缓存 +} + +// 存储信息 +message Diskinfo{ + string name = 1; // 名称 + string path = 2; // 路径 + double total = 3; // 总大小 + double free = 4; // 空闲 + double used = 5; // 已用 + double used_percent = 6; // 已用占比 +} + +// 网络信息 +message Netinfo{ + string name = 1; // 网卡名称 + uint64 bytesSent = 2; // number of bytes sent + uint64 bytesRecv = 3; // number of bytes received + uint64 packetsSent = 4; // number of packets sent + uint64 packetsRecv = 5; // number of packets received } \ No newline at end of file diff --git a/src/proto/net.proto b/src/proto/net.proto index b5ec032..c6afe74 100644 --- a/src/proto/net.proto +++ b/src/proto/net.proto @@ -1,20 +1,20 @@ -syntax = "proto3"; -option go_package = "data/"; - -message net_info{ - repeated ip_info ip = 1; - dns_info dns = 2; -} - -message ip_info{ - string name = 1; - string mode = 2; - string ip = 3; - string mk = 4; - string gw = 5; -} - -message dns_info{ - string dns1 = 1; - string dns2 = 2; +syntax = "proto3"; +option go_package = "data/"; + +message net_info{ + repeated ip_info ip = 1; + dns_info dns = 2; +} + +message ip_info{ + string name = 1; + string mode = 2; + string ip = 3; + string mk = 4; + string gw = 5; +} + +message dns_info{ + string dns1 = 1; + string dns2 = 2; } \ No newline at end of file diff --git a/src/proto/post.proto b/src/proto/post.proto new file mode 100644 index 0000000..765fbd3 --- /dev/null +++ b/src/proto/post.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; +option go_package = "data/"; + +message post{ + int32 cmd = 1; + bytes data = 2; +} \ No newline at end of file diff --git a/src/proto/response.proto b/src/proto/response.proto index f92bd40..e50fe16 100644 --- a/src/proto/response.proto +++ b/src/proto/response.proto @@ -1,8 +1,8 @@ -syntax = "proto3"; -option go_package = "data/"; - -message response{ - uint32 code = 1; - bytes data = 2; - string msg = 3; +syntax = "proto3"; +option go_package = "data/"; + +message response{ + uint32 code = 1; + bytes data = 2; + string msg = 3; } \ No newline at end of file diff --git a/src/proto/rule.proto b/src/proto/rule.proto index e29e0e2..0cbb396 100644 --- a/src/proto/rule.proto +++ b/src/proto/rule.proto @@ -8,5 +8,7 @@ message rule{ message rule_info{ string id = 1; string label = 2; - bool disabled = 3; + string info = 3; + bytes nodes = 4; + bool disabled = 5; } \ No newline at end of file diff --git a/src/proto/sb.proto b/src/proto/sb.proto new file mode 100644 index 0000000..d9c891e --- /dev/null +++ b/src/proto/sb.proto @@ -0,0 +1,41 @@ +syntax = "proto3"; +option go_package = "data/"; + +message sb_list{ + repeated sb_info sb = 1; +} + +message sb_host{ + repeated string host = 1; +} + +message sb_info{ + string name = 1; + string drive = 2; + string host = 3; + uint32 status = 4; + string description = 5; + bool enable = 6; + repeated string device_name = 7; +} + +message sb_add{ + string name = 1; + string drive = 2; + string description = 3; + bytes config = 4; +} + +message sb_drive_list{ + repeated sb_drive_info sb_drive = 1; +} + +message sb_drive_info{ + string name = 1; + bytes config = 2; +} + +// message tx_drive_config_modbusTCP{ +// string host = 1; +// string port = 2; +// } \ No newline at end of file diff --git a/src/proto/tx.proto b/src/proto/tx.proto new file mode 100644 index 0000000..e3a1838 --- /dev/null +++ b/src/proto/tx.proto @@ -0,0 +1,67 @@ +syntax = "proto3"; +option go_package = "data/"; +import "data.proto"; + +message tx_list{ + repeated tx_info tx = 1; +} + +message tx_host{ + repeated string host = 1; +} + +message tx_info{ + string name = 1; + string drive = 2; + bool serial = 3; + string host = 4; + uint32 status = 5; + string description = 6; + bool enable = 7; + repeated tx_device_info device = 8; +} + +message tx_add{ + string name = 1; + string drive = 2; + bool serial = 3; + string description = 4; + bytes config = 5; +} + +message tx_add_device{ + string name = 1; + repeated tx_device_info device = 2; +} + +message tx_drive_list{ + repeated tx_drive_info tx_drive = 1; +} + +message tx_drive_info{ + string name = 1; + bool serial = 2; + bytes config = 3; +} + +message tx_drive_config_modbusTCP{ + string host = 1; + string port = 2; +} + +message tx_device_info{ + string name = 1; + string template = 2; + repeated m_properties properties = 3; +} + +message mb_list{ + repeated mb_info mb = 1; +} + +message mb_info{ + string name = 1; + string type = 2; + string description = 3; + repeated m_point points = 4; +} \ No newline at end of file diff --git a/src/proto/user.proto b/src/proto/user.proto index 8954bbc..af9174f 100644 --- a/src/proto/user.proto +++ b/src/proto/user.proto @@ -1,21 +1,22 @@ -syntax = "proto3"; -option go_package = "data/"; - -message user{ - string name = 1; - string password = 2; - fixed64 timestamp = 3; -} - -message token{ - string name = 1; - string token = 2; - fixed64 timestamp = 3; - fixed64 expiration_time = 4; -} - -message passwd{ - string name = 1; - string old_password = 2; - string new_password = 3; +syntax = "proto3"; +option go_package = "data/"; + +message user{ + string name = 1; + string password = 2; + fixed64 timestamp = 3; +} + +message token{ + string name = 1; + string token = 2; + fixed64 timestamp = 3; + fixed64 expiration_time = 4; +} + +message passwd{ + string name = 1; + string old_password = 2; + string new_password = 3; + string new_password2 = 4; } \ No newline at end of file diff --git a/src/views/Rules.vue b/src/views/Rules.vue index 1c5a302..deb6499 100644 --- a/src/views/Rules.vue +++ b/src/views/Rules.vue @@ -69,7 +69,7 @@ import { onMounted, reactive, ref, toRefs } from "vue"; import { ElMessage, ElMessageBox } from "element-plus"; import infoApi from "@/api/infoApi.js"; -import { response, rule_info } from '../proto/data/pd' +import { response, rule,rule_info,post } from '../proto/data/pd' import AddRule from "@/components/AddRule.vue"; export default { name: "rules", @@ -97,8 +97,8 @@ export default { if (ret.code == 0) { // 获取数据 - state.tableData = rule_info.decode(ret.data); - console.log(rule_info.decode(ret.data)); + console.log(rule.decode(ret.data)); + state.tableData = rule.decode(ret.data); } else { console.log(res); } diff --git a/vite.config.js b/vite.config.js index 0dbeec6..b2f1c39 100644 --- a/vite.config.js +++ b/vite.config.js @@ -24,8 +24,8 @@ export default ({ mode }) => defineConfig({ server: { proxy: { '/api': { - target: 'http://api.shikicc.com:58909', - // target: 'http://10.10.14.123', + // target: 'http://api.shikicc.com:58909', + target: 'http://10.10.14.247', // target: 'https://cdcmapi.shikicc.com', changeOrigin: true, rewrite: path => path.replace(/^\/api/, '/api')