feat: 新增 Vue 工具箱供对比
This commit is contained in:
@@ -0,0 +1,252 @@
|
||||
<script setup>
|
||||
import { computed, onMounted, onUnmounted, reactive, ref, watch } from 'vue'
|
||||
import FileField from '../components/FileField.vue'
|
||||
import TaskCard from '../components/TaskCard.vue'
|
||||
import { getJSON, postJSON } from '../api'
|
||||
|
||||
const hints = {
|
||||
MARKET_GPKG: '市场边界,默认 source/GridMap.gpkg',
|
||||
GRID_5G_GPKG: '大文件请填本地路径,不要上传',
|
||||
BUILDING_INFO_GPKG: '建筑信息',
|
||||
AOI_CSV: 'AOI 报表',
|
||||
GIS_PROJECT_SOURCE: 'QGIS 工程模板',
|
||||
NR_BUILDINGS_DATA_CSV: '楼宇查询结果。开始生成时如有需要会整理边界图层',
|
||||
}
|
||||
const draft = reactive({
|
||||
ready: false,
|
||||
paths: {},
|
||||
allMarkets: true,
|
||||
chosen: [],
|
||||
maxWorkers: 4,
|
||||
scale: 5,
|
||||
summary: true,
|
||||
maxRaster: 25,
|
||||
summaryRaster: 100,
|
||||
clipMode: 'intersects',
|
||||
padding: 0.05,
|
||||
lastTaskId: '',
|
||||
})
|
||||
const sources = ref([])
|
||||
const nr = ref(null)
|
||||
const options = ref([])
|
||||
const marketError = ref('')
|
||||
const error = ref('')
|
||||
const success = ref('')
|
||||
const submitting = ref(false)
|
||||
const loadingMarkets = ref(false)
|
||||
const lastTask = ref(null)
|
||||
let marketTicket = 0
|
||||
let marketTimer = 0
|
||||
let pollTimer = 0
|
||||
|
||||
const fileItems = computed(() => {
|
||||
const items = sources.value.map((item) => ({ ...item, hint: hints[item.key] || '' }))
|
||||
if (nr.value) items.push({ ...nr.value, hint: hints[nr.value.key] || '' })
|
||||
return items
|
||||
})
|
||||
const canStart = computed(() => draft.ready && options.value.length > 0 && !submitting.value)
|
||||
const clipOptions = [
|
||||
{ label: '与市场相交', value: 'intersects' },
|
||||
{ label: '中心点在市场内', value: 'center' },
|
||||
]
|
||||
|
||||
async function ensureCatalog() {
|
||||
const data = await getJSON('/api/catalog')
|
||||
sources.value = data.sources
|
||||
nr.value = data.nr_csv
|
||||
if (!draft.ready) {
|
||||
for (const item of data.sources) draft.paths[item.key] = item.path
|
||||
draft.paths[data.nr_csv.key] = data.nr_csv.path
|
||||
draft.ready = true
|
||||
}
|
||||
}
|
||||
|
||||
async function loadMarkets(path) {
|
||||
const current = ++marketTicket
|
||||
loadingMarkets.value = true
|
||||
try {
|
||||
if (!path) {
|
||||
options.value = []
|
||||
marketError.value = '请先导入可用的市场边界。'
|
||||
return
|
||||
}
|
||||
const data = await getJSON(`/api/markets?path=${encodeURIComponent(path)}`)
|
||||
if (current !== marketTicket) return
|
||||
options.value = data.options || []
|
||||
draft.chosen = draft.chosen.filter((id) => options.value.some((item) => item.id === id))
|
||||
marketError.value = options.value.length ? '' : '请先导入可用的市场边界。'
|
||||
} catch (reason) {
|
||||
if (current !== marketTicket) return
|
||||
options.value = []
|
||||
marketError.value = reason.message
|
||||
} finally {
|
||||
if (current === marketTicket) loadingMarkets.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshTask() {
|
||||
if (!draft.lastTaskId) return
|
||||
try {
|
||||
lastTask.value = await getJSON(`/api/tasks/${encodeURIComponent(draft.lastTaskId)}`)
|
||||
} catch {
|
||||
// 轮询失败时保留上一帧。
|
||||
}
|
||||
}
|
||||
|
||||
function numbersReady() {
|
||||
return [draft.maxWorkers, draft.scale, draft.maxRaster, draft.summaryRaster, draft.padding]
|
||||
.every((value) => typeof value === 'number')
|
||||
}
|
||||
|
||||
async function submit() {
|
||||
error.value = ''
|
||||
success.value = ''
|
||||
if (!canStart.value) return
|
||||
if (!numbersReady()) {
|
||||
error.value = '请填写完整参数。'
|
||||
return
|
||||
}
|
||||
const ids = draft.allMarkets ? options.value.map((item) => item.id) : [...draft.chosen]
|
||||
if (!ids.length) {
|
||||
error.value = '请至少选择一个市场网格。'
|
||||
return
|
||||
}
|
||||
for (const item of fileItems.value) {
|
||||
if (!draft.paths[item.key]) {
|
||||
error.value = '请完成所需数据的导入。'
|
||||
return
|
||||
}
|
||||
}
|
||||
submitting.value = true
|
||||
try {
|
||||
const result = await postJSON('/api/tasks', {
|
||||
kind: 'market',
|
||||
params: {
|
||||
...draft.paths,
|
||||
SELECTED_MARKET_IDS: ids,
|
||||
MAX_WORKERS: draft.maxWorkers,
|
||||
SCALE: draft.scale,
|
||||
SUMMARY_OUTPUT_ENABLED: draft.summary,
|
||||
MAX_RASTER_PIXELS: Math.round(draft.maxRaster * 1_000_000),
|
||||
SUMMARY_MAX_RASTER_PIXELS: Math.round(draft.summaryRaster * 1_000_000),
|
||||
CLIP_MODE: draft.clipMode,
|
||||
PROJECT_EXTENT_PADDING_RATIO: draft.padding,
|
||||
},
|
||||
})
|
||||
draft.lastTaskId = result.id
|
||||
success.value = '任务已启动,可在任务中心查看进度。'
|
||||
await refreshTask()
|
||||
} catch (reason) {
|
||||
error.value = reason.message
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
watch(() => draft.paths.MARKET_GPKG, (path) => {
|
||||
clearTimeout(marketTimer)
|
||||
marketTimer = setTimeout(() => loadMarkets(path), 300)
|
||||
})
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
await ensureCatalog()
|
||||
await loadMarkets(draft.paths.MARKET_GPKG)
|
||||
} catch (reason) {
|
||||
error.value = reason.message
|
||||
}
|
||||
await refreshTask()
|
||||
pollTimer = setInterval(refreshTask, 2000)
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
clearInterval(pollTimer)
|
||||
clearTimeout(marketTimer)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="page">
|
||||
<teleport to="#page-actions">
|
||||
<n-button type="primary" :disabled="!canStart" :loading="submitting" @click="submit">开始生成</n-button>
|
||||
</teleport>
|
||||
<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">
|
||||
<FileField
|
||||
v-for="item in fileItems"
|
||||
:key="item.key"
|
||||
v-model="draft.paths[item.key]"
|
||||
:label="item.label"
|
||||
:extension="item.extension"
|
||||
:hint="item.hint"
|
||||
/>
|
||||
</div>
|
||||
<h2 class="section-title">2 · 选择市场与参数</h2>
|
||||
<n-alert v-if="marketError" type="warning">{{ marketError }}</n-alert>
|
||||
<n-spin :show="loadingMarkets" size="small">
|
||||
<div class="panel market-box">
|
||||
<n-tooltip>
|
||||
<template #trigger>
|
||||
<n-checkbox v-model:checked="draft.allMarkets" :disabled="!options.length">处理全部市场</n-checkbox>
|
||||
</template>
|
||||
取消后可在下方指定市场
|
||||
</n-tooltip>
|
||||
<div v-if="options.length && !draft.allMarkets" class="scroll-box">
|
||||
<n-checkbox-group v-model:value="draft.chosen">
|
||||
<div v-for="item in options" :key="item.id" class="pick">
|
||||
<n-checkbox :value="item.id" :label="`${item.id} · ${item.name}`" />
|
||||
</div>
|
||||
</n-checkbox-group>
|
||||
</div>
|
||||
<p v-else-if="options.length" class="muted">将处理全部 {{ options.length }} 个市场</p>
|
||||
<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-form-item>
|
||||
<template #label>
|
||||
<n-tooltip><template #trigger><span class="tip">并行进程数</span></template>1 到 16,默认 4</n-tooltip>
|
||||
</template>
|
||||
<n-input-number v-model:value="draft.maxWorkers" :min="1" :max="16" :precision="0" style="width: 100%" />
|
||||
</n-form-item>
|
||||
<n-form-item>
|
||||
<template #label>
|
||||
<n-tooltip><template #trigger><span class="tip">分辨率倍数</span></template>放大查看更清晰,默认 5</n-tooltip>
|
||||
</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>
|
||||
</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>
|
||||
<TaskCard v-if="lastTask" :task="lastTask" log-open @changed="refreshTask" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.market-box { display: flex; flex-direction: column; gap: 8px; }
|
||||
.pick { padding: 2px 0; }
|
||||
.tip { border-bottom: 1px dashed #b7c2cc; cursor: help; }
|
||||
</style>
|
||||
Reference in New Issue
Block a user