fix: 修改前端样式
This commit is contained in:
parent
86f731b76c
commit
ee338d2a09
129
db.go
129
db.go
@ -9,12 +9,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var db *sql.DB
|
var db *sql.DB
|
||||||
|
|
||||||
const SCALING_FACTOR = 1000 // 浮点数到整数的转换因子
|
const SCALING_FACTOR = 1000 // 浮点数到整数的转换因子
|
||||||
|
|
||||||
// 初始化数据库连接
|
// 初始化数据库连接
|
||||||
func InitDB() error {
|
func InitDB() error {
|
||||||
username := "root"
|
username := "root"
|
||||||
password := "root" // 请替换为你的实际密码
|
password := "root"
|
||||||
host := "localhost"
|
host := "localhost"
|
||||||
port := "3306"
|
port := "3306"
|
||||||
dbName := "probe_db"
|
dbName := "probe_db"
|
||||||
@ -60,101 +61,101 @@ func SaveSensorData(sensorID int, x, y, z float64) error {
|
|||||||
|
|
||||||
// 获取传感器数据 - 添加时间范围
|
// 获取传感器数据 - 添加时间范围
|
||||||
func GetSensorData(sensorID int, limit int, startDate time.Time, endDate time.Time) ([]SensorData, error) {
|
func GetSensorData(sensorID int, limit int, startDate time.Time, endDate time.Time) ([]SensorData, error) {
|
||||||
query := `SELECT id, sensor_id, x_value, y_value, z_value,
|
query := `SELECT id, sensor_id, x_value, y_value, z_value,
|
||||||
timestamp as timestamp
|
timestamp as timestamp
|
||||||
FROM sensor_data
|
FROM sensor_data
|
||||||
WHERE sensor_id = ?`
|
WHERE sensor_id = ?`
|
||||||
|
|
||||||
var args []interface{}
|
var args []interface{}
|
||||||
args = append(args, sensorID)
|
args = append(args, sensorID)
|
||||||
|
|
||||||
if !startDate.IsZero() {
|
if !startDate.IsZero() {
|
||||||
query += " AND timestamp >= ?"
|
query += " AND timestamp >= ?"
|
||||||
args = append(args, startDate)
|
args = append(args, startDate)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !endDate.IsZero() {
|
if !endDate.IsZero() {
|
||||||
query += " AND timestamp <= ?"
|
query += " AND timestamp <= ?"
|
||||||
args = append(args, endDate)
|
args = append(args, endDate)
|
||||||
}
|
}
|
||||||
|
|
||||||
query += " ORDER BY timestamp DESC LIMIT ?"
|
query += " ORDER BY timestamp DESC LIMIT ?"
|
||||||
args = append(args, limit)
|
args = append(args, limit)
|
||||||
|
|
||||||
rows, err := db.Query(query, args...)
|
rows, err := db.Query(query, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
||||||
var result []SensorData
|
var result []SensorData
|
||||||
|
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var data SensorData
|
var data SensorData
|
||||||
var xInt, yInt, zInt int
|
var xInt, yInt, zInt int
|
||||||
|
|
||||||
err := rows.Scan(&data.ID, &data.SensorID, &xInt, &yInt, &zInt, &data.Timestamp)
|
err := rows.Scan(&data.ID, &data.SensorID, &xInt, &yInt, &zInt, &data.Timestamp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
data.X = float64(xInt) / SCALING_FACTOR
|
data.X = float64(xInt) / SCALING_FACTOR
|
||||||
data.Y = float64(yInt) / SCALING_FACTOR
|
data.Y = float64(yInt) / SCALING_FACTOR
|
||||||
data.Z = float64(zInt) / SCALING_FACTOR
|
data.Z = float64(zInt) / SCALING_FACTOR
|
||||||
|
|
||||||
result = append(result, data)
|
result = append(result, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取所有传感器数据
|
// 获取所有传感器数据
|
||||||
func GetAllSensorData(limit int, startDate time.Time, endDate time.Time) ([]SensorData, error) {
|
func GetAllSensorData(limit int, startDate time.Time, endDate time.Time) ([]SensorData, error) {
|
||||||
query := `SELECT id, sensor_id, x_value, y_value, z_value,
|
query := `SELECT id, sensor_id, x_value, y_value, z_value,
|
||||||
timestamp as timestamp
|
timestamp as timestamp
|
||||||
FROM sensor_data
|
FROM sensor_data
|
||||||
WHERE 1=1`
|
WHERE 1=1`
|
||||||
|
|
||||||
var args []interface{}
|
var args []interface{}
|
||||||
|
|
||||||
if !startDate.IsZero() {
|
if !startDate.IsZero() {
|
||||||
query += " AND timestamp >= ?"
|
query += " AND timestamp >= ?"
|
||||||
args = append(args, startDate)
|
args = append(args, startDate)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !endDate.IsZero() {
|
if !endDate.IsZero() {
|
||||||
query += " AND timestamp <= ?"
|
query += " AND timestamp <= ?"
|
||||||
args = append(args, endDate)
|
args = append(args, endDate)
|
||||||
}
|
}
|
||||||
|
|
||||||
query += " ORDER BY timestamp DESC LIMIT ?"
|
query += " ORDER BY timestamp DESC LIMIT ?"
|
||||||
args = append(args, limit)
|
args = append(args, limit)
|
||||||
|
|
||||||
rows, err := db.Query(query, args...)
|
rows, err := db.Query(query, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
||||||
var result []SensorData
|
var result []SensorData
|
||||||
|
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var data SensorData
|
var data SensorData
|
||||||
var xInt, yInt, zInt int
|
var xInt, yInt, zInt int
|
||||||
|
|
||||||
err := rows.Scan(&data.ID, &data.SensorID, &xInt, &yInt, &zInt, &data.Timestamp)
|
err := rows.Scan(&data.ID, &data.SensorID, &xInt, &yInt, &zInt, &data.Timestamp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
data.X = float64(xInt) / SCALING_FACTOR
|
data.X = float64(xInt) / SCALING_FACTOR
|
||||||
data.Y = float64(yInt) / SCALING_FACTOR
|
data.Y = float64(yInt) / SCALING_FACTOR
|
||||||
data.Z = float64(zInt) / SCALING_FACTOR
|
data.Z = float64(zInt) / SCALING_FACTOR
|
||||||
|
|
||||||
result = append(result, data)
|
result = append(result, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取所有传感器ID
|
// 获取所有传感器ID
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="zh-CN">
|
<html lang="zh-CN">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
@ -32,7 +32,8 @@
|
|||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
border: 1px solid #ddd;
|
border: 1px solid #ddd;
|
||||||
border-radius: 1px;
|
border-radius: 4px;
|
||||||
|
background-color: #fff;
|
||||||
}
|
}
|
||||||
|
|
||||||
.control-group {
|
.control-group {
|
||||||
@ -42,18 +43,30 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
select, input, button {
|
select, input, button {
|
||||||
padding: 5px;
|
padding: 5px 10px;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
button {
|
button {
|
||||||
|
background-color: #007bff;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
transition: background-color 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
button:hover {
|
||||||
|
background-color: #0056b3;
|
||||||
}
|
}
|
||||||
|
|
||||||
.chart-container {
|
.chart-container {
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
border: 1px solid #ddd;
|
border: 1px solid #ddd;
|
||||||
border-radius: 1px;
|
border-radius: 4px;
|
||||||
padding: 10px;
|
padding: 15px;
|
||||||
|
background-color: #fff;
|
||||||
}
|
}
|
||||||
|
|
||||||
canvas {
|
canvas {
|
||||||
@ -63,13 +76,17 @@
|
|||||||
|
|
||||||
.table-container {
|
.table-container {
|
||||||
overflow-x: auto;
|
overflow-x: auto;
|
||||||
margin-bottom: 20px;
|
margin-top: 20px;
|
||||||
border: 1px solid #ddd;
|
border: 1px solid #ddd;
|
||||||
border-radius: 5px;
|
border-radius: 4px;
|
||||||
padding: 10px;
|
background-color: #fff;
|
||||||
|
padding: 15px;
|
||||||
}
|
}
|
||||||
h2{
|
h2{
|
||||||
text-align:center;
|
text-align:center;
|
||||||
|
color: #333;
|
||||||
|
margin-top: 0;
|
||||||
|
margin-bottom: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
table {
|
table {
|
||||||
@ -79,18 +96,23 @@
|
|||||||
|
|
||||||
th, td {
|
th, td {
|
||||||
border: 1px solid #ddd;
|
border: 1px solid #ddd;
|
||||||
padding: 8px;
|
padding: 12px 8px;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
th {
|
th {
|
||||||
background-color: #f8f8f8;
|
background-color: #f8f9fa;
|
||||||
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
tr:nth-child(even) {
|
tr:nth-child(even) {
|
||||||
background-color: #f9f9f9;
|
background-color: #f9f9f9;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tr:hover {
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
}
|
||||||
|
|
||||||
.footer {
|
.footer {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
@ -100,11 +122,14 @@
|
|||||||
@media (max-width: 768px) {
|
@media (max-width: 768px) {
|
||||||
.controls {
|
.controls {
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: stretch;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.control-group {
|
.control-group {
|
||||||
justify-content: space-between;
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
select, input {
|
||||||
|
width: 100%;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user