feat 添加mock数据

This commit is contained in:
Ironsp
2026-09-10 10:08:56 +08:00
parent 7a4477966d
commit b670e06bc9
8 changed files with 482 additions and 49 deletions

163
src/service/seed.ts Normal file
View File

@@ -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
}
}