feat 联调项目表
This commit is contained in:
@@ -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