feat 无项目数据--
This commit is contained in:
@@ -1,31 +1,28 @@
|
||||
<script setup lang="ts">
|
||||
import { onShow } from '@dcloudio/uni-app'
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { computed, onMounted } from 'vue'
|
||||
import { useCurrentProject } from '@/composables/useCurrentProject'
|
||||
import { calcUncompactedArea } from '@/service/project'
|
||||
import { useDbStore } from '@/store/modules/db'
|
||||
import storage from '@/utils/storage'
|
||||
|
||||
const db = useDbStore()
|
||||
const currentProjectId = ref<number | null>(storage.get('current_project')?.id ?? null)
|
||||
const { currentProject: storedProject, hasCurrentProject } = useCurrentProject()
|
||||
|
||||
const currentProject = computed(() => {
|
||||
const list = db.project || []
|
||||
if (!list.length)
|
||||
if (!hasCurrentProject.value)
|
||||
return null
|
||||
|
||||
const stored = currentProjectId.value != null
|
||||
? list.find(item => item.id === currentProjectId.value)
|
||||
: null
|
||||
if (stored)
|
||||
return stored
|
||||
const list = db.project || []
|
||||
const storedId = storedProject.value?.id
|
||||
if (storedId == null)
|
||||
return null
|
||||
|
||||
return list.find(item => item.status === 2) || list[0]
|
||||
return list.find(item => item.id === storedId) || null
|
||||
})
|
||||
|
||||
const progressPercent = computed(() => {
|
||||
const project = currentProject.value
|
||||
if (!project)
|
||||
return 0
|
||||
return null
|
||||
if (project.progress)
|
||||
return clampPercent(project.progress)
|
||||
|
||||
@@ -35,16 +32,28 @@ const progressPercent = computed(() => {
|
||||
return clampPercent(((project.total_compaction_area ?? 0) / total) * 100)
|
||||
})
|
||||
|
||||
const qualifiedRate = computed(() => currentProject.value?.qualified_rate ?? 0)
|
||||
const qualifiedRate = computed(() => {
|
||||
if (!currentProject.value)
|
||||
return null
|
||||
return currentProject.value.qualified_rate ?? 0
|
||||
})
|
||||
|
||||
const totalArea = computed(() => currentProject.value?.total_area ?? 0)
|
||||
const totalArea = computed(() => {
|
||||
if (!currentProject.value)
|
||||
return null
|
||||
return currentProject.value.total_area ?? 0
|
||||
})
|
||||
|
||||
const compactedArea = computed(() => currentProject.value?.total_compaction_area ?? 0)
|
||||
const compactedArea = computed(() => {
|
||||
if (!currentProject.value)
|
||||
return null
|
||||
return currentProject.value.total_compaction_area ?? 0
|
||||
})
|
||||
|
||||
const uncompactedArea = computed(() => {
|
||||
const project = currentProject.value
|
||||
if (!project)
|
||||
return 0
|
||||
return null
|
||||
if (project.uncompacted_area != null)
|
||||
return Math.max(0, project.uncompacted_area)
|
||||
return calcUncompactedArea(project.total_area, project.total_compaction_area)
|
||||
@@ -54,24 +63,30 @@ function clampPercent(value: number) {
|
||||
return Math.min(100, Math.max(0, Number(value.toFixed(1))))
|
||||
}
|
||||
|
||||
function formatArea(value: number) {
|
||||
function formatArea(value: number | null) {
|
||||
if (value == null)
|
||||
return '--'
|
||||
const text = Number.isInteger(value) ? String(value) : String(value)
|
||||
return `${text}m²`
|
||||
}
|
||||
|
||||
function formatRate(value: number) {
|
||||
function formatRate(value: number | null) {
|
||||
if (value == null)
|
||||
return '--'
|
||||
const text = Number.isInteger(value) ? String(value) : value.toFixed(2)
|
||||
return `${text}%`
|
||||
}
|
||||
|
||||
function formatPercent(value: number | null) {
|
||||
if (value == null)
|
||||
return '--'
|
||||
return `${value}%`
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
if (!db.project?.length)
|
||||
await db.loadAll()
|
||||
})
|
||||
|
||||
onShow(() => {
|
||||
currentProjectId.value = storage.get('current_project')?.id ?? null
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -81,22 +96,19 @@ onShow(() => {
|
||||
项目作业进度
|
||||
</text>
|
||||
<text class="card-sub">
|
||||
{{ currentProject?.stake_range || currentProject?.project_name || '暂无项目' }}
|
||||
{{ currentProject?.stake_range || currentProject?.project_name || '暂无施工段' }}
|
||||
</text>
|
||||
</view>
|
||||
<view class="card-body">
|
||||
<view v-if="!currentProject" class="empty-tip">
|
||||
暂无项目数据
|
||||
</view>
|
||||
<view v-else class="progress-content">
|
||||
<view class="progress-content">
|
||||
<view class="progress-circle">
|
||||
<wd-circle :model-value="progressPercent" :size="120">
|
||||
<wd-circle :model-value="progressPercent ?? 0" :size="120">
|
||||
<view class="progress-circle-text">
|
||||
<text class="progress-percent">
|
||||
{{ progressPercent }}%
|
||||
{{ hasCurrentProject ? `${progressPercent}%` : '0%' }}
|
||||
</text>
|
||||
<text class="progress-label">
|
||||
已完成
|
||||
{{ hasCurrentProject ? '已完成' : '未开始' }}
|
||||
</text>
|
||||
</view>
|
||||
</wd-circle>
|
||||
@@ -111,7 +123,7 @@ onShow(() => {
|
||||
{{ formatRate(qualifiedRate) }}
|
||||
</text>
|
||||
</view>
|
||||
<wd-progress :percentage="clampPercent(qualifiedRate)" hide-text />
|
||||
<wd-progress :percentage="clampPercent(qualifiedRate ?? 0)" hide-text />
|
||||
</view>
|
||||
<view class="progress-item">
|
||||
<view class="progress-row">
|
||||
@@ -119,10 +131,10 @@ onShow(() => {
|
||||
完成进度
|
||||
</text>
|
||||
<text class="progress-value">
|
||||
{{ progressPercent }}%
|
||||
{{ formatPercent(progressPercent) }}
|
||||
</text>
|
||||
</view>
|
||||
<wd-progress :percentage="progressPercent" hide-text />
|
||||
<wd-progress :percentage="progressPercent ?? 0" hide-text />
|
||||
</view>
|
||||
<view class="progress-item progress-item-inline">
|
||||
<text class="progress-name">
|
||||
@@ -187,13 +199,6 @@ onShow(() => {
|
||||
padding: 12px 16px;
|
||||
}
|
||||
|
||||
.empty-tip {
|
||||
font-size: 14px;
|
||||
color: #999999;
|
||||
text-align: center;
|
||||
padding: 16px 0;
|
||||
}
|
||||
|
||||
.progress-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
Reference in New Issue
Block a user