feat 添加mock数据
This commit is contained in:
@@ -1,12 +1,26 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { onMounted } from 'vue'
|
import { onMounted } from 'vue'
|
||||||
|
import { useDbStore } from '@/store/modules/db'
|
||||||
import { useDeviceStore } from '@/store/modules/home'
|
import { useDeviceStore } from '@/store/modules/home'
|
||||||
|
|
||||||
const deviceStore = useDeviceStore()
|
const deviceStore = useDeviceStore()
|
||||||
|
const dbStore = useDbStore()
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(async () => {
|
||||||
console.log('组件挂载时 初始化设备信息')
|
console.log('组件挂载时 初始化设备信息')
|
||||||
deviceStore.initDevice()
|
deviceStore.initDevice()
|
||||||
|
|
||||||
|
await dbStore.loadProjects()
|
||||||
|
console.log('projects:', dbStore.projects)
|
||||||
|
|
||||||
|
await dbStore.loadWorkRecords()
|
||||||
|
console.log('workRecords:', dbStore.workRecords)
|
||||||
|
|
||||||
|
await dbStore.loadRtkTracks()
|
||||||
|
console.log('rtkTracks:', dbStore.rtkTracks)
|
||||||
|
|
||||||
|
await dbStore.loadWarningRecords()
|
||||||
|
console.log('warningRecords:', dbStore.warningRecords)
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,16 @@ import { warningRecordTableSql } from './warningRecord'
|
|||||||
import { workRecordTableSql } from './workRecord'
|
import { workRecordTableSql } from './workRecord'
|
||||||
|
|
||||||
export { projectTableSql } from './project'
|
export { projectTableSql } from './project'
|
||||||
|
// 导出所有 service 方法
|
||||||
|
export * as projectService from './project'
|
||||||
export { rtkTrackTableSql } from './rtkTrack'
|
export { rtkTrackTableSql } from './rtkTrack'
|
||||||
|
export * as rtkTrackService from './rtkTrack'
|
||||||
|
export { seedAll } from './seed'
|
||||||
|
|
||||||
export { warningRecordTableSql } from './warningRecord'
|
export { warningRecordTableSql } from './warningRecord'
|
||||||
|
export * as warningRecordService from './warningRecord'
|
||||||
export { workRecordTableSql } from './workRecord'
|
export { workRecordTableSql } from './workRecord'
|
||||||
|
export * as workRecordService from './workRecord'
|
||||||
|
|
||||||
const tableSqls = [
|
const tableSqls = [
|
||||||
projectTableSql,
|
projectTableSql,
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
/**
|
import DB from '@/utils/sqlite'
|
||||||
* 项目信息表: 项目名称,压路机名称, (平板)设备ID, 开始时间, 结束时间,
|
|
||||||
* 字段说明:
|
const TABLE = 'project'
|
||||||
* - id:项目唯一标识符
|
|
||||||
* - project_name:项目名称
|
|
||||||
* - project_type:项目类型
|
|
||||||
* - status:项目状态(默认值为 'offline')
|
|
||||||
*/
|
|
||||||
export const projectTableSql = `CREATE TABLE IF NOT EXISTS project (
|
export const projectTableSql = `CREATE TABLE IF NOT EXISTS project (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
project_name TEXT NOT NULL,
|
project_name TEXT NOT NULL,
|
||||||
@@ -14,3 +10,42 @@ export const projectTableSql = `CREATE TABLE IF NOT EXISTS project (
|
|||||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||||
updated_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<Project[]> {
|
||||||
|
return DB.select(TABLE)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 按 ID 查询 */
|
||||||
|
export async function selectById(id: number): Promise<Project | null> {
|
||||||
|
return DB.selectById(TABLE, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 按状态查询 */
|
||||||
|
export async function selectByStatus(status: string): Promise<Project[]> {
|
||||||
|
return DB.selectByField(TABLE, 'status', status)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 新增项目 */
|
||||||
|
export async function insert(data: Project): Promise<any> {
|
||||||
|
return DB.insert(TABLE, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 更新项目 */
|
||||||
|
export async function update(id: number, data: Partial<Project>): Promise<any> {
|
||||||
|
return DB.update(TABLE, data, `id = ${id}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除项目 */
|
||||||
|
export async function remove(id: number): Promise<any> {
|
||||||
|
return DB.delete(TABLE, `id = ${id}`)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,16 +1,7 @@
|
|||||||
/**
|
import DB from '@/utils/sqlite'
|
||||||
* RTK 轨迹数据表: 作业记录ID, 时间戳, , 压实度, 纬度, 经度, 高度, 速度, 方向, 创建时间, 外键约束
|
|
||||||
* 字段说明:
|
const TABLE = 'rtk_track'
|
||||||
* - id:轨迹唯一标识符
|
|
||||||
* - work_record_id:作业记录 ID
|
|
||||||
* - timestamp:时间戳
|
|
||||||
* - latitude:纬度
|
|
||||||
* - longitude:经度
|
|
||||||
* - altitude:高度
|
|
||||||
* - speed:速度
|
|
||||||
* - heading:方向
|
|
||||||
* - created_at:记录创建时间(默认值为当前时间)
|
|
||||||
*/
|
|
||||||
export const rtkTrackTableSql = `CREATE TABLE IF NOT EXISTS rtk_track (
|
export const rtkTrackTableSql = `CREATE TABLE IF NOT EXISTS rtk_track (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
work_record_id INTEGER,
|
work_record_id INTEGER,
|
||||||
@@ -23,3 +14,45 @@ export const rtkTrackTableSql = `CREATE TABLE IF NOT EXISTS rtk_track (
|
|||||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||||
FOREIGN KEY (work_record_id) REFERENCES work_record(id)
|
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<RtkTrack[]> {
|
||||||
|
return DB.select(TABLE)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 按 ID 查询 */
|
||||||
|
export async function selectById(id: number): Promise<RtkTrack | null> {
|
||||||
|
return DB.selectById(TABLE, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 按作业记录 ID 查询 */
|
||||||
|
export async function selectByWorkRecordId(workRecordId: number): Promise<RtkTrack[]> {
|
||||||
|
return DB.selectByField(TABLE, 'work_record_id', workRecordId)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 新增 */
|
||||||
|
export async function insert(data: RtkTrack): Promise<any> {
|
||||||
|
return DB.insert(TABLE, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 更新 */
|
||||||
|
export async function update(id: number, data: Partial<RtkTrack>): Promise<any> {
|
||||||
|
return DB.update(TABLE, data, `id = ${id}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除 */
|
||||||
|
export async function remove(id: number): Promise<any> {
|
||||||
|
return DB.delete(TABLE, `id = ${id}`)
|
||||||
|
}
|
||||||
|
|||||||
163
src/service/seed.ts
Normal file
163
src/service/seed.ts
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +1,7 @@
|
|||||||
/**
|
import DB from '@/utils/sqlite'
|
||||||
* 告警记录表
|
|
||||||
* 字段说明:
|
const TABLE = 'warning_record'
|
||||||
* - id:告警记录唯一标识符
|
|
||||||
* - project_id:项目 ID
|
|
||||||
* - warning_type:告警类型
|
|
||||||
* - warning_level:告警等级
|
|
||||||
* - message:告警信息
|
|
||||||
* - is_read:是否已读(0 表示未读,1 表示已读,默认值为 0)
|
|
||||||
* - created_at:创建时间(默认值为当前时间)
|
|
||||||
*/
|
|
||||||
export const warningRecordTableSql = `CREATE TABLE IF NOT EXISTS warning_record (
|
export const warningRecordTableSql = `CREATE TABLE IF NOT EXISTS warning_record (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
project_id INTEGER,
|
project_id INTEGER,
|
||||||
@@ -19,3 +12,53 @@ export const warningRecordTableSql = `CREATE TABLE IF NOT EXISTS warning_record
|
|||||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||||
FOREIGN KEY (project_id) REFERENCES project(id)
|
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<WarningRecord[]> {
|
||||||
|
return DB.select(TABLE)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 按 ID 查询 */
|
||||||
|
export async function selectById(id: number): Promise<WarningRecord | null> {
|
||||||
|
return DB.selectById(TABLE, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 按项目 ID 查询 */
|
||||||
|
export async function selectByProjectId(projectId: number): Promise<WarningRecord[]> {
|
||||||
|
return DB.selectByField(TABLE, 'project_id', projectId)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 查询未读 */
|
||||||
|
export async function selectUnread(): Promise<WarningRecord[]> {
|
||||||
|
return DB.select(TABLE, '*', 'is_read = 0')
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 新增 */
|
||||||
|
export async function insert(data: WarningRecord): Promise<any> {
|
||||||
|
return DB.insert(TABLE, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 标记已读 */
|
||||||
|
export async function markRead(id: number): Promise<any> {
|
||||||
|
return DB.update(TABLE, { is_read: 1 }, `id = ${id}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 更新 */
|
||||||
|
export async function update(id: number, data: Partial<WarningRecord>): Promise<any> {
|
||||||
|
return DB.update(TABLE, data, `id = ${id}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除 */
|
||||||
|
export async function remove(id: number): Promise<any> {
|
||||||
|
return DB.delete(TABLE, `id = ${id}`)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,19 +1,7 @@
|
|||||||
/**
|
import DB from '@/utils/sqlite'
|
||||||
* 作业记录表
|
|
||||||
* 字段说明:
|
const TABLE = 'work_record'
|
||||||
* -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字段
|
|
||||||
*/
|
|
||||||
export const workRecordTableSql = `CREATE TABLE IF NOT EXISTS work_record (
|
export const workRecordTableSql = `CREATE TABLE IF NOT EXISTS work_record (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
project_id INTEGER,
|
project_id INTEGER,
|
||||||
@@ -28,3 +16,47 @@ export const workRecordTableSql = `CREATE TABLE IF NOT EXISTS work_record (
|
|||||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||||
FOREIGN KEY (project_id) REFERENCES project(id)
|
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<WorkRecord[]> {
|
||||||
|
return DB.select(TABLE)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 按 ID 查询 */
|
||||||
|
export async function selectById(id: number): Promise<WorkRecord | null> {
|
||||||
|
return DB.selectById(TABLE, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 按项目 ID 查询 */
|
||||||
|
export async function selectByProjectId(projectId: number): Promise<WorkRecord[]> {
|
||||||
|
return DB.selectByField(TABLE, 'project_id', projectId)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 新增 */
|
||||||
|
export async function insert(data: WorkRecord): Promise<any> {
|
||||||
|
return DB.insert(TABLE, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 更新 */
|
||||||
|
export async function update(id: number, data: Partial<WorkRecord>): Promise<any> {
|
||||||
|
return DB.update(TABLE, data, `id = ${id}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除 */
|
||||||
|
export async function remove(id: number): Promise<any> {
|
||||||
|
return DB.delete(TABLE, `id = ${id}`)
|
||||||
|
}
|
||||||
|
|||||||
106
src/store/modules/db.ts
Normal file
106
src/store/modules/db.ts
Normal file
@@ -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<Project[]>([])
|
||||||
|
const workRecords = ref<WorkRecord[]>([])
|
||||||
|
const rtkTracks = ref<RtkTrack[]>([])
|
||||||
|
const warningRecords = ref<WarningRecord[]>([])
|
||||||
|
|
||||||
|
// --- 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<Project>) {
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user