add home view and reverse 4 bytes order to send
This commit is contained in:
29
src/views/HomeView.vue
Normal file
29
src/views/HomeView.vue
Normal file
@@ -0,0 +1,29 @@
|
||||
<template>
|
||||
<div class="bg-base-200 min-h-screen">
|
||||
<main class="hero min-h-screen bg-base-200">
|
||||
<div class="hero-content flex-col lg:flex-row-reverse">
|
||||
<img src="https://placehold.co/600x400" class="max-w-sm rounded-lg shadow-2xl" />
|
||||
<div>
|
||||
<h1 class="text-5xl font-bold">Welcome to FPGA Web Lab!</h1>
|
||||
<p class="py-6">
|
||||
Prototype and simulate electronic circuits in your browser.
|
||||
</p>
|
||||
<button class="btn btn-primary">Get Started</button>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<div class="fixed bottom-10 right-10 btn btn-circle">
|
||||
<ThemeControlButton class=""></ThemeControlButton>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import ThemeControlButton from "@/components/ThemeControlButton.vue";
|
||||
import "@/router";
|
||||
</script>
|
||||
|
||||
<style scoped lang="postcss">
|
||||
@import "../assets/main.css";
|
||||
</style>
|
||||
@@ -3,44 +3,38 @@
|
||||
<div class="h-full w-32"></div>
|
||||
|
||||
<div class="h-full w-[70%] shadow-2xl flex">
|
||||
<p>{{ logText }}</p>
|
||||
|
||||
<button class="btn btn-primary h-10 w-30">获取ID Code</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref } from "vue";
|
||||
const eventSource = new EventSource("http://localhost:5000/api/log");
|
||||
const logText = ref("");
|
||||
import { ref, onMounted, onUnmounted } from "vue";
|
||||
|
||||
// 启动SSE连接
|
||||
function startStream() {
|
||||
eventSource.onmessage = function (e) {
|
||||
logText.value = e.data;
|
||||
const eventSource = ref<EventSource>();
|
||||
|
||||
const initSource = () => {
|
||||
eventSource.value = new EventSource("http://localhost:500/api/log/example");
|
||||
|
||||
eventSource.value.onmessage = (event) => {
|
||||
console.log("收到消息内容是:", event.data);
|
||||
};
|
||||
|
||||
eventSource.onerror = function (err) {
|
||||
console.error("Error:", err);
|
||||
eventSource.close();
|
||||
eventSource.value.onerror = (error) => {
|
||||
console.error("SSE 连接出错:", error);
|
||||
eventSource.value!.close();
|
||||
};
|
||||
};
|
||||
|
||||
eventSource.onopen = function () {
|
||||
console.log("Connection opened");
|
||||
};
|
||||
}
|
||||
onMounted(() => {
|
||||
initSource();
|
||||
});
|
||||
|
||||
// 停止SSE连接
|
||||
function stopStream() {
|
||||
onUnmounted(() => {
|
||||
if (eventSource) {
|
||||
eventSource.close();
|
||||
console.log("Connection closed");
|
||||
eventSource.value?.close();
|
||||
}
|
||||
}
|
||||
|
||||
// 页面加载时自动启动
|
||||
window.onload = startStream;
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped lang="postcss">
|
||||
|
||||
Reference in New Issue
Block a user