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