feat 联调项目表
This commit is contained in:
@@ -4,21 +4,27 @@ import { useCurrentProject } from '@/composables/useCurrentProject'
|
||||
import { useDbStore } from '@/store/modules/db'
|
||||
|
||||
const db = useDbStore()
|
||||
const { hasCurrentProject } = useCurrentProject()
|
||||
const { hasCurrentProject, currentProjectId } = useCurrentProject()
|
||||
|
||||
const now = new Date()
|
||||
const dateStr = `${now.getFullYear()}年${now.getMonth() + 1}月${now.getDate()}日`
|
||||
|
||||
const projectWorkRecords = computed(() => {
|
||||
if (!hasCurrentProject.value || currentProjectId.value == null)
|
||||
return []
|
||||
return (db.work_record || []).filter(item => item.project_id === currentProjectId.value)
|
||||
})
|
||||
|
||||
const totalCompactionArea = computed(() => {
|
||||
if (!hasCurrentProject.value)
|
||||
return null
|
||||
return (db.work_record || []).reduce((sum, item) => sum + (item.compaction_area ?? 0), 0)
|
||||
return projectWorkRecords.value.reduce((sum, item) => sum + (item.compaction_area ?? 0), 0)
|
||||
})
|
||||
|
||||
const totalDuration = computed(() => {
|
||||
if (!hasCurrentProject.value)
|
||||
return null
|
||||
return (db.work_record || []).reduce((sum, item) => sum + (item.duration ?? 0), 0)
|
||||
return projectWorkRecords.value.reduce((sum, item) => sum + (item.duration ?? 0), 0)
|
||||
})
|
||||
|
||||
const onlineCount = computed(() => {
|
||||
@@ -40,8 +46,9 @@ function formatCount(value: number | null) {
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
if (!db.work_record?.length)
|
||||
await db.loadAll()
|
||||
if (!hasCurrentProject.value || currentProjectId.value == null)
|
||||
return
|
||||
await db.loadByProject(currentProjectId.value)
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
@@ -5,18 +5,14 @@ import { calcUncompactedArea } from '@/service/project'
|
||||
import { useDbStore } from '@/store/modules/db'
|
||||
|
||||
const db = useDbStore()
|
||||
const { currentProject: storedProject, hasCurrentProject } = useCurrentProject()
|
||||
const { hasCurrentProject, currentProjectId } = useCurrentProject()
|
||||
|
||||
const currentProject = computed(() => {
|
||||
if (!hasCurrentProject.value)
|
||||
if (!hasCurrentProject.value || currentProjectId.value == null)
|
||||
return null
|
||||
|
||||
const list = db.project || []
|
||||
const storedId = storedProject.value?.id
|
||||
if (storedId == null)
|
||||
return null
|
||||
|
||||
return list.find(item => item.id === storedId) || null
|
||||
return list.find(item => item.id === currentProjectId.value) || null
|
||||
})
|
||||
|
||||
const progressPercent = computed(() => {
|
||||
@@ -84,8 +80,9 @@ function formatPercent(value: number | null) {
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
if (!db.project?.length)
|
||||
await db.loadAll()
|
||||
if (!hasCurrentProject.value || currentProjectId.value == null)
|
||||
return
|
||||
await db.loadByProject(currentProjectId.value)
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
@@ -1,18 +1,12 @@
|
||||
<script setup lang="ts">
|
||||
import type { Project } from '@/service/project'
|
||||
import { computed, onMounted } from 'vue'
|
||||
import { useCurrentProject } from '@/composables/useCurrentProject'
|
||||
import { useDbStore } from '@/store/modules/db'
|
||||
|
||||
const db = useDbStore()
|
||||
const { hasCurrentProject } = useCurrentProject()
|
||||
|
||||
/** 首页只展示最近几条 */
|
||||
const list = computed(() => {
|
||||
if (!hasCurrentProject.value)
|
||||
return []
|
||||
return (db.project || []).slice(0, 2)
|
||||
})
|
||||
/** 首页展示最近 2 条,按 id 倒序 */
|
||||
const list = computed(() => (db.project || []).slice().sort((a, b) => (b.id ?? 0) - (a.id ?? 0)).slice(0, 2))
|
||||
|
||||
onMounted(async () => {
|
||||
if (!db.project?.length)
|
||||
@@ -45,10 +39,7 @@ function goToDetail(item: Project) {
|
||||
</wd-button>
|
||||
</view>
|
||||
<view class="card-body">
|
||||
<view v-if="!hasCurrentProject" class="empty-tip">
|
||||
--
|
||||
</view>
|
||||
<view v-else-if="!list.length" class="empty-tip">
|
||||
<view v-if="!list.length" class="empty-tip">
|
||||
暂无项目
|
||||
</view>
|
||||
<home-list
|
||||
|
||||
@@ -37,7 +37,7 @@ function goToWork() {
|
||||
</view>
|
||||
</view>
|
||||
<view class="status-params">
|
||||
<view class="param">
|
||||
<!-- <view class="param">
|
||||
<text class="param-label">
|
||||
振动频率
|
||||
</text>
|
||||
@@ -52,7 +52,7 @@ function goToWork() {
|
||||
<text class="param-value">
|
||||
8939mm
|
||||
</text>
|
||||
</view>
|
||||
</view> -->
|
||||
<view class="param">
|
||||
<text class="param-label">
|
||||
行驶速度
|
||||
|
||||
@@ -5,21 +5,21 @@ import { useCurrentProject } from '@/composables/useCurrentProject'
|
||||
import { useDbStore } from '@/store/modules/db'
|
||||
|
||||
const db = useDbStore()
|
||||
const { hasCurrentProject, currentProject } = useCurrentProject()
|
||||
const { hasCurrentProject, currentProjectId } = useCurrentProject()
|
||||
|
||||
/** 首页只展示当前项目最近几条 */
|
||||
const list = computed(() => {
|
||||
if (!hasCurrentProject.value)
|
||||
if (!hasCurrentProject.value || currentProjectId.value == null)
|
||||
return []
|
||||
const projectId = currentProject.value?.id
|
||||
return (db.warning_record || [])
|
||||
.filter(item => projectId == null || item.project_id === projectId)
|
||||
.filter(item => item.project_id === currentProjectId.value)
|
||||
.slice(0, 3)
|
||||
})
|
||||
|
||||
onMounted(async () => {
|
||||
if (!db.warning_record?.length)
|
||||
await db.loadAll()
|
||||
if (!hasCurrentProject.value || currentProjectId.value == null)
|
||||
return
|
||||
await db.loadByProject(currentProjectId.value)
|
||||
})
|
||||
|
||||
function goToWarningList() {
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
<script setup lang="ts">
|
||||
import { useCurrentProject } from '@/composables/useCurrentProject'
|
||||
import { projectService } from '@/service'
|
||||
import storage from '@/utils/storage'
|
||||
import { useDbStore } from '@/store/modules/db'
|
||||
|
||||
const PROJECT_KEY = 'current_project'
|
||||
const currentProject = storage.get(PROJECT_KEY)
|
||||
const db = useDbStore()
|
||||
const { setCurrentProject, currentProjectId } = useCurrentProject()
|
||||
|
||||
const projectName = ref(currentProject?.project_name || '')
|
||||
const startEndStation = ref(currentProject?.stake_range || '')
|
||||
const totalArea = ref(currentProject?.total_area ? String(currentProject.total_area) : '')
|
||||
const projectName = ref('')
|
||||
const startEndStation = ref('')
|
||||
const totalArea = ref('')
|
||||
|
||||
async function handleSave() {
|
||||
if (!projectName.value) {
|
||||
@@ -16,21 +17,30 @@ async function handleSave() {
|
||||
}
|
||||
|
||||
try {
|
||||
const id = await projectService.insert({
|
||||
const payload = {
|
||||
project_name: projectName.value,
|
||||
stake_range: startEndStation.value,
|
||||
total_area: Number(totalArea.value) || 0,
|
||||
status: 0,
|
||||
})
|
||||
status: 0 as const,
|
||||
}
|
||||
|
||||
// 保存到 storage
|
||||
storage.set(PROJECT_KEY, {
|
||||
id,
|
||||
project_name: projectName.value,
|
||||
stake_range: startEndStation.value,
|
||||
total_area: Number(totalArea.value) || 0,
|
||||
status: 0,
|
||||
})
|
||||
// 始终新建项目,写入数据库
|
||||
const id = await projectService.insert(payload)
|
||||
if (!id) {
|
||||
uni.showToast({ title: '保存失败:未获取到项目ID', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
// 写入 storage,后续业务按该项目 id 查询
|
||||
const project = await projectService.selectById(id)
|
||||
if (!project) {
|
||||
uni.showToast({ title: '保存失败:项目不存在', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
setCurrentProject(project)
|
||||
await db.loadByProject(id)
|
||||
console.log('id22222', id, 'currentProjectId.value', currentProjectId.value)
|
||||
|
||||
uni.showToast({ title: '保存成功', icon: 'success' })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user