baoshiwei
6 天以前 5bf14aed888cd0e258e325c65f14022dad02985b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
<script setup lang="ts">
import { ref } from "vue";
import { invoke } from "@tauri-apps/api/core";
import ForceChart from "./components/ForceChart.vue";
import GaugeDisplay from "./components/GaugeDisplay.vue";
import TableDisplay from "./components/TableDisplay.vue";
import ThreeDDisplay from "./components/ThreeDDisplay.vue";
import TitleBar from "./components/TitleBar.vue";
 
// const message = ref('');
const logs = ref<string[]>([]);
const showChart = ref(false);
const pipeName = 'tauri-pipe-server';
const currentDisplay = ref('line'); // 默认显示曲线图
const dataSource = ref<'pipe' | 'ws'>('ws'); // 默认数据源为管道
 
async function startPipeServer() {
  try {
    const res = await invoke('start_pipe_server_command', {pipeName});
    console.log(res);
    logs.value.push('[系统] 数据接收服务已启动');
    console.log('[系统] 管道服务端已启动');
    showChart.value = true;
  } catch (err) {
    logs.value.push(`[错误] 启动失败: ${err}`);
  }
}
 
// async function sendToPipe() {
//   if (!message.value) return;
  
//   try {
//     const response = await invoke('send_pipe_message', {pipeName, message: message.value });
//     logs.value.push(`[发送] ${message.value}`);
//     logs.value.push(`[接收] ${response}`);
//     message.value = '';
//   } catch (err) {
//     logs.value.push(`[错误] 通信失败: ${err}`);
//   }
// }
startPipeServer();
</script>
 
<template>
  <TitleBar :currentDisplay="currentDisplay" @start-service="startPipeServer" @select-display="(mode) => currentDisplay = mode" />
  <main class="container">
    <!-- <div class="data-source-switch">
      <label>数据源:</label>
      <select v-model="dataSource">
        <option value="pipe">管道</option>
        <option value="ws">WebSocket</option>
      </select>
    </div> -->
    
      <div class="display-mode-icons">
      <button :class="['icon-button', { active: currentDisplay === 'line' }]" @click="currentDisplay = 'line'" title="曲线图">
        <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M2 13L8.5 6L13.5 12L19 7L22 10"/><path d="M18 13a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"/></svg>
      </button>
      <button :class="['icon-button', { active: currentDisplay === 'gauge' }]" @click="currentDisplay = 'gauge'" title="仪表盘">
        <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M12 6v6l4 2"/></svg>
      </button>
      <button :class="['icon-button', { active: currentDisplay === 'table' }]" @click="currentDisplay = 'table'" title="数据表格">
        <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="14" x="2" y="7" rx="2"/><path d="M10 12H6"/><path d="M18 12h-4"/><path d="M10 16H6"/><path d="M18 16h-4"/></svg>
      </button>
      <button :class="['icon-button', { active: currentDisplay === '3d' }]" @click="currentDisplay = '3d'" title="3D坐标轴">
        <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 2L2 7l10 5l10-5l-10-5z"/><path d="M2 17l10 5l10-5"/><path d="M2 12l10 5l10-5"/></svg>
      </button>
    </div>
    <div class="header-row">
      <h2>Force Sensor Data Visualization</h2>
    </div>
    
 
    
    <!-- 显示力传感器数据 -->
    <div v-if="showChart" class="chart-wrapper">
      <ForceChart v-if="currentDisplay === 'line'" :pipeName="pipeName" :dataSource="dataSource" />
      <GaugeDisplay v-else-if="currentDisplay === 'gauge'" :pipeName="pipeName" :dataSource="dataSource" />
      <TableDisplay v-else-if="currentDisplay === 'table'" :pipeName="pipeName" :dataSource="dataSource" />
      <ThreeDDisplay v-else-if="currentDisplay === '3d'" :pipeName="pipeName" :dataSource="dataSource" />
    </div>
    
    <!-- <div class="input-group">
      <input 
        v-model="message"
        placeholder="输入测试消息"
        @keyup.enter="sendToPipe"
      />
      <button @click="sendToPipe">发送消息</button>
    </div> -->
    
    <div class="log-container">
      <div v-for="(log, index) in logs" :key="index" class="log-item">
        {{ log }}
      </div>
    </div>
  </main>
</template>
 
<style scoped>
.control-group {
  margin: 20px 0;
}
 
.input-group {
  display: flex;
  gap: 10px;
  margin: 20px 20px auto;
  max-width: 500px;
}
 
.chart-wrapper {
  width: 95%;
  margin: 10px auto;
  background-color: #ffffff;
  border-radius: 8px;
  padding: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  height: 580px;
}
 
.log-container {
 
  border-radius: 8px;
  max-height: 300px;
  overflow-y: auto;
 
}
 
.log-item {
  padding: 5px 0;
  color: #000;
  font-size: 0.9em;
}
 
.data-source-switch {
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
</style>
 
<style>
:root {
  font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 24px;
  font-weight: 400;
 
  color: #0f0f0f;
  background-color: #f6f6f6;
 
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
}
 
.container {
  margin: 32px 0 0 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  align-items: center;
}
 
.logo {
  height: 6em;
  padding: 1.5em;
  will-change: filter;
  transition: 0.75s;
}
 
.logo.tauri:hover {
  filter: drop-shadow(0 0 2em #24c8db);
}
 
.row {
  display: flex;
  justify-content: center;
}
 
a {
  font-weight: 500;
  color: #646cff;
  text-decoration: inherit;
}
 
a:hover {
  color: #535bf2;
}
 
h1 {
  text-align: center;
}
 
input,
button {
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0.6em 1.2em;
  font-size: 1em;
  font-weight: 500;
  font-family: inherit;
  color: #0f0f0f;
  background-color: #ffffff;
  transition: border-color 0.25s;
  box-shadow: 0 2px 2px rgba(0, 0, 0, 0.2);
}
 
button {
  cursor: pointer;
}
 
button:hover {
  border-color: #396cd8;
}
button:active {
  border-color: #396cd8;
  background-color: #e8e8e8;
}
 
input,
button {
  outline: none;
}
 
#greet-input {
  margin-right: 5px;
}
 
@media (prefers-color-scheme: dark) {
  :root {
    color: #f6f6f6;
    background-color: #2f2f2f;
  }
 
  a:hover {
    color: #24c8db;
  }
 
  input,
  button {
    color: #ffffff;
    background-color: #0f0f0f98;
  }
  button:active {
    background-color: #0f0f0f69;
  }
}
 
.header-row {
  height: 60px;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0 20px;
  color: wheat;
}
 
.header-row h2 {
  margin: 0;
}
 
.icon-button {
  width: 28px; /* Slightly larger for icons */
  height: 28px; /* Slightly larger for icons */
  border: none;
  background: rgba(255, 254, 254, 0.7);
  color: rgba(85, 85, 85, 0.7); /* Slightly transparent white */
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  padding: 0;
  transition: background-color 0.2s, color 0.2s;
  cursor: pointer;
}
 
.icon-button:hover {
  background-color: rgba(255, 255, 255, 0.1);
  color: black; /* Full white on hover */
}
 
.icon-button.active {
  color: #3498db; /* Active color */
  background-color: rgba(255, 254, 254, 0.7); /* Slightly different background for active */
}
.display-mode-icons {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px; /* Smaller gap for icons */
  margin-top: -27px; /* Space between icons and window controls */
  width: 100px;
  z-index: 9999;
}
 
 
</style>