init
9
.editorconfig
Normal file
@ -0,0 +1,9 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
4
.eslintignore
Normal file
@ -0,0 +1,4 @@
|
||||
node_modules
|
||||
dist
|
||||
out
|
||||
.gitignore
|
15
.eslintrc.cjs
Normal file
@ -0,0 +1,15 @@
|
||||
/* eslint-env node */
|
||||
require('@rushstack/eslint-patch/modern-module-resolution')
|
||||
|
||||
module.exports = {
|
||||
extends: [
|
||||
'eslint:recommended',
|
||||
'plugin:vue/vue3-recommended',
|
||||
'@electron-toolkit',
|
||||
'@vue/eslint-config-prettier'
|
||||
],
|
||||
rules: {
|
||||
'vue/require-default-prop': 'off',
|
||||
'vue/multi-word-component-names': 'off'
|
||||
}
|
||||
}
|
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
node_modules
|
||||
dist
|
||||
out
|
||||
.DS_Store
|
||||
*.log*
|
6
.prettierignore
Normal file
@ -0,0 +1,6 @@
|
||||
out
|
||||
dist
|
||||
pnpm-lock.yaml
|
||||
LICENSE.md
|
||||
tsconfig.json
|
||||
tsconfig.*.json
|
4
.prettierrc.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
singleQuote: true
|
||||
semi: false
|
||||
printWidth: 100
|
||||
trailingComma: none
|
3
.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"recommendations": ["dbaeumer.vscode-eslint"]
|
||||
}
|
39
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Debug Main Process",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"cwd": "${workspaceRoot}",
|
||||
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron-vite",
|
||||
"windows": {
|
||||
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron-vite.cmd"
|
||||
},
|
||||
"runtimeArgs": ["--sourcemap"],
|
||||
"env": {
|
||||
"REMOTE_DEBUGGING_PORT": "9222"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Debug Renderer Process",
|
||||
"port": 9222,
|
||||
"request": "attach",
|
||||
"type": "chrome",
|
||||
"webRoot": "${workspaceFolder}/src/renderer",
|
||||
"timeout": 60000,
|
||||
"presentation": {
|
||||
"hidden": true
|
||||
}
|
||||
}
|
||||
],
|
||||
"compounds": [
|
||||
{
|
||||
"name": "Debug All",
|
||||
"configurations": ["Debug Main Process", "Debug Renderer Process"],
|
||||
"presentation": {
|
||||
"order": 1
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
11
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"[typescript]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
},
|
||||
"[javascript]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
},
|
||||
"[json]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
}
|
||||
}
|
34
README.md
Normal file
@ -0,0 +1,34 @@
|
||||
# sensor-simulator
|
||||
|
||||
An Electron application with Vue
|
||||
|
||||
## Recommended IDE Setup
|
||||
|
||||
- [VSCode](https://code.visualstudio.com/) + [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) + [Prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar)
|
||||
|
||||
## Project Setup
|
||||
|
||||
### Install
|
||||
|
||||
```bash
|
||||
$ npm install
|
||||
```
|
||||
|
||||
### Development
|
||||
|
||||
```bash
|
||||
$ npm run dev
|
||||
```
|
||||
|
||||
### Build
|
||||
|
||||
```bash
|
||||
# For windows
|
||||
$ npm run build:win
|
||||
|
||||
# For macOS
|
||||
$ npm run build:mac
|
||||
|
||||
# For Linux
|
||||
$ npm run build:linux
|
||||
```
|
12
build/entitlements.mac.plist
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>com.apple.security.cs.allow-jit</key>
|
||||
<true/>
|
||||
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
|
||||
<true/>
|
||||
<key>com.apple.security.cs.allow-dyld-environment-variables</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
BIN
build/icon.icns
Normal file
BIN
build/icon.ico
Normal file
After Width: | Height: | Size: 121 KiB |
BIN
build/icon.png
Normal file
After Width: | Height: | Size: 35 KiB |
42
electron-builder.yml
Normal file
@ -0,0 +1,42 @@
|
||||
appId: com.electron.app
|
||||
productName: sensor-simulator
|
||||
directories:
|
||||
buildResources: build
|
||||
files:
|
||||
- '!**/.vscode/*'
|
||||
- '!src/*'
|
||||
- '!electron.vite.config.{js,ts,mjs,cjs}'
|
||||
- '!{.eslintignore,.eslintrc.cjs,.prettierignore,.prettierrc.yaml,dev-app-update.yml,CHANGELOG.md,README.md}'
|
||||
- '!{.env,.env.*,.npmrc,pnpm-lock.yaml}'
|
||||
asarUnpack:
|
||||
- resources/**
|
||||
win:
|
||||
executableName: sensor-simulator
|
||||
nsis:
|
||||
artifactName: ${name}-${version}-setup.${ext}
|
||||
shortcutName: ${productName}
|
||||
uninstallDisplayName: ${productName}
|
||||
createDesktopShortcut: always
|
||||
mac:
|
||||
entitlementsInherit: build/entitlements.mac.plist
|
||||
extendInfo:
|
||||
- NSCameraUsageDescription: Application requests access to the device's camera.
|
||||
- NSMicrophoneUsageDescription: Application requests access to the device's microphone.
|
||||
- NSDocumentsFolderUsageDescription: Application requests access to the user's Documents folder.
|
||||
- NSDownloadsFolderUsageDescription: Application requests access to the user's Downloads folder.
|
||||
notarize: false
|
||||
dmg:
|
||||
artifactName: ${name}-${version}.${ext}
|
||||
linux:
|
||||
target:
|
||||
- AppImage
|
||||
- snap
|
||||
- deb
|
||||
maintainer: electronjs.org
|
||||
category: Utility
|
||||
appImage:
|
||||
artifactName: ${name}-${version}.${ext}
|
||||
npmRebuild: false
|
||||
publish:
|
||||
provider: generic
|
||||
url: https://example.com/auto-updates
|
20
electron.vite.config.mjs
Normal file
@ -0,0 +1,20 @@
|
||||
import { resolve } from 'path'
|
||||
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
|
||||
export default defineConfig({
|
||||
main: {
|
||||
plugins: [externalizeDepsPlugin()]
|
||||
},
|
||||
preload: {
|
||||
plugins: [externalizeDepsPlugin()]
|
||||
},
|
||||
renderer: {
|
||||
resolve: {
|
||||
alias: {
|
||||
'@renderer': resolve('src/renderer/src')
|
||||
}
|
||||
},
|
||||
plugins: [vue()]
|
||||
}
|
||||
})
|
6889
package-lock.json
generated
Normal file
39
package.json
Normal file
@ -0,0 +1,39 @@
|
||||
{
|
||||
"name": "sensor-simulator",
|
||||
"version": "1.0.0",
|
||||
"description": "An Electron application with Vue",
|
||||
"main": "./out/main/index.js",
|
||||
"author": "example.com",
|
||||
"homepage": "https://electron-vite.org",
|
||||
"scripts": {
|
||||
"format": "prettier --write .",
|
||||
"lint": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix",
|
||||
"start": "electron-vite preview",
|
||||
"dev": "electron-vite dev",
|
||||
"build": "electron-vite build",
|
||||
"postinstall": "electron-builder install-app-deps",
|
||||
"build:unpack": "npm run build && electron-builder --dir",
|
||||
"build:win": "npm run build && electron-builder --win",
|
||||
"build:mac": "npm run build && electron-builder --mac",
|
||||
"build:linux": "npm run build && electron-builder --linux"
|
||||
},
|
||||
"dependencies": {
|
||||
"@electron-toolkit/preload": "^3.0.1",
|
||||
"@electron-toolkit/utils": "^3.0.0",
|
||||
"axios": "^1.7.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@electron-toolkit/eslint-config": "^1.0.2",
|
||||
"@rushstack/eslint-patch": "^1.10.3",
|
||||
"@vitejs/plugin-vue": "^5.0.5",
|
||||
"@vue/eslint-config-prettier": "^9.0.0",
|
||||
"electron": "^31.0.2",
|
||||
"electron-builder": "^24.13.3",
|
||||
"electron-vite": "^2.3.0",
|
||||
"eslint": "^8.57.0",
|
||||
"eslint-plugin-vue": "^9.26.0",
|
||||
"prettier": "^3.3.2",
|
||||
"vite": "^5.3.1",
|
||||
"vue": "^3.4.30"
|
||||
}
|
||||
}
|
BIN
resources/icon.png
Normal file
After Width: | Height: | Size: 35 KiB |
74
src/main/index.js
Normal file
@ -0,0 +1,74 @@
|
||||
import { app, shell, BrowserWindow, ipcMain } from 'electron'
|
||||
import { join } from 'path'
|
||||
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
||||
import icon from '../../resources/icon.png?asset'
|
||||
|
||||
function createWindow() {
|
||||
// Create the browser window.
|
||||
const mainWindow = new BrowserWindow({
|
||||
width: 900,
|
||||
height: 820,
|
||||
show: false,
|
||||
autoHideMenuBar: true,
|
||||
...(process.platform === 'linux' ? { icon } : {}),
|
||||
webPreferences: {
|
||||
preload: join(__dirname, '../preload/index.js'),
|
||||
sandbox: false
|
||||
}
|
||||
})
|
||||
|
||||
mainWindow.on('ready-to-show', () => {
|
||||
mainWindow.show()
|
||||
})
|
||||
|
||||
mainWindow.webContents.setWindowOpenHandler((details) => {
|
||||
shell.openExternal(details.url)
|
||||
return { action: 'deny' }
|
||||
})
|
||||
|
||||
// HMR for renderer base on electron-vite cli.
|
||||
// Load the remote URL for development or the local html file for production.
|
||||
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
|
||||
mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL'])
|
||||
} else {
|
||||
mainWindow.loadFile(join(__dirname, '../renderer/index.html'))
|
||||
}
|
||||
}
|
||||
|
||||
// This method will be called when Electron has finished
|
||||
// initialization and is ready to create browser windows.
|
||||
// Some APIs can only be used after this event occurs.
|
||||
app.whenReady().then(() => {
|
||||
// Set app user model id for windows
|
||||
electronApp.setAppUserModelId('com.electron')
|
||||
|
||||
// Default open or close DevTools by F12 in development
|
||||
// and ignore CommandOrControl + R in production.
|
||||
// see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils
|
||||
app.on('browser-window-created', (_, window) => {
|
||||
optimizer.watchWindowShortcuts(window)
|
||||
})
|
||||
|
||||
// IPC test
|
||||
ipcMain.on('ping', () => console.log('pong'))
|
||||
|
||||
createWindow()
|
||||
|
||||
app.on('activate', function () {
|
||||
// On macOS it's common to re-create a window in the app when the
|
||||
// dock icon is clicked and there are no other windows open.
|
||||
if (BrowserWindow.getAllWindows().length === 0) createWindow()
|
||||
})
|
||||
})
|
||||
|
||||
// Quit when all windows are closed, except on macOS. There, it's common
|
||||
// for applications and their menu bar to stay active until the user quits
|
||||
// explicitly with Cmd + Q.
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit()
|
||||
}
|
||||
})
|
||||
|
||||
// In this file you can include the rest of your app"s specific main process
|
||||
// code. You can also put them in separate files and require them here.
|
20
src/preload/index.js
Normal file
@ -0,0 +1,20 @@
|
||||
import { contextBridge } from 'electron'
|
||||
import { electronAPI } from '@electron-toolkit/preload'
|
||||
|
||||
// Custom APIs for renderer
|
||||
const api = {}
|
||||
|
||||
// Use `contextBridge` APIs to expose Electron APIs to
|
||||
// renderer only if context isolation is enabled, otherwise
|
||||
// just add to the DOM global.
|
||||
if (process.contextIsolated) {
|
||||
try {
|
||||
contextBridge.exposeInMainWorld('electron', electronAPI)
|
||||
contextBridge.exposeInMainWorld('api', api)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
} else {
|
||||
window.electron = electronAPI
|
||||
window.api = api
|
||||
}
|
18
src/renderer/index.html
Normal file
@ -0,0 +1,18 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>环境传感设备模拟器</title>
|
||||
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<meta
|
||||
http-equiv="Content-Security-Policy"
|
||||
content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:"
|
||||
/>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.js"></script>
|
||||
</body>
|
||||
</html>
|
257
src/renderer/src/App.vue
Normal file
@ -0,0 +1,257 @@
|
||||
<script setup>
|
||||
import { ref, watch } from 'vue';
|
||||
import axios from 'axios';
|
||||
|
||||
const api = ref('http://localhost:3000/api/device');
|
||||
const deviceToken = ref('554DCCEC37A0144FB3C4F78B19CAFD73'); // 新增设备 Token 的引用
|
||||
var devicecilent = null;
|
||||
|
||||
const deviceList = ref([
|
||||
{
|
||||
name: 'CS616 时域反射土壤含水量传感器',
|
||||
description: `技术参数
|
||||
l 探针间误差:±0.5% VWC(干燥土壤)±1.5% VWC(典型饱和土壤)
|
||||
l 精度:±2.5% VWC 采用标准校正,电导率≤0.5 dSm-1, 容积密度≤1.55gcm-3,测量范围由 0%VWC 至 50%VWC
|
||||
l 准确度:优于 0.1% VWC
|
||||
l 输出:±0.7V 方波,频率参考含水量
|
||||
l 功耗:65mA 12Vdc(激活状态下) 45μA(完全静止状态)
|
||||
l 供电电压:最小 5Vdc,最大 18Vdc
|
||||
l 激活电压:最小 4Vdc,最大 18Vdc
|
||||
l 电磁:兼容 CE,满足 EN61326 对静电放电防护的需求
|
||||
l 探针尺寸:长度:300mm(11.8 in) 直径:3.2mm(0.13 in) 间距:32mm(1.3 in)
|
||||
l 探头尺寸:高:85mm(3.3 in) 宽:63mm(2.5 in) 深:18 mm(0.7 in)
|
||||
l 重量:探头不含缆线:280g(9.9 oz) 缆线:35 g/m (0.38 oz/ft)`,
|
||||
log: '',
|
||||
value: 'CS616',
|
||||
img: '/src/assets/device/CS616.png',
|
||||
revalue: () => { return `{"VWC":${Math.random() * 50}}` }
|
||||
},
|
||||
{
|
||||
name: 'DHT11温湿度传感器',
|
||||
description: `DHT11 工作参数:
|
||||
湿度测量范围:20~90%RH
|
||||
湿度测量精度:±5%RH
|
||||
温度测量范围:0~50℃
|
||||
温度测量精度:±2℃
|
||||
工作电压:DC 3.3V/5V`,
|
||||
log: '',
|
||||
value: 'DHT11',
|
||||
img: '/src/assets/device/DHT11.jpeg',
|
||||
revalue: () => { return `{"temperature":${Math.random() * 50},"humidity":${Math.random() * 100}}` }
|
||||
},
|
||||
{
|
||||
name: 'HFP01(SC)热通量传感器',
|
||||
description: `主要技术参数
|
||||
传感器类型:热电偶
|
||||
量程:-2000~2000W/m2
|
||||
灵敏度:50μV/W/m2
|
||||
标称电阻:2Ω
|
||||
工作温度:-30℃~70℃
|
||||
尺寸:直径80mm,厚5mm
|
||||
重量:200g
|
||||
HFP01型
|
||||
传感器内阻:<0.00625km2/W
|
||||
精度:-15%~+5%(土壤内持续12小时)
|
||||
HFP01SC自标定型
|
||||
精度:±3%
|
||||
加热电阻:100Ω
|
||||
输入电压:9~15VDC
|
||||
输出电压:0~2VDC
|
||||
标定持续时间:±3分钟(1.5W时)
|
||||
平均功耗:0.02~0.04W
|
||||
产地:荷兰`,
|
||||
log: '',
|
||||
value: 'HFP01',
|
||||
img: '/src/assets/device/HFP01(SC).png',
|
||||
revalue: () => { return `{"heatflux":${Math.random() * 4000}}` }
|
||||
},
|
||||
{
|
||||
name: 'FST100-2006B 土壤PH值传感器',
|
||||
description: `测量范围3-9PH
|
||||
测量精度±0.3PH
|
||||
分辨率±0.1PH
|
||||
响应时间<15秒
|
||||
输出信号Rs485/4-20mA/0-5VDC/0-10VDC
|
||||
长期稳定性≤5%/年
|
||||
供电电压12~24VDC
|
||||
工作温度0°℃~55°℃
|
||||
密封材料:黑色阻燃环氧树脂
|
||||
电气连接:直接引线`,
|
||||
log: '',
|
||||
value: 'FST100-2006B',
|
||||
img: '/src/assets/device/FST100-2006B.png',
|
||||
revalue: () => { return `{"PH":${Math.random() * 6}}` }
|
||||
},
|
||||
{
|
||||
name: '科蓝带自动清洗浊度仪传感器KL680ZZ',
|
||||
description: `技术参数:
|
||||
1)测量范围:浊度:0-10NTU;0-400NTU;0-4000NTU 及可以扩展。污泥浓度:0-10mg/L;0-400mg/L;0-5000mg/L及可以扩展。
|
||||
2) 工作温度:0-60℃。
|
||||
3) 输出电流:4-20mA。
|
||||
4)通信接口:485。
|
||||
5)供电电源:12-24VDC(可提供电源转换器220VAC→12VDC)。
|
||||
6)外形尺寸:Φ50×262mm。
|
||||
7)介质压力:≥3Mpa 。
|
||||
8) 信号线缆:标配10米。
|
||||
9)安装方式:
|
||||
9.1)流通式(可配置流通池):
|
||||
a)外壳材质:PMMA;
|
||||
b) 过程连接:Φ12软管。
|
||||
9.2)沉入式(可配置连接杆和支架): a)外外壳材质:316不锈钢;b) 过程连接:NPT3/4。`,
|
||||
log: '',
|
||||
value: 'KL680ZZ',
|
||||
img: '/src/assets/device/KL680ZZ.jpg',
|
||||
revalue: () => { return `{"turbidity":${Math.random() * 4000},"sludge":${Math.random() * 5000}}` }
|
||||
},
|
||||
{
|
||||
name: '归一化植被指数(NDVI)测量仪',
|
||||
description: `技术参数
|
||||
校准系数(灵敏度的倒数) 逐个传感器校准,数据存储在固件中
|
||||
校准不确定性 ± 5 %
|
||||
波长范围 红光检测器650 nm ± 5 nm;半峰宽(FWHM)65 nm;NIR检测器 810 nm ± 5 nm;半峰宽(FWHM)65 nm
|
||||
测量范围 2倍全日照
|
||||
测量重复性 < 1 %
|
||||
长期漂移 每年< 2 %
|
||||
响应时间 < 0.6 s
|
||||
视场范围 向上180°,向下30°
|
||||
方向(余弦)响应 ± 2 % @ 45°, ± 5 % @ 75° 天顶角
|
||||
温度响应 < 0.1 % 每 ℃
|
||||
输出 SDI-12
|
||||
供电 5.5 ~ 24 V DC
|
||||
外壳 带有丙烯酸散射窗的阳极铝
|
||||
IP 防护 IP68
|
||||
工作环境 -40 ~ 70 ℃; 0 ~ 100 % RH
|
||||
尺寸
|
||||
S2-411-SS(向上):直径 30.5 mm, 高37 mm
|
||||
S2-412-SS(向下):直径 30.5 mm, 高34.5 m
|
||||
重量(包含5米缆线) 140 g
|
||||
缆线 5米屏蔽双绞线;TPR护套和不锈钢接口
|
||||
兼容数采(须另购) METER EM60 系列, ZL6 系列, ZSC, ProCheck, Campbell Scientific, NexSens, OTT, Eureka, Hydrolab, 以及其他 SDI-12 兼容设备`,
|
||||
log: '',
|
||||
value: 'NDVI',
|
||||
img: '/src/assets/device/NDVI.png',
|
||||
revalue: () => { return `{"NDVI":${Math.random()}}` }
|
||||
}
|
||||
|
||||
]);
|
||||
|
||||
const selectedDevice = ref(deviceList.value[0].value);
|
||||
|
||||
// 更新 selectedDevice 的值
|
||||
const updateSelectedDevice = (event) => {
|
||||
selectedDevice.value = event.target.value;
|
||||
};
|
||||
|
||||
// 根据 selectedDevice 获取当前设备信息
|
||||
const currentDevice = ref(deviceList.value[0]);
|
||||
|
||||
watch(selectedDevice, (newValue) => {
|
||||
currentDevice.value = deviceList.value.find(device => device.value === newValue);
|
||||
});
|
||||
|
||||
// 开始连接 API 地址和设备 Token
|
||||
const startApi = () => {
|
||||
console.log('API:', api.value);
|
||||
console.log('Device Token:', deviceToken.value);
|
||||
|
||||
// 连接采集平台
|
||||
currentDevice.value.log += `开始连接到 ${api.value}\n`;
|
||||
devicecilent = setInterval(() => {
|
||||
const data = currentDevice.value.revalue();
|
||||
const config = {
|
||||
method: 'post',
|
||||
url: api.value,
|
||||
headers: {
|
||||
'token': deviceToken.value,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
data: data
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
console.log(JSON.stringify(response.data));
|
||||
currentDevice.value.log += `${data}\n`;
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log(error);
|
||||
currentDevice.value.log += `${error.message}\n`;
|
||||
});
|
||||
}, 1000);
|
||||
};
|
||||
|
||||
const endApi = () => {
|
||||
currentDevice.value.log += `结束连接到 ${api.value}\n`;
|
||||
clearInterval(devicecilent);
|
||||
devicecilent = null;
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="max-w-4xl mx-auto bg-white rounded-lg shadow-lg p-6">
|
||||
<!-- 标题 -->
|
||||
<h1 class="text-3xl font-bold text-gray-800 mb-6">环境传感设备模拟器</h1>
|
||||
|
||||
<!-- 设备选择和 API 输入框 -->
|
||||
<div class="space-y-4 mb-8">
|
||||
<div>
|
||||
<label for="device-list" class="block text-sm font-medium text-gray-700">选择设备</label>
|
||||
<select id="device-list"
|
||||
class="mt-1 block w-full p-2 border border-gray-300 rounded-md shadow-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
|
||||
@change="updateSelectedDevice">
|
||||
<option v-for="device in deviceList" :key="device.value" :value="device.value">{{ device.name }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
<div class="flex-1">
|
||||
<label for="api-input" class="block text-sm font-medium text-gray-700">API 接口</label>
|
||||
<input type="text" id="api-input" placeholder="输入 API 接口地址" v-model="api"
|
||||
class="mt-1 block w-full p-2 border border-gray-300 rounded-md shadow-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
|
||||
</div>
|
||||
<div class="flex-1">
|
||||
<label for="token-input" class="block text-sm font-medium text-gray-700">设备 Token</label>
|
||||
<input type="text" id="token-input" placeholder="输入设备 Token" v-model="deviceToken"
|
||||
class="mt-1 block w-full p-2 border border-gray-300 rounded-md shadow-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
|
||||
</div>
|
||||
<div class="self-end">
|
||||
<button @click="startApi"
|
||||
class="px-4 py-2 bg-blue-500 text-white rounded-md hover:bg-blue-600 focus:ring-2 focus:ring-blue-500 focus:ring-offset-2">
|
||||
连接
|
||||
</button>
|
||||
<button @click="endApi"
|
||||
class="px-4 py-2 bg-red-500 text-white rounded-md hover:bg-red-600 focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 ml-2">
|
||||
停止
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 设备图片和参数 -->
|
||||
<div class="flex flex-col md:flex-row gap-6 mb-8">
|
||||
<!-- 左侧:设备图片 -->
|
||||
<div class="flex-2">
|
||||
<div class="overflow-hidden rounded-lg shadow-md">
|
||||
<img :src="currentDevice.img" alt="设备图片"
|
||||
class="w-full h-64 object-cover transition-transform duration-300 hover:scale-105">
|
||||
</div>
|
||||
</div>
|
||||
<!-- 右侧:设备参数 -->
|
||||
<div class="flex-1">
|
||||
<h2 class="text-xl font-semibold text-gray-800 mb-4">设备参数</h2>
|
||||
<textarea id="data-display" rows="8"
|
||||
class="w-full p-3 border border-gray-300 rounded-md shadow-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
|
||||
readonly>{{ currentDevice.description }}
|
||||
</textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 设备日志 -->
|
||||
<div>
|
||||
<h2 class="text-xl font-semibold text-gray-800 mb-4">设备日志</h2>
|
||||
<textarea id="data-display" rows="6"
|
||||
class="w-full p-3 border border-gray-300 rounded-md shadow-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
|
||||
readonly>{{ currentDevice.log }}
|
||||
</textarea>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
BIN
src/renderer/src/assets/device/CS616.png
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
src/renderer/src/assets/device/DHT11.jpeg
Normal file
After Width: | Height: | Size: 630 KiB |
BIN
src/renderer/src/assets/device/FST100-2006B.png
Normal file
After Width: | Height: | Size: 37 KiB |
BIN
src/renderer/src/assets/device/HFP01(SC).png
Normal file
After Width: | Height: | Size: 59 KiB |
BIN
src/renderer/src/assets/device/KL680ZZ.jpg
Normal file
After Width: | Height: | Size: 19 KiB |
BIN
src/renderer/src/assets/device/NDVI.png
Normal file
After Width: | Height: | Size: 75 KiB |
10
src/renderer/src/assets/electron.svg
Normal file
@ -0,0 +1,10 @@
|
||||
<svg viewBox="0 0 128 128" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<circle cx="64" cy="64" r="64" fill="#2F3242"/>
|
||||
<ellipse cx="63.9835" cy="23.2036" rx="4.48794" ry="4.495" stroke="#A2ECFB" stroke-width="3.6" stroke-linecap="round"/>
|
||||
<path d="M51.3954 39.5028C52.3733 39.6812 53.3108 39.033 53.4892 38.055C53.6676 37.0771 53.0194 36.1396 52.0414 35.9612L51.3954 39.5028ZM28.6153 43.5751L30.1748 44.4741L30.1748 44.4741L28.6153 43.5751ZM28.9393 60.9358C29.4332 61.7985 30.5329 62.0976 31.3957 61.6037C32.2585 61.1098 32.5575 60.0101 32.0636 59.1473L28.9393 60.9358ZM37.6935 66.7457C37.025 66.01 35.8866 65.9554 35.1508 66.6239C34.415 67.2924 34.3605 68.4308 35.029 69.1666L37.6935 66.7457ZM53.7489 81.7014L52.8478 83.2597L53.7489 81.7014ZM96.9206 89.515C97.7416 88.9544 97.9526 87.8344 97.3919 87.0135C96.8313 86.1925 95.7113 85.9815 94.8904 86.5422L96.9206 89.515ZM52.0414 35.9612C46.4712 34.9451 41.2848 34.8966 36.9738 35.9376C32.6548 36.9806 29.0841 39.1576 27.0559 42.6762L30.1748 44.4741C31.5693 42.0549 34.1448 40.3243 37.8188 39.4371C41.5009 38.5479 46.1547 38.5468 51.3954 39.5028L52.0414 35.9612ZM27.0559 42.6762C24.043 47.9029 25.2781 54.5399 28.9393 60.9358L32.0636 59.1473C28.6579 53.1977 28.1088 48.0581 30.1748 44.4741L27.0559 42.6762ZM35.029 69.1666C39.6385 74.24 45.7158 79.1355 52.8478 83.2597L54.6499 80.1432C47.8081 76.1868 42.0298 71.5185 37.6935 66.7457L35.029 69.1666ZM52.8478 83.2597C61.344 88.1726 70.0465 91.2445 77.7351 92.3608C85.359 93.4677 92.2744 92.6881 96.9206 89.515L94.8904 86.5422C91.3255 88.9767 85.4902 89.849 78.2524 88.7982C71.0793 87.7567 62.809 84.8612 54.6499 80.1432L52.8478 83.2597ZM105.359 84.9077C105.359 81.4337 102.546 78.6127 99.071 78.6127V82.2127C100.553 82.2127 101.759 83.4166 101.759 84.9077H105.359ZM99.071 78.6127C95.5956 78.6127 92.7831 81.4337 92.7831 84.9077H96.3831C96.3831 83.4166 97.5892 82.2127 99.071 82.2127V78.6127ZM92.7831 84.9077C92.7831 88.3817 95.5956 91.2027 99.071 91.2027V87.6027C97.5892 87.6027 96.3831 86.3988 96.3831 84.9077H92.7831ZM99.071 91.2027C102.546 91.2027 105.359 88.3817 105.359 84.9077H101.759C101.759 86.3988 100.553 87.6027 99.071 87.6027V91.2027Z" fill="#A2ECFB"/>
|
||||
<path d="M91.4873 65.382C90.8456 66.1412 90.9409 67.2769 91.7002 67.9186C92.4594 68.5603 93.5951 68.465 94.2368 67.7058L91.4873 65.382ZM99.3169 43.6354L97.7574 44.5344L99.3169 43.6354ZM84.507 35.2412C83.513 35.2282 82.6967 36.0236 82.6838 37.0176C82.6708 38.0116 83.4661 38.8279 84.4602 38.8409L84.507 35.2412ZM74.9407 39.8801C75.9127 39.6716 76.5315 38.7145 76.323 37.7425C76.1144 36.7706 75.1573 36.1517 74.1854 36.3603L74.9407 39.8801ZM53.7836 46.3728L54.6847 47.931L53.7836 46.3728ZM25.5491 80.9047C25.6932 81.8883 26.6074 82.5688 27.5911 82.4247C28.5747 82.2806 29.2552 81.3664 29.1111 80.3828L25.5491 80.9047ZM94.2368 67.7058C97.8838 63.3907 100.505 58.927 101.752 54.678C103.001 50.4213 102.9 46.2472 100.876 42.7365L97.7574 44.5344C99.1494 46.9491 99.3603 50.0419 98.2974 53.6644C97.2323 57.2945 94.9184 61.3223 91.4873 65.382L94.2368 67.7058ZM100.876 42.7365C97.9119 37.5938 91.7082 35.335 84.507 35.2412L84.4602 38.8409C91.1328 38.9278 95.7262 41.0106 97.7574 44.5344L100.876 42.7365ZM74.1854 36.3603C67.4362 37.8086 60.0878 40.648 52.8826 44.8146L54.6847 47.931C61.5972 43.9338 68.5948 41.2419 74.9407 39.8801L74.1854 36.3603ZM52.8826 44.8146C44.1366 49.872 36.9669 56.0954 32.1491 62.3927C27.3774 68.63 24.7148 75.2115 25.5491 80.9047L29.1111 80.3828C28.4839 76.1026 30.4747 70.5062 35.0084 64.5802C39.496 58.7143 46.2839 52.7889 54.6847 47.931L52.8826 44.8146Z" fill="#A2ECFB"/>
|
||||
<path d="M49.0825 87.2295C48.7478 86.2934 47.7176 85.8059 46.7816 86.1406C45.8455 86.4753 45.358 87.5055 45.6927 88.4416L49.0825 87.2295ZM78.5635 96.4256C79.075 95.5732 78.7988 94.4675 77.9464 93.9559C77.0941 93.4443 75.9884 93.7205 75.4768 94.5729L78.5635 96.4256ZM79.5703 85.1795C79.2738 86.1284 79.8027 87.1379 80.7516 87.4344C81.7004 87.7308 82.71 87.2019 83.0064 86.2531L79.5703 85.1795ZM84.3832 64.0673H82.5832H84.3832ZM69.156 22.5301C68.2477 22.1261 67.1838 22.535 66.7799 23.4433C66.3759 24.3517 66.7848 25.4155 67.6931 25.8194L69.156 22.5301ZM45.6927 88.4416C47.5994 93.7741 50.1496 98.2905 53.2032 101.505C56.2623 104.724 59.9279 106.731 63.9835 106.731V103.131C61.1984 103.131 58.4165 101.765 55.8131 99.0249C53.2042 96.279 50.8768 92.2477 49.0825 87.2295L45.6927 88.4416ZM63.9835 106.731C69.8694 106.731 74.8921 102.542 78.5635 96.4256L75.4768 94.5729C72.0781 100.235 68.0122 103.131 63.9835 103.131V106.731ZM83.0064 86.2531C85.0269 79.7864 86.1832 72.1831 86.1832 64.0673H82.5832C82.5832 71.8536 81.4723 79.0919 79.5703 85.1795L83.0064 86.2531ZM86.1832 64.0673C86.1832 54.1144 84.4439 44.922 81.4961 37.6502C78.5748 30.4436 74.3436 24.8371 69.156 22.5301L67.6931 25.8194C71.6364 27.5731 75.3846 32.1564 78.1598 39.0026C80.9086 45.7836 82.5832 54.507 82.5832 64.0673H86.1832Z" fill="#A2ECFB"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M103.559 84.9077C103.559 82.4252 101.55 80.4127 99.071 80.4127C96.5924 80.4127 94.5831 82.4252 94.5831 84.9077C94.5831 87.3902 96.5924 89.4027 99.071 89.4027C101.55 89.4027 103.559 87.3902 103.559 84.9077V84.9077Z" stroke="#A2ECFB" stroke-width="3.6" stroke-linecap="round"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M28.8143 89.4027C31.2929 89.4027 33.3023 87.3902 33.3023 84.9077C33.3023 82.4252 31.2929 80.4127 28.8143 80.4127C26.3357 80.4127 24.3264 82.4252 24.3264 84.9077C24.3264 87.3902 26.3357 89.4027 28.8143 89.4027V89.4027V89.4027Z" stroke="#A2ECFB" stroke-width="3.6" stroke-linecap="round"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M64.8501 68.0857C62.6341 68.5652 60.451 67.1547 59.9713 64.9353C59.4934 62.7159 60.9007 60.5293 63.1167 60.0489C65.3326 59.5693 67.5157 60.9798 67.9954 63.1992C68.4742 65.4186 67.066 67.6052 64.8501 68.0857Z" fill="#A2ECFB"/>
|
||||
</svg>
|
After Width: | Height: | Size: 5.7 KiB |
0
src/renderer/src/assets/main.css
Normal file
6
src/renderer/src/main.js
Normal file
@ -0,0 +1,6 @@
|
||||
import './assets/main.css'
|
||||
|
||||
import { createApp } from 'vue'
|
||||
import App from './App.vue'
|
||||
|
||||
createApp(App).mount('#app')
|