feat: 新增市场边界编辑并修正 Vue 列表布局

This commit is contained in:
nixevol
2026-10-15 00:22:26 +08:00
parent 0c668e473e
commit 81daf9f266
14 changed files with 901 additions and 15 deletions
+9 -1
View File
@@ -96,5 +96,13 @@ function go(key) {
z-index: 2;
}
.topbar h1 { margin: 0; font-size: 16px; font-weight: 600; }
.page-body { flex: 1; min-height: 0; overflow: auto; padding: 12px 16px 16px; background: #f5f7f9; }
.page-body {
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
overflow: auto;
padding: 12px 16px 16px;
background: #f5f7f9;
}
</style>
+4
View File
@@ -42,6 +42,10 @@ export function postJSON(path, body) {
return request(path, { method: 'POST', body: JSON.stringify(body) })
}
export function putJSON(path, body) {
return request(path, { method: 'PUT', body: JSON.stringify(body) })
}
export function del(path) {
return request(path, { method: 'DELETE' })
}
+2 -1
View File
@@ -77,6 +77,7 @@ async function customRequest({ file, onFinish, onError, onProgress }) {
{{ 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>
@@ -105,6 +106,6 @@ async function customRequest({ file, onFinish, onError, onProgress }) {
<style scoped>
.file-field { display: flex; flex-direction: column; gap: 8px; }
.file-title { font-weight: 600; }
.file-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-weight: 600; }
.hint { border-bottom: 1px dashed #b7c2cc; cursor: help; }
</style>
+274
View File
@@ -0,0 +1,274 @@
<script setup>
import { computed, ref, watch } from 'vue'
import { del, getJSON, postJSON, putJSON } from '../api'
const props = defineProps({
show: { type: Boolean, default: false },
path: { type: String, default: '' },
})
const emit = defineEmits(['update:show', 'changed'])
const loading = ref(false)
const saving = ref(false)
const error = ref('')
const keyword = ref('')
const layer = ref(null)
const detail = ref(false)
const draft = ref(null)
const removing = ref(null)
const clearing = ref(false)
const visible = computed({
get: () => props.show,
set: (value) => emit('update:show', value),
})
const editable = computed(() => (layer.value?.columns || []).filter((column) => !column.primary))
const gridColumns = computed(() => {
const fields = editable.value.map(() => 'minmax(100px, 1fr)').join(' ')
return `72px ${fields} minmax(180px, 1.6fr) 112px`.replace(' ', ' ')
})
const filtered = computed(() => {
const rows = layer.value?.features || []
const query = keyword.value.trim().toLowerCase()
if (!query) return rows
return rows.filter((row) => {
const text = [row.fid, row.summary, row.wkt, ...Object.values(row.values || {})].join(' ').toLowerCase()
return text.includes(query)
})
})
watch(() => props.show, (open) => {
if (open) load()
})
async function load() {
if (!props.path) {
error.value = '请先填写市场边界文件。'
layer.value = null
return
}
loading.value = true
error.value = ''
try {
layer.value = await getJSON(`/api/layer?path=${encodeURIComponent(props.path)}`)
} catch (reason) {
layer.value = null
error.value = reason.message
} finally {
loading.value = false
}
}
function blankValues() {
return Object.fromEntries(editable.value.map((column) => [column.name, '']))
}
function openCreate() {
draft.value = { fid: null, wkt: '', values: blankValues() }
detail.value = true
}
function openEdit(row) {
const values = blankValues()
for (const column of editable.value) {
const value = row.values?.[column.name]
values[column.name] = value == null ? '' : String(value)
}
draft.value = { fid: row.fid, wkt: row.wkt, values }
detail.value = true
}
async function save() {
if (!draft.value) return
saving.value = true
error.value = ''
const body = { path: props.path, wkt: draft.value.wkt, values: draft.value.values }
try {
if (draft.value.fid == null) await postJSON('/api/layer/features', body)
else await putJSON(`/api/layer/features/${draft.value.fid}`, body)
detail.value = false
await load()
emit('changed')
} catch (reason) {
error.value = reason.message
} finally {
saving.value = false
}
}
async function confirmClear() {
clearing.value = false
saving.value = true
error.value = ''
try {
await postJSON('/api/layer/clear', { path: props.path, wkt: '', values: {} })
await load()
emit('changed')
} catch (reason) {
error.value = reason.message
} finally {
saving.value = false
}
}
async function confirmRemove() {
if (!removing.value) return
saving.value = true
error.value = ''
try {
await del(`/api/layer/features/${removing.value.fid}?path=${encodeURIComponent(props.path)}`)
removing.value = null
await load()
emit('changed')
} catch (reason) {
error.value = reason.message
} finally {
saving.value = false
}
}
function textOf(row, name) {
const value = row.values?.[name]
return value == null ? '' : String(value)
}
</script>
<template>
<n-modal
v-model:show="visible"
preset="card"
title="市场边界"
style="width: min(1080px, 94vw)"
:segmented="{ content: true, footer: 'soft' }"
:content-style="{ maxHeight: '72vh', overflow: 'hidden', display: 'flex' }"
>
<div class="editor">
<n-alert v-if="error" type="error">{{ error }}</n-alert>
<div class="toolbar">
<n-input v-model:value="keyword" clearable placeholder="搜索名称、编号或边界" />
<n-button :disabled="!layer?.count" @click="clearing = true">一键清空</n-button>
<n-button type="primary" :disabled="!layer" @click="openCreate">新增</n-button>
</div>
<p v-if="layer" class="muted">{{ layer.table }} · {{ layer.geometry_type }} · {{ layer.count }} 条</p>
<n-spin :show="loading" class="list-spin">
<div class="rows">
<div class="row head" :style="{ gridTemplateColumns: gridColumns }">
<span>fid</span>
<span v-for="column in editable" :key="column.name">{{ column.name }}</span>
<span>边界</span>
<span></span>
</div>
<p v-if="layer && !filtered.length" class="muted empty">没有边界。</p>
<div v-for="row in filtered" :key="row.fid" class="row" :style="{ gridTemplateColumns: gridColumns }">
<span>{{ row.fid }}</span>
<span v-for="column in editable" :key="column.name" :title="textOf(row, column.name)">{{ textOf(row, column.name) }}</span>
<span :title="row.wkt">{{ row.summary }}</span>
<span class="actions">
<n-button text type="primary" @click="openEdit(row)">编辑</n-button>
<n-button text type="error" @click="removing = row">删除</n-button>
</span>
</div>
</div>
</n-spin>
</div>
<template #footer>
<n-space justify="end">
<n-button @click="visible = false">关闭</n-button>
</n-space>
</template>
</n-modal>
<n-modal
v-model:show="detail"
preset="card"
:title="draft?.fid == null ? '新增边界' : `编辑边界 ${draft.fid}`"
style="width: min(760px, 94vw)"
:segmented="{ content: true, footer: 'soft' }"
:content-style="{ maxHeight: '68vh', overflow: 'auto' }"
>
<n-form v-if="draft" label-placement="left" label-width="88" :show-feedback="false">
<n-form-item v-for="column in editable" :key="column.name" :label="column.name">
<n-input v-model:value="draft.values[column.name]" clearable />
</n-form-item>
<n-form-item label="边界">
<n-input
v-model:value="draft.wkt"
type="textarea"
placeholder="POLYGON((经度 纬度, ...)) 或 MULTIPOLYGON(...)"
:autosize="{ minRows: 6, maxRows: 14 }"
/>
</n-form-item>
</n-form>
<template #footer>
<n-space justify="end">
<n-button @click="detail = false">取消</n-button>
<n-button type="primary" :loading="saving" @click="save">保存</n-button>
</n-space>
</template>
</n-modal>
<n-modal
v-model:show="clearing"
preset="card"
title="清空全部边界"
style="width: 440px"
:segmented="{ content: true, footer: 'soft' }"
>
<p>将删除当前图层的全部 {{ layer?.count || 0 }} 条边界,不可恢复。</p>
<template #footer>
<n-space justify="end">
<n-button @click="clearing = false">取消</n-button>
<n-button type="primary" :loading="saving" @click="confirmClear">确认清空</n-button>
</n-space>
</template>
</n-modal>
<n-modal
:show="!!removing"
preset="card"
title="删除边界"
style="width: 420px"
:segmented="{ content: true, footer: 'soft' }"
@update:show="(value) => { if (!value) removing = null }"
>
<p>删除 fid {{ removing?.fid }}{{ removing?.values?.Name ? `(${removing.values.Name})` : '' }}?删除后不可恢复。</p>
<template #footer>
<n-space justify="end">
<n-button @click="removing = null">取消</n-button>
<n-button type="primary" :loading="saving" @click="confirmRemove">确认删除</n-button>
</n-space>
</template>
</n-modal>
</template>
<style scoped>
.editor { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 8px; width: 100%; }
.toolbar { display: flex; gap: 8px; align-items: center; }
.toolbar .n-input { flex: 1; }
.list-spin { flex: 1; min-height: 0; display: flex; }
.list-spin :deep(.n-spin-content) { flex: 1; min-height: 0; display: flex; }
.rows {
flex: 1;
min-height: 240px;
max-height: 52vh;
overflow: auto;
border: 1px solid #e4ebf1;
border-radius: 8px;
background: #fff;
}
.row {
display: grid;
gap: 8px;
align-items: center;
padding: 7px 10px;
border-bottom: 1px solid #f0f3f6;
}
.row span {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.row.head { position: sticky; top: 0; background: #f7f9fb; font-weight: 600; z-index: 1; }
.actions { display: flex; justify-content: flex-end; gap: 8px; overflow: visible; }
.empty { padding: 16px; }
</style>
+36
View File
@@ -17,6 +17,25 @@ body {
max-width: 1120px;
}
.page.fill {
flex: 1;
align-self: stretch;
width: auto;
max-width: none;
min-height: 0;
overflow: hidden;
}
.page.fill > * {
flex: none;
}
.page.fill > .task-list,
.page.fill > .file-list {
flex: 1 1 auto;
min-height: 0;
}
.section-title {
margin: 4px 0 0;
font-size: 14px;
@@ -48,6 +67,23 @@ body {
line-height: 1.5;
}
/* 左侧标题只跟控件同一行,并在这一行里垂直居中。校验提示留在下一行,不再把标题顶到上沿。 */
.n-form-item--left-labelled > .n-form-item-label {
grid-row: 1 / 2;
align-self: start;
height: 32px !important;
min-height: 32px !important;
}
.n-form-item--left-labelled > .n-form-item-blank {
min-height: 32px;
align-items: center;
}
.n-form-item--left-labelled > .n-form-item-feedback-wrapper:empty {
min-height: 0;
height: 0;
padding: 0;
}
.scroll-box {
max-height: 280px;
overflow: auto;
-3
View File
@@ -34,9 +34,6 @@ onMounted(load)
<teleport to="#page-actions">
<n-button :loading="loading" @click="load">刷新</n-button>
</teleport>
<n-alert type="info">
这是供对比的 Vue 界面,Streamlit 仍从 start-ui.cmd 进入。几何编辑和规则引擎是后续能力,当前未提供。
</n-alert>
<n-alert v-if="error" type="error">{{ error }}</n-alert>
<div class="metrics">
<div class="panel metric"><span>正在运行</span><strong>{{ home.running }}</strong></div>
+12 -1
View File
@@ -1,6 +1,7 @@
<script setup>
import { computed, onMounted, onUnmounted, reactive, ref, watch } from 'vue'
import FileField from '../components/FileField.vue'
import LayerEditor from '../components/LayerEditor.vue'
import TaskCard from '../components/TaskCard.vue'
import { getJSON, postJSON } from '../api'
@@ -33,6 +34,7 @@ const marketError = ref('')
const error = ref('')
const success = ref('')
const submitting = ref(false)
const editingBoundary = ref(false)
const loadingMarkets = ref(false)
const lastTask = ref(null)
let marketTicket = 0
@@ -181,8 +183,17 @@ onUnmounted(() => {
:label="item.label"
:extension="item.extension"
:hint="item.hint"
/>
>
<template v-if="item.key === 'MARKET_GPKG'" #extra>
<n-button size="small" :disabled="!draft.paths.MARKET_GPKG" @click="editingBoundary = true">编辑图层</n-button>
</template>
</FileField>
</div>
<LayerEditor
v-model:show="editingBoundary"
:path="draft.paths.MARKET_GPKG || ''"
@changed="loadMarkets(draft.paths.MARKET_GPKG)"
/>
<h2 class="section-title">2 · 选择市场与参数</h2>
<n-alert v-if="marketError" type="warning">{{ marketError }}</n-alert>
<n-spin :show="loadingMarkets" size="small">
+5 -4
View File
@@ -69,7 +69,7 @@ onMounted(loadTasks)
</script>
<template>
<div class="page">
<div class="page fill">
<teleport to="#page-actions">
<n-button :disabled="!selectedId" :loading="opening" @click="openDirectory">打开目录</n-button>
</teleport>
@@ -77,8 +77,8 @@ onMounted(loadTasks)
<n-alert v-if="notice" type="info">{{ notice }}</n-alert>
<n-empty v-if="!tasks.length" description="暂无成果。完成出图或查询后会显示在这里。" />
<template v-else>
<n-form label-placement="left" label-width="88">
<n-form-item label="成果清单">
<n-form label-placement="left" label-width="88" :show-feedback="false">
<n-form-item label="成果清单" :show-feedback="false">
<n-select v-model:value="selectedId" :options="options" />
</n-form-item>
</n-form>
@@ -98,7 +98,8 @@ onMounted(loadTasks)
<style scoped>
.file-list {
max-height: 420px;
flex: 1;
min-height: 0;
overflow: auto;
border: 1px solid #e4ebf1;
border-radius: 8px;
+3 -3
View File
@@ -45,7 +45,7 @@ onUnmounted(() => clearInterval(pollTimer))
</script>
<template>
<div class="page">
<div class="page fill">
<teleport to="#page-actions">
<n-button :disabled="!finishedCount || confirming" @click="confirming = true">清空全部任务</n-button>
</teleport>
@@ -76,11 +76,11 @@ onUnmounted(() => clearInterval(pollTimer))
<style scoped>
.task-list {
max-height: calc(100vh - 150px);
flex: 1;
min-height: 0;
overflow: auto;
display: flex;
flex-direction: column;
gap: 10px;
padding-right: 2px;
}
</style>