From b670e06bc93e579aa5c3330cf38bedfe1d66fe9c Mon Sep 17 00:00:00 2001
From: Ironsp <1522278303@qq.com>
Date: Thu, 10 Sep 2026 10:08:56 +0800
Subject: [PATCH] =?UTF-8?q?feat=20=E6=B7=BB=E5=8A=A0mock=E6=95=B0=E6=8D=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/components/home/deviceFooter.vue | 16 ++-
src/service/index.ts | 7 ++
src/service/project.ts | 51 +++++++--
src/service/rtkTrack.ts | 59 +++++++---
src/service/seed.ts | 163 +++++++++++++++++++++++++++
src/service/warningRecord.ts | 65 +++++++++--
src/service/workRecord.ts | 64 ++++++++---
src/store/modules/db.ts | 106 +++++++++++++++++
8 files changed, 482 insertions(+), 49 deletions(-)
create mode 100644 src/service/seed.ts
create mode 100644 src/store/modules/db.ts
diff --git a/src/components/home/deviceFooter.vue b/src/components/home/deviceFooter.vue
index a7ce2a0..1b496f7 100644
--- a/src/components/home/deviceFooter.vue
+++ b/src/components/home/deviceFooter.vue
@@ -1,12 +1,26 @@
diff --git a/src/service/index.ts b/src/service/index.ts
index 52438cc..e9c8570 100644
--- a/src/service/index.ts
+++ b/src/service/index.ts
@@ -5,9 +5,16 @@ import { warningRecordTableSql } from './warningRecord'
import { workRecordTableSql } from './workRecord'
export { projectTableSql } from './project'
+// 导出所有 service 方法
+export * as projectService from './project'
export { rtkTrackTableSql } from './rtkTrack'
+export * as rtkTrackService from './rtkTrack'
+export { seedAll } from './seed'
+
export { warningRecordTableSql } from './warningRecord'
+export * as warningRecordService from './warningRecord'
export { workRecordTableSql } from './workRecord'
+export * as workRecordService from './workRecord'
const tableSqls = [
projectTableSql,
diff --git a/src/service/project.ts b/src/service/project.ts
index 790b90a..8ec2ae1 100644
--- a/src/service/project.ts
+++ b/src/service/project.ts
@@ -1,11 +1,7 @@
-/**
- * 项目信息表: 项目名称,压路机名称, (平板)设备ID, 开始时间, 结束时间,
- * 字段说明:
- * - id:项目唯一标识符
- * - project_name:项目名称
- * - project_type:项目类型
- * - status:项目状态(默认值为 'offline')
- */
+import DB from '@/utils/sqlite'
+
+const TABLE = 'project'
+
export const projectTableSql = `CREATE TABLE IF NOT EXISTS project (
id INTEGER PRIMARY KEY AUTOINCREMENT,
project_name TEXT NOT NULL,
@@ -14,3 +10,42 @@ export const projectTableSql = `CREATE TABLE IF NOT EXISTS project (
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
)`
+
+export interface Project {
+ id?: number
+ project_name: string
+ project_type?: string
+ status?: string
+ created_at?: string
+ updated_at?: string
+}
+
+/** 查询全部项目 */
+export async function selectAll(): Promise {
+ return DB.select(TABLE)
+}
+
+/** 按 ID 查询 */
+export async function selectById(id: number): Promise {
+ return DB.selectById(TABLE, id)
+}
+
+/** 按状态查询 */
+export async function selectByStatus(status: string): Promise {
+ return DB.selectByField(TABLE, 'status', status)
+}
+
+/** 新增项目 */
+export async function insert(data: Project): Promise {
+ return DB.insert(TABLE, data)
+}
+
+/** 更新项目 */
+export async function update(id: number, data: Partial): Promise {
+ return DB.update(TABLE, data, `id = ${id}`)
+}
+
+/** 删除项目 */
+export async function remove(id: number): Promise {
+ return DB.delete(TABLE, `id = ${id}`)
+}
diff --git a/src/service/rtkTrack.ts b/src/service/rtkTrack.ts
index abd8ebd..3ef2388 100644
--- a/src/service/rtkTrack.ts
+++ b/src/service/rtkTrack.ts
@@ -1,16 +1,7 @@
-/**
- * RTK 轨迹数据表: 作业记录ID, 时间戳, , 压实度, 纬度, 经度, 高度, 速度, 方向, 创建时间, 外键约束
- * 字段说明:
- * - id:轨迹唯一标识符
- * - work_record_id:作业记录 ID
- * - timestamp:时间戳
- * - latitude:纬度
- * - longitude:经度
- * - altitude:高度
- * - speed:速度
- * - heading:方向
- * - created_at:记录创建时间(默认值为当前时间)
- */
+import DB from '@/utils/sqlite'
+
+const TABLE = 'rtk_track'
+
export const rtkTrackTableSql = `CREATE TABLE IF NOT EXISTS rtk_track (
id INTEGER PRIMARY KEY AUTOINCREMENT,
work_record_id INTEGER,
@@ -23,3 +14,45 @@ export const rtkTrackTableSql = `CREATE TABLE IF NOT EXISTS rtk_track (
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (work_record_id) REFERENCES work_record(id)
)`
+
+export interface RtkTrack {
+ id?: number
+ work_record_id: number
+ timestamp?: string
+ latitude?: number
+ longitude?: number
+ altitude?: number
+ speed?: number
+ heading?: number
+ created_at?: string
+}
+
+/** 查询全部 */
+export async function selectAll(): Promise {
+ return DB.select(TABLE)
+}
+
+/** 按 ID 查询 */
+export async function selectById(id: number): Promise {
+ return DB.selectById(TABLE, id)
+}
+
+/** 按作业记录 ID 查询 */
+export async function selectByWorkRecordId(workRecordId: number): Promise {
+ return DB.selectByField(TABLE, 'work_record_id', workRecordId)
+}
+
+/** 新增 */
+export async function insert(data: RtkTrack): Promise {
+ return DB.insert(TABLE, data)
+}
+
+/** 更新 */
+export async function update(id: number, data: Partial): Promise {
+ return DB.update(TABLE, data, `id = ${id}`)
+}
+
+/** 删除 */
+export async function remove(id: number): Promise {
+ return DB.delete(TABLE, `id = ${id}`)
+}
diff --git a/src/service/seed.ts b/src/service/seed.ts
new file mode 100644
index 0000000..7dba5fe
--- /dev/null
+++ b/src/service/seed.ts
@@ -0,0 +1,163 @@
+import DB from '@/utils/sqlite'
+
+/**
+ * 插入项目假数据(3条)
+ */
+async function seedProject() {
+ const data = [
+ {
+ project_name: '京雄高速河北段',
+ project_type: '高速公路',
+ status: 'online',
+ },
+ {
+ project_name: '雄安新区市政道路',
+ project_type: '市政工程',
+ status: 'online',
+ },
+ {
+ project_name: '白沟产业园场地',
+ project_type: '场地平整',
+ status: 'offline',
+ },
+ ]
+
+ for (const item of data) {
+ await DB.insert('project', item)
+ }
+}
+
+/**
+ * 插入作业记录假数据(3条)
+ */
+async function seedWorkRecord() {
+ const data = [
+ {
+ project_id: 1,
+ start_time: '2026-09-10 08:00:00',
+ end_time: '2026-09-10 12:00:00',
+ speed: 5.2,
+ frequency: 28.5,
+ amplitude: 1.8,
+ compaction_value: 92.3,
+ gps_lat: 38.9697,
+ gps_lng: 115.9697,
+ },
+ {
+ project_id: 1,
+ start_time: '2026-09-10 13:00:00',
+ end_time: '2026-09-10 17:30:00',
+ speed: 4.8,
+ frequency: 30.0,
+ amplitude: 2.0,
+ compaction_value: 95.1,
+ gps_lat: 38.9712,
+ gps_lng: 115.9712,
+ },
+ {
+ project_id: 2,
+ start_time: '2026-09-09 07:30:00',
+ end_time: '2026-09-09 11:30:00',
+ speed: 6.0,
+ frequency: 25.0,
+ amplitude: 1.5,
+ compaction_value: 88.7,
+ gps_lat: 38.9534,
+ gps_lng: 115.9534,
+ },
+ ]
+
+ for (const item of data) {
+ await DB.insert('work_record', item)
+ }
+}
+
+/**
+ * 插入 RTK 轨迹假数据(3条)
+ */
+async function seedRtkTrack() {
+ const data = [
+ {
+ work_record_id: 1,
+ timestamp: '2026-09-10 08:00:05',
+ latitude: 38.9697,
+ longitude: 115.9697,
+ altitude: 15.2,
+ speed: 5.1,
+ heading: 90.0,
+ },
+ {
+ work_record_id: 1,
+ timestamp: '2026-09-10 08:00:10',
+ latitude: 38.9698,
+ longitude: 115.9699,
+ altitude: 15.3,
+ speed: 5.2,
+ heading: 92.5,
+ },
+ {
+ work_record_id: 2,
+ timestamp: '2026-09-10 13:00:05',
+ latitude: 38.9712,
+ longitude: 115.9712,
+ altitude: 16.0,
+ speed: 4.7,
+ heading: 180.0,
+ },
+ ]
+
+ for (const item of data) {
+ await DB.insert('rtk_track', item)
+ }
+}
+
+/**
+ * 插入告警记录假数据(3条)
+ */
+async function seedWarningRecord() {
+ const data = [
+ {
+ project_id: 1,
+ warning_type: '超速',
+ warning_level: 'high',
+ message: '碾压速度超过设定阈值(6.5km/h)',
+ is_read: 0,
+ },
+ {
+ project_id: 2,
+ warning_type: '漏压',
+ warning_level: 'medium',
+ message: 'K2+350处检测到漏压区域',
+ is_read: 0,
+ },
+ {
+ project_id: 1,
+ warning_type: '偏航',
+ warning_level: 'low',
+ message: 'RTK信号偏移超过2cm',
+ is_read: 1,
+ },
+ ]
+
+ for (const item of data) {
+ await DB.insert('warning_record', item)
+ }
+}
+
+/**
+ * 初始化所有假数据
+ */
+export async function seedAll() {
+ try {
+ console.log('开始插入假数据...')
+ await seedProject()
+ await seedWorkRecord()
+ await seedRtkTrack()
+ await seedWarningRecord()
+ console.log('假数据插入完成')
+ }
+ catch (err) {
+ console.error('假数据插入失败:', err)
+ throw err
+ }
+}
diff --git a/src/service/warningRecord.ts b/src/service/warningRecord.ts
index a45eefc..8189363 100644
--- a/src/service/warningRecord.ts
+++ b/src/service/warningRecord.ts
@@ -1,14 +1,7 @@
-/**
- * 告警记录表
- * 字段说明:
- * - id:告警记录唯一标识符
- * - project_id:项目 ID
- * - warning_type:告警类型
- * - warning_level:告警等级
- * - message:告警信息
- * - is_read:是否已读(0 表示未读,1 表示已读,默认值为 0)
- * - created_at:创建时间(默认值为当前时间)
- */
+import DB from '@/utils/sqlite'
+
+const TABLE = 'warning_record'
+
export const warningRecordTableSql = `CREATE TABLE IF NOT EXISTS warning_record (
id INTEGER PRIMARY KEY AUTOINCREMENT,
project_id INTEGER,
@@ -19,3 +12,53 @@ export const warningRecordTableSql = `CREATE TABLE IF NOT EXISTS warning_record
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (project_id) REFERENCES project(id)
)`
+
+export interface WarningRecord {
+ id?: number
+ project_id: number
+ warning_type?: string
+ warning_level?: string
+ message?: string
+ is_read?: number
+ created_at?: string
+}
+
+/** 查询全部 */
+export async function selectAll(): Promise {
+ return DB.select(TABLE)
+}
+
+/** 按 ID 查询 */
+export async function selectById(id: number): Promise {
+ return DB.selectById(TABLE, id)
+}
+
+/** 按项目 ID 查询 */
+export async function selectByProjectId(projectId: number): Promise {
+ return DB.selectByField(TABLE, 'project_id', projectId)
+}
+
+/** 查询未读 */
+export async function selectUnread(): Promise {
+ return DB.select(TABLE, '*', 'is_read = 0')
+}
+
+/** 新增 */
+export async function insert(data: WarningRecord): Promise {
+ return DB.insert(TABLE, data)
+}
+
+/** 标记已读 */
+export async function markRead(id: number): Promise {
+ return DB.update(TABLE, { is_read: 1 }, `id = ${id}`)
+}
+
+/** 更新 */
+export async function update(id: number, data: Partial): Promise {
+ return DB.update(TABLE, data, `id = ${id}`)
+}
+
+/** 删除 */
+export async function remove(id: number): Promise {
+ return DB.delete(TABLE, `id = ${id}`)
+}
diff --git a/src/service/workRecord.ts b/src/service/workRecord.ts
index 69d5925..878d558 100644
--- a/src/service/workRecord.ts
+++ b/src/service/workRecord.ts
@@ -1,19 +1,7 @@
-/**
- * 作业记录表
- * 字段说明:
- * -id:作业记录唯一标识符
- * -project_id:所属项目ID
- * -start_time:作业开始时间
- * -end_time:作业结束时间
- * -speed:作业速度
- * -frequency:作业频率
- * -amplitude:作业振幅
- * -compaction_value:压实度值
- * -gps_lat:GPS纬度
- * -gps_lng:GPS经度
- * -created_at:记录创建时间(默认值为当前时间)
- * -FOREIGN KEY (project_id) REFERENCES project(id):外键约束,关联到项目表中的id字段
- */
+import DB from '@/utils/sqlite'
+
+const TABLE = 'work_record'
+
export const workRecordTableSql = `CREATE TABLE IF NOT EXISTS work_record (
id INTEGER PRIMARY KEY AUTOINCREMENT,
project_id INTEGER,
@@ -28,3 +16,47 @@ export const workRecordTableSql = `CREATE TABLE IF NOT EXISTS work_record (
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (project_id) REFERENCES project(id)
)`
+
+export interface WorkRecord {
+ id?: number
+ project_id: number
+ start_time?: string
+ end_time?: string
+ speed?: number
+ frequency?: number
+ amplitude?: number
+ compaction_value?: number
+ gps_lat?: number
+ gps_lng?: number
+ created_at?: string
+}
+
+/** 查询全部 */
+export async function selectAll(): Promise {
+ return DB.select(TABLE)
+}
+
+/** 按 ID 查询 */
+export async function selectById(id: number): Promise {
+ return DB.selectById(TABLE, id)
+}
+
+/** 按项目 ID 查询 */
+export async function selectByProjectId(projectId: number): Promise {
+ return DB.selectByField(TABLE, 'project_id', projectId)
+}
+
+/** 新增 */
+export async function insert(data: WorkRecord): Promise {
+ return DB.insert(TABLE, data)
+}
+
+/** 更新 */
+export async function update(id: number, data: Partial): Promise {
+ return DB.update(TABLE, data, `id = ${id}`)
+}
+
+/** 删除 */
+export async function remove(id: number): Promise {
+ return DB.delete(TABLE, `id = ${id}`)
+}
diff --git a/src/store/modules/db.ts b/src/store/modules/db.ts
new file mode 100644
index 0000000..6382bf7
--- /dev/null
+++ b/src/store/modules/db.ts
@@ -0,0 +1,106 @@
+import type { Project } from '@/service/project'
+import type { RtkTrack } from '@/service/rtkTrack'
+import type { WarningRecord } from '@/service/warningRecord'
+import type { WorkRecord } from '@/service/workRecord'
+import { defineStore } from 'pinia'
+import { ref } from 'vue'
+import {
+ projectService,
+ rtkTrackService,
+ warningRecordService,
+ workRecordService,
+} from '@/service'
+
+export const useDbStore = defineStore('db', () => {
+ // --- State ---
+ const projects = ref([])
+ const workRecords = ref([])
+ const rtkTracks = ref([])
+ const warningRecords = ref([])
+
+ // --- Project ---
+ async function loadProjects() {
+ projects.value = await projectService.selectAll()
+ }
+
+ async function addProject(data: Project) {
+ await projectService.insert(data)
+ await loadProjects()
+ }
+
+ async function updateProject(id: number, data: Partial) {
+ await projectService.update(id, data)
+ await loadProjects()
+ }
+
+ async function deleteProject(id: number) {
+ await projectService.remove(id)
+ await loadProjects()
+ }
+
+ // --- WorkRecord ---
+ async function loadWorkRecords() {
+ workRecords.value = await workRecordService.selectAll()
+ }
+
+ async function loadWorkRecordsByProject(projectId: number) {
+ workRecords.value = await workRecordService.selectByProjectId(projectId)
+ }
+
+ async function addWorkRecord(data: WorkRecord) {
+ await workRecordService.insert(data)
+ await loadWorkRecords()
+ }
+
+ // --- RtkTrack ---
+ async function loadRtkTracks() {
+ rtkTracks.value = await rtkTrackService.selectAll()
+ }
+
+ async function loadRtkTracksByWorkRecord(workRecordId: number) {
+ rtkTracks.value = await rtkTrackService.selectByWorkRecordId(workRecordId)
+ }
+
+ async function addRtkTrack(data: RtkTrack) {
+ await rtkTrackService.insert(data)
+ }
+
+ // --- WarningRecord ---
+ async function loadWarningRecords() {
+ warningRecords.value = await warningRecordService.selectAll()
+ }
+
+ async function loadUnreadWarnings() {
+ warningRecords.value = await warningRecordService.selectUnread()
+ }
+
+ async function markWarningRead(id: number) {
+ await warningRecordService.markRead(id)
+ await loadWarningRecords()
+ }
+
+ return {
+ // State
+ projects,
+ workRecords,
+ rtkTracks,
+ warningRecords,
+ // Project
+ loadProjects,
+ addProject,
+ updateProject,
+ deleteProject,
+ // WorkRecord
+ loadWorkRecords,
+ loadWorkRecordsByProject,
+ addWorkRecord,
+ // RtkTrack
+ loadRtkTracks,
+ loadRtkTracksByWorkRecord,
+ addRtkTrack,
+ // WarningRecord
+ loadWarningRecords,
+ loadUnreadWarnings,
+ markWarningRead,
+ }
+})