feat: 出图导入改为列表并把参数收进设置

This commit is contained in:
nixevol
2026-10-15 01:38:38 +08:00
parent 611c500ac4
commit 393859fabe
2 changed files with 107 additions and 88 deletions
+52 -54
View File
@@ -1,5 +1,5 @@
<script setup>
import { ref, watch } from 'vue'
import { computed, ref, watch } from 'vue'
import { statFile, uploadFile, formatMb } from '../api'
const props = defineProps({
@@ -7,32 +7,28 @@ const props = defineProps({
extension: { type: String, required: true },
hint: { type: String, default: '' },
modelValue: { type: String, default: '' },
actions: { type: Array, default: () => [] },
})
const emit = defineEmits(['update:modelValue'])
const emit = defineEmits(['update:modelValue', 'action'])
const mode = ref('path')
const savedPath = ref(props.modelValue || '')
const picker = ref(null)
const status = ref('')
const busy = ref(false)
let ticket = 0
let timer = 0
const ready = computed(() => status.value.startsWith('已就绪'))
const missing = computed(() => status.value === '文件不存在' || status.value === '导入失败')
watch(() => props.modelValue, (value) => {
if (mode.value === 'path' && value) savedPath.value = value
clearTimeout(timer)
timer = setTimeout(() => refresh(value), value ? 250 : 0)
}, { immediate: true })
function setMode(next) {
mode.value = next
if (next === 'upload') emit('update:modelValue', '')
else emit('update:modelValue', savedPath.value)
}
async function refresh(path) {
const current = ++ticket
if (!path) {
status.value = mode.value === 'upload' ? `请选择 .${props.extension} 文件` : '文件不存在'
status.value = '未选择文件'
return
}
try {
@@ -44,23 +40,21 @@ async function refresh(path) {
}
}
async function customRequest({ file, onFinish, onError, onProgress }) {
if (!file.file) {
onError()
return
}
function choose() {
picker.value?.click()
}
async function onPick(event) {
const file = event.target.files?.[0]
event.target.value = ''
if (!file) return
busy.value = true
status.value = '正在导入…'
try {
onProgress({ percent: 30 })
const result = await uploadFile(file.file)
savedPath.value = result.path
const result = await uploadFile(file)
emit('update:modelValue', result.path)
onProgress({ percent: 100 })
onFinish()
} catch (error) {
status.value = error.message || '导入失败'
onError()
} finally {
busy.value = false
}
@@ -68,44 +62,48 @@ async function customRequest({ file, onFinish, onError, onProgress }) {
</script>
<template>
<div class="file-field panel">
<div class="file-title">
<n-tooltip v-if="hint">
<template #trigger>
<span class="hint">{{ label }}</span>
</template>
{{ hint }}
</n-tooltip>
<span v-else>{{ label }}</span>
<slot name="extra" />
</div>
<n-radio-group :value="mode" size="small" @update:value="setMode">
<n-radio-button value="path">本地路径</n-radio-button>
<n-radio-button value="upload">拖拽上传</n-radio-button>
</n-radio-group>
<div class="file-field" :class="{ 'has-actions': actions.length }">
<n-tooltip v-if="hint">
<template #trigger>
<span class="label hint">{{ label }}</span>
</template>
{{ hint }}
</n-tooltip>
<span v-else class="label">{{ label }}</span>
<n-input
v-if="mode === 'path'"
:value="modelValue"
placeholder="文件路径"
:placeholder="`本地路径,或选择 .${extension} 文件`"
:status="missing ? 'error' : undefined"
clearable
@update:value="emit('update:modelValue', ($event || '').trim())"
/>
<n-upload
v-else
:accept="`.${extension}`"
:max="1"
:show-file-list="false"
:custom-request="customRequest"
:disabled="busy"
>
<n-button size="small" :loading="busy">选择 .{{ extension }} 文件</n-button>
</n-upload>
<p class="muted">{{ status }}</p>
<template #suffix>
<span class="status" :class="{ ok: ready, bad: missing }">{{ status }}</span>
</template>
</n-input>
<n-button size="small" :loading="busy" @click="choose">选择文件</n-button>
<n-dropdown v-if="actions.length" :options="actions" @select="emit('action', $event)">
<n-button size="small">操作</n-button>
</n-dropdown>
<input ref="picker" class="picker" type="file" :accept="`.${extension}`" @change="onPick" />
</div>
</template>
<style scoped>
.file-field { display: flex; flex-direction: column; gap: 8px; }
.file-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-weight: 600; }
.hint { border-bottom: 1px dashed #b7c2cc; cursor: help; }
.file-field {
display: grid;
grid-template-columns: 112px minmax(0, 1fr) auto;
gap: 8px;
align-items: center;
padding: 6px 10px;
border-bottom: 1px solid #f0f3f6;
}
.file-field.has-actions { grid-template-columns: 112px minmax(0, 1fr) auto auto; }
.file-field:last-child { border-bottom: 0; }
.label { font-weight: 600; }
.hint { border-bottom: 1px dashed #b7c2cc; cursor: help; width: fit-content; }
.status { color: #66788a; font-size: 12px; white-space: nowrap; }
.status.ok { color: #16835a; }
.status.bad { color: #d03050; }
.picker { display: none; }
</style>
+55 -34
View File
@@ -8,7 +8,7 @@ import { getJSON, postJSON } from '../api'
const hints = {
MARKET_GPKG: '市场边界,默认 source/GridMap.gpkg',
GRID_5G_GPKG: '大文件请填本地路径,不要上传',
GRID_5G_GPKG: '大文件请直接填写本地路径',
BUILDING_INFO_GPKG: '建筑信息',
AOI_CSV: 'AOI 报表',
GIS_PROJECT_SOURCE: 'QGIS 工程模板',
@@ -21,7 +21,7 @@ const draft = reactive({
chosen: [],
maxWorkers: 4,
scale: 5,
summary: true,
summary: false,
maxRaster: 25,
summaryRaster: 100,
clipMode: 'intersects',
@@ -37,6 +37,7 @@ const success = ref('')
const submitting = ref(false)
const editingBoundary = ref(false)
const editingProject = ref(false)
const settingsOpen = ref(false)
const loadingMarkets = ref(false)
const lastTask = ref(null)
let marketTicket = 0
@@ -54,6 +55,17 @@ const clipOptions = [
{ label: '中心点在市场内', value: 'center' },
]
function fileActions(item) {
if (item.key === 'MARKET_GPKG') return [{ label: '编辑图层', key: 'boundary', disabled: !draft.paths.MARKET_GPKG }]
if (item.key === 'GIS_PROJECT_SOURCE') return [{ label: '编辑工程', key: 'project', disabled: !draft.paths.GIS_PROJECT_SOURCE }]
return []
}
function onFileAction(item, key) {
if (item.key === 'MARKET_GPKG' && key === 'boundary') editingBoundary.value = true
if (item.key === 'GIS_PROJECT_SOURCE' && key === 'project') editingProject.value = true
}
async function ensureCatalog() {
const data = await getJSON('/api/catalog')
sources.value = data.sources
@@ -177,7 +189,7 @@ onUnmounted(() => {
<n-alert v-if="error" type="error">{{ error }}</n-alert>
<n-alert v-if="success" type="success">{{ success }}</n-alert>
<h2 class="section-title">1 · 导入数据</h2>
<div class="two-col">
<div class="file-form">
<FileField
v-for="item in fileItems"
:key="item.key"
@@ -185,12 +197,9 @@ onUnmounted(() => {
:label="item.label"
:extension="item.extension"
:hint="item.hint"
>
<template #extra>
<n-button v-if="item.key === 'MARKET_GPKG'" size="small" :disabled="!draft.paths.MARKET_GPKG" @click="editingBoundary = true">编辑图层</n-button>
<n-button v-if="item.key === 'GIS_PROJECT_SOURCE'" size="small" :disabled="!draft.paths.GIS_PROJECT_SOURCE" @click="editingProject = true">编辑工程</n-button>
</template>
</FileField>
:actions="fileActions(item)"
@action="onFileAction(item, $event)"
/>
</div>
<LayerEditor
v-model:show="editingBoundary"
@@ -198,7 +207,10 @@ onUnmounted(() => {
@changed="loadMarkets(draft.paths.MARKET_GPKG)"
/>
<ProjectEditor v-model:show="editingProject" :path="draft.paths.GIS_PROJECT_SOURCE || ''" />
<h2 class="section-title">2 · 选择市场与参数</h2>
<div class="section-head">
<h2 class="section-title">2 · 选择市场</h2>
<n-button size="small" @click="settingsOpen = true">设置</n-button>
</div>
<n-alert v-if="marketError" type="warning">{{ marketError }}</n-alert>
<n-spin :show="loadingMarkets" size="small">
<div class="panel market-box">
@@ -219,8 +231,15 @@ onUnmounted(() => {
<p v-else class="muted">请先导入可用的市场边界。</p>
</div>
</n-spin>
<n-form label-placement="left" label-width="176" @submit.prevent="submit">
<div class="three-col">
<n-modal
v-model:show="settingsOpen"
preset="card"
title="出图设置"
style="width: min(640px, 94vw)"
:segmented="{ content: true, footer: 'soft' }"
:content-style="{ maxHeight: '70vh', overflow: 'auto' }"
>
<n-form label-placement="left" label-width="168" :show-feedback="false">
<n-form-item>
<template #label>
<n-tooltip><template #trigger><span class="tip">并行进程数</span></template>1 到 16,默认 4</n-tooltip>
@@ -233,34 +252,36 @@ onUnmounted(() => {
</template>
<n-input-number v-model:value="draft.scale" :min="0.1" :max="20" :step="0.5" style="width: 100%" />
</n-form-item>
<n-form-item label="全量汇总包">
<n-checkbox v-model:checked="draft.summary">生成全量汇总包</n-checkbox>
<n-form-item label="生成全量汇总包">
<n-checkbox v-model:checked="draft.summary" />
</n-form-item>
</div>
<n-collapse>
<n-collapse-item title="更多参数" name="more">
<div class="two-col">
<n-form-item label="单市场像元上限(百万)">
<n-input-number v-model:value="draft.maxRaster" :min="1" :max="100" :precision="0" style="width: 100%" />
</n-form-item>
<n-form-item label="汇总像元上限(百万)">
<n-input-number v-model:value="draft.summaryRaster" :min="1" :max="200" :precision="0" style="width: 100%" />
</n-form-item>
<n-form-item label="网格纳入方式">
<n-select v-model:value="draft.clipMode" :options="clipOptions" />
</n-form-item>
<n-form-item label="地图留白比例">
<n-input-number v-model:value="draft.padding" :min="0" :max="1" :step="0.01" style="width: 100%" />
</n-form-item>
</div>
</n-collapse-item>
</n-collapse>
</n-form>
<n-form-item label="单市场像元上限(百万)">
<n-input-number v-model:value="draft.maxRaster" :min="1" :max="100" :precision="0" style="width: 100%" />
</n-form-item>
<n-form-item label="汇总像元上限(百万)">
<n-input-number v-model:value="draft.summaryRaster" :min="1" :max="200" :precision="0" style="width: 100%" />
</n-form-item>
<n-form-item label="网格纳入方式">
<n-select v-model:value="draft.clipMode" :options="clipOptions" />
</n-form-item>
<n-form-item label="地图留白比例">
<n-input-number v-model:value="draft.padding" :min="0" :max="1" :step="0.01" style="width: 100%" />
</n-form-item>
</n-form>
<template #footer>
<n-space justify="end">
<n-button type="primary" @click="settingsOpen = false">完成</n-button>
</n-space>
</template>
</n-modal>
<TaskCard v-if="lastTask" :task="lastTask" log-open @changed="refreshTask" />
</div>
</template>
<style scoped>
.file-form { border: 1px solid #e4ebf1; border-radius: 8px; background: #fff; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.section-head .section-title { margin: 0; }
.market-box { display: flex; flex-direction: column; gap: 8px; }
.pick { padding: 2px 0; }
.tip { border-bottom: 1px dashed #b7c2cc; cursor: help; }