Commit 3312e0c3 by 周田

test: 测试 protobufjs

parent 70bbaa6c
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
"process": "^0.11.10", "process": "^0.11.10",
"protobufjs": "^7.2.4", "protobufjs": "^7.2.4",
"terser": "^5.19.2", "terser": "^5.19.2",
"ts-protoc-gen": "^0.15.0",
"vue": "^3.3.4", "vue": "^3.3.4",
"vue-router": "^4.2.4" "vue-router": "^4.2.4"
}, },
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
syntax = "proto3"; syntax = "proto3";
import "google/protobuf/any.proto"; import "google/protobuf/any.proto";
import "google/protobuf/timestamp.proto"; import "google/protobuf/timestamp.proto";
import "TDSCmd.proto";
option go_package="../protogo"; option go_package="../protogo";
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
syntax = "proto3"; syntax = "proto3";
import "google/protobuf/any.proto"; import "google/protobuf/any.proto";
import "google/protobuf/timestamp.proto"; import "google/protobuf/timestamp.proto";
import "TDSCmd.proto";
//alrm level //alrm level
enum Level{ enum Level{
......
<script setup lang="ts"> <script setup lang="ts">
import { ref, watch, onMounted } from 'vue'; import { ref, watch, onMounted } from 'vue';
import { ElScrollbar, ElInput, ElButton } from 'element-plus'; import { ElScrollbar, ElInput, ElButton } from 'element-plus';
import { load } from 'protobufjs';
const innerRef = ref<HTMLDivElement>(); const innerRef = ref<HTMLDivElement>();
const scrollbarRef = ref<InstanceType<typeof ElScrollbar>>(); const scrollbarRef = ref<InstanceType<typeof ElScrollbar>>();
...@@ -29,6 +30,24 @@ const send = () => { ...@@ -29,6 +30,24 @@ const send = () => {
input.value = ''; input.value = '';
} }
const test = () => {
load([
"../proto/TDSCmd.proto",
"../proto/OAM_datastruct.proto",
"../proto/Device_datastruct.proto",
], (error: any, root: any) => {
if (error) {
throw error
}
console.log(root)
let cmd = root.lookupType('TDSCmd');
console.log(cmd);
});
}
watch(flag, () => { watch(flag, () => {
setTimeout(() => { setTimeout(() => {
scrollbarRef.value!.setScrollTop(innerRef.value!.offsetHeight); scrollbarRef.value!.setScrollTop(innerRef.value!.offsetHeight);
...@@ -49,7 +68,8 @@ onMounted(() => { ...@@ -49,7 +68,8 @@ onMounted(() => {
// const byteArray = new Uint8Array(e.data); // const byteArray = new Uint8Array(e.data);
// // 将字节流转换为字符串或其他格式进行处理 // // 将字节流转换为字符串或其他格式进行处理
// const message = byteArray.toString(); // const message = byteArray.toString();
items.value.push(JSON.stringify(e.data)); // items.value.push(JSON.stringify(e.data));
items.value.push(e.data);
flag.value = !flag.value flag.value = !flag.value
}; };
...@@ -59,12 +79,11 @@ onMounted(() => { ...@@ -59,12 +79,11 @@ onMounted(() => {
}) })
</script> </script>
<template> <template>
<el-scrollbar ref="scrollbarRef" mb-10 h-100 always> <el-scrollbar ref="scrollbarRef" mb-10 height="400px" always>
<div ref="innerRef"> <div ref="innerRef">
<p v-for="item in items" :key="item" class="scrollbar-demo-item"> <p v-for="item in items" :key="item" class="scrollbar-demo-item">
<div>{{ JSON.parse(item)!.ts }}</div> <div>{{ JSON.parse(item)?.ts }}</div>
{{ item }} {{ item }}
</p> </p>
</div> </div>
...@@ -72,6 +91,8 @@ onMounted(() => { ...@@ -72,6 +91,8 @@ onMounted(() => {
<el-input v-model="input" placeholder="Please input" @keyup.enter="send"></el-input> <el-input v-model="input" placeholder="Please input" @keyup.enter="send"></el-input>
<el-button mt-10 @click="send">Send</el-button> <el-button mt-10 @click="send">Send</el-button>
<br/>
<el-button mt-10 @click="test">test</el-button>
</template> </template>
<style scoped> <style scoped>
......
...@@ -2069,6 +2069,11 @@ globals@^11.1.0: ...@@ -2069,6 +2069,11 @@ globals@^11.1.0:
resolved "https://registry.npmmirror.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e" resolved "https://registry.npmmirror.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e"
integrity sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA== integrity sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==
google-protobuf@^3.15.5:
version "3.21.2"
resolved "https://registry.npmmirror.com/google-protobuf/-/google-protobuf-3.21.2.tgz#4580a2bea8bbb291ee579d1fefb14d6fa3070ea4"
integrity sha512-3MSOYFO5U9mPGikIYCzK0SaThypfGgS6bHqrUGXG3DPHCrb+txNqeEcns1W0lkGfk0rCyNXm7xB9rMxnCiZOoA==
gzip-size@^6.0.0: gzip-size@^6.0.0:
version "6.0.0" version "6.0.0"
resolved "https://registry.npmmirror.com/gzip-size/-/gzip-size-6.0.0.tgz#065367fd50c239c0671cbcbad5be3e2eeb10e462" resolved "https://registry.npmmirror.com/gzip-size/-/gzip-size-6.0.0.tgz#065367fd50c239c0671cbcbad5be3e2eeb10e462"
...@@ -2653,6 +2658,13 @@ totalist@^3.0.0: ...@@ -2653,6 +2658,13 @@ totalist@^3.0.0:
resolved "https://registry.npmmirror.com/totalist/-/totalist-3.0.1.tgz#ba3a3d600c915b1a97872348f79c127475f6acf8" resolved "https://registry.npmmirror.com/totalist/-/totalist-3.0.1.tgz#ba3a3d600c915b1a97872348f79c127475f6acf8"
integrity sha512-sf4i37nQ2LBx4m3wB74y+ubopq6W/dIzXg0FDGjsYnZHVa1Da8FH853wlL2gtUhg+xJXjfk3kUZS3BRoQeoQBQ== integrity sha512-sf4i37nQ2LBx4m3wB74y+ubopq6W/dIzXg0FDGjsYnZHVa1Da8FH853wlL2gtUhg+xJXjfk3kUZS3BRoQeoQBQ==
ts-protoc-gen@^0.15.0:
version "0.15.0"
resolved "https://registry.npmmirror.com/ts-protoc-gen/-/ts-protoc-gen-0.15.0.tgz#2fec5930b46def7dcc9fa73c060d770b7b076b7b"
integrity sha512-TycnzEyrdVDlATJ3bWFTtra3SCiEP0W0vySXReAuEygXCUr1j2uaVyL0DhzjwuUdQoW5oXPwk6oZWeA0955V+g==
dependencies:
google-protobuf "^3.15.5"
typescript@^5.0.2: typescript@^5.0.2:
version "5.1.6" version "5.1.6"
resolved "https://registry.npmmirror.com/typescript/-/typescript-5.1.6.tgz#02f8ac202b6dad2c0dd5e0913745b47a37998274" resolved "https://registry.npmmirror.com/typescript/-/typescript-5.1.6.tgz#02f8ac202b6dad2c0dd5e0913745b47a37998274"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment