Files
Road_roller/src/components/settings/projectForm.vue
2026-09-17 10:41:07 +08:00

121 lines
2.8 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import { useCurrentProject } from '@/composables/useCurrentProject'
import { projectService } from '@/service'
import { useDbStore } from '@/store/modules/db'
const db = useDbStore()
const { setCurrentProject, currentProjectId } = useCurrentProject()
const projectName = ref('')
const startEndStation = ref('')
const totalArea = ref('')
async function handleSave() {
if (!projectName.value) {
uni.showToast({ title: '请输入项目名称', icon: 'none' })
return
}
try {
const payload = {
project_name: projectName.value,
stake_range: startEndStation.value,
total_area: Number(totalArea.value) || 0,
status: 0 as const,
}
// 始终新建项目,写入数据库
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' })
}
catch (err) {
console.error('保存失败:', err)
uni.showToast({ title: '保存失败', icon: 'none' })
}
}
</script>
<template>
<view class="project-form">
<view class="form-item">
<text class="form-label">
项目名称
</text>
<uni-easyinput v-model="projectName" placeholder="请输入项目名称,保存后将显示首页顶部" />
</view>
<view class="form-item">
<text class="form-label">
起止桩号
</text>
<view class="input-with-button">
<uni-easyinput v-model="startEndStation" placeholder="请输入起止桩号" />
<wd-button size="small" type="primary" class="map-btn">
地图框选
</wd-button>
</view>
</view>
<view class="form-item">
<text class="form-label">
项目设计总面积 (m²)
</text>
<uni-easyinput v-model="totalArea" placeholder="请输入项目设计总面积" />
</view>
<wd-button type="primary" block class="save-btn" @tap="handleSave">
保存
</wd-button>
</view>
</template>
<style scoped>
.project-form {
background-color: #ffffff;
border-radius: 12px;
padding: 16px;
}
.form-item {
margin-bottom: 16px;
}
.form-label {
font-size: 18px;
font-weight: bold;
color: #333;
margin-bottom: 8px;
display: block;
}
.input-with-button {
display: flex;
gap: 8px;
align-items: center;
}
.map-btn {
flex-shrink: 0;
}
.save-btn {
margin-top: 8px;
}
</style>