diff --git a/web/src/components/TaskCard.vue b/web/src/components/TaskCard.vue
index 22c87cd..1c4238f 100644
--- a/web/src/components/TaskCard.vue
+++ b/web/src/components/TaskCard.vue
@@ -5,6 +5,7 @@ import { del, formatTime, getJSON, postJSON } from '../api'
const props = defineProps({
task: { type: Object, required: true },
logOpen: { type: Boolean, default: false },
+ focusLog: { type: Boolean, default: false },
})
const emit = defineEmits(['changed'])
@@ -27,7 +28,7 @@ const countText = computed(() => {
})
watch(() => [props.task.message, props.task.done, props.task.status], () => {
- if (expanded.value) loadLog()
+ if (props.focusLog || expanded.value) loadLog()
})
function onExpand(names) {
@@ -36,7 +37,7 @@ function onExpand(names) {
}
onMounted(() => {
- if (props.logOpen) loadLog()
+ if (props.logOpen || props.focusLog) loadLog()
})
async function loadLog() {
@@ -94,8 +95,12 @@ async function remove() {
停止任务
删除任务
-
成果目录:{{ task.output }}
-
+ 成果目录:{{ task.output }}
+
+
{{ logError }}
+
{{ log || '等待任务输出……' }}
+
+
{{ logError }}
@@ -133,6 +138,7 @@ header span, .message { margin: 0; }
border-radius: 6px;
padding: 8px;
}
+.log-box.focus { max-height: min(52vh, 480px); min-height: 220px; }
pre {
margin: 0;
white-space: pre-wrap;
diff --git a/web/src/views/Market.vue b/web/src/views/Market.vue
index 482a076..0bc2b86 100644
--- a/web/src/views/Market.vue
+++ b/web/src/views/Market.vue
@@ -38,7 +38,6 @@ const step = ref(1)
const options = ref([])
const marketError = ref('')
const error = ref('')
-const success = ref('')
const submitting = ref(false)
const opening = ref(false)
const editingBoundary = ref(false)
@@ -46,9 +45,11 @@ const editingProject = ref(false)
const settingsOpen = ref(false)
const loadingMarkets = ref(false)
const lastTask = ref(null)
+const FORM_KEY = 'marketgrid.market-form'
let marketTicket = 0
let marketTimer = 0
let pollTimer = 0
+let persistReady = false
const neededSourceKeys = computed(() => {
const keys = new Set(alwaysSources.value)
@@ -68,7 +69,8 @@ const fileItems = computed(() => {
}
return items
})
-const canStart = computed(() => draft.ready && options.value.length > 0 && !submitting.value)
+const taskBusy = computed(() => !!lastTask.value?.active)
+const canStart = computed(() => draft.ready && options.value.length > 0 && !submitting.value && !taskBusy.value)
const clipOptions = [
{ label: '与网格相交', value: 'intersects' },
{ label: '中心点在网格内', value: 'center' },
@@ -85,21 +87,86 @@ function onFileAction(item, key) {
if (item.key === 'GIS_PROJECT_SOURCE' && key === 'project') editingProject.value = true
}
+function persistForm() {
+ if (!persistReady) return
+ const payload = {
+ paths: { ...draft.paths },
+ allMarkets: draft.allMarkets,
+ chosen: [...draft.chosen],
+ maxWorkers: draft.maxWorkers,
+ scale: draft.scale,
+ summary: draft.summary,
+ maxRaster: draft.maxRaster,
+ summaryRaster: draft.summaryRaster,
+ clipMode: draft.clipMode,
+ padding: draft.padding,
+ lastTaskId: draft.lastTaskId,
+ layerPlan: JSON.parse(JSON.stringify(layerPlan)),
+ step: step.value,
+ }
+ localStorage.setItem(FORM_KEY, JSON.stringify(payload))
+}
+
+function restoreForm() {
+ let saved
+ try {
+ saved = JSON.parse(localStorage.getItem(FORM_KEY) || 'null')
+ } catch {
+ return
+ }
+ if (!saved || typeof saved !== 'object') return
+ if (saved.paths && typeof saved.paths === 'object') Object.assign(draft.paths, saved.paths)
+ if (typeof saved.allMarkets === 'boolean') draft.allMarkets = saved.allMarkets
+ if (Array.isArray(saved.chosen)) draft.chosen = saved.chosen
+ for (const key of ['maxWorkers', 'scale', 'maxRaster', 'summaryRaster', 'padding']) {
+ if (typeof saved[key] === 'number') draft[key] = saved[key]
+ }
+ if (typeof saved.summary === 'boolean') draft.summary = saved.summary
+ if (saved.clipMode === 'intersects' || saved.clipMode === 'center') draft.clipMode = saved.clipMode
+ if (typeof saved.lastTaskId === 'string') draft.lastTaskId = saved.lastTaskId
+ if (saved.layerPlan && typeof saved.layerPlan === 'object') {
+ for (const [key, value] of Object.entries(saved.layerPlan)) {
+ if (!value || typeof value !== 'object') continue
+ const enabled = !!value.enabled
+ layerPlan[key] = { enabled, visible: enabled && !!value.visible }
+ }
+ }
+ if (saved.step >= 1 && saved.step <= 4) step.value = saved.step
+ draft.ready = true
+}
+
function setLayerEnabled(key, enabled) {
layerPlan[key].enabled = enabled
if (!enabled) layerPlan[key].visible = false
}
-function nextStep() {
+function validateThrough(through) {
error.value = ''
- if (step.value === 2) {
+ if (through >= 1 && !outputLayers.value.some((item) => layerPlan[item.key]?.enabled)) {
+ error.value = '请至少选择一个要生成的图层。'
+ step.value = 1
+ return false
+ }
+ if (through >= 2) {
for (const item of fileItems.value) {
if (!draft.paths[item.key]) {
error.value = `请先填写${item.label}。`
- return
+ step.value = 2
+ return false
}
}
}
+ return true
+}
+
+function goStep(target) {
+ if (target < 1 || target > 4 || target === step.value) return
+ if (target > step.value && !validateThrough(target - 1)) return
+ step.value = target
+}
+
+function nextStep() {
+ if (!validateThrough(step.value) || step.value >= 3) return
step.value += 1
}
@@ -112,11 +179,11 @@ async function ensureCatalog() {
for (const item of outputLayers.value) {
if (!layerPlan[item.key]) layerPlan[item.key] = { enabled: true, visible: item.visible }
}
- 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
+ for (const item of data.sources) {
+ if (!(item.key in draft.paths)) draft.paths[item.key] = item.path
}
+ if (data.nr_csv && !(data.nr_csv.key in draft.paths)) draft.paths[data.nr_csv.key] = data.nr_csv.path
+ draft.ready = true
}
async function loadMarkets(path) {
@@ -159,11 +226,28 @@ async function refreshTask() {
if (!draft.lastTaskId) return
try {
lastTask.value = await getJSON(`/api/tasks/${encodeURIComponent(draft.lastTaskId)}`)
- } catch {
- // 轮询失败时保留上一帧。
+ } catch (reason) {
+ if (String(reason.message || '').includes('不存在')) {
+ lastTask.value = null
+ draft.lastTaskId = ''
+ }
}
}
+async function restoreTask() {
+ if (!draft.lastTaskId) {
+ try {
+ const data = await getJSON('/api/tasks')
+ const running = (data.tasks || []).find((item) => item.kind === 'market' && item.active)
+ if (running) draft.lastTaskId = running.id
+ } catch {
+ // 没有任务列表时仍显示已保存的配置。
+ }
+ }
+ await refreshTask()
+ if (lastTask.value?.active) step.value = 4
+}
+
function numbersReady() {
return [draft.maxWorkers, draft.scale, draft.maxRaster, draft.summaryRaster, draft.padding]
.every((value) => typeof value === 'number')
@@ -171,7 +255,10 @@ function numbersReady() {
async function submit() {
error.value = ''
- success.value = ''
+ if (taskBusy.value) {
+ step.value = 4
+ return
+ }
if (!canStart.value) return
if (!numbersReady()) {
error.value = '请填写完整参数。'
@@ -206,7 +293,7 @@ async function submit() {
},
})
draft.lastTaskId = result.id
- success.value = '任务已启动,可在任务中心查看进度。'
+ step.value = 4
await refreshTask()
} catch (reason) {
error.value = reason.message
@@ -220,14 +307,21 @@ watch(() => draft.paths.MARKET_GPKG, (path) => {
marketTimer = setTimeout(() => loadMarkets(path), 300)
})
+watch(draft, persistForm, { deep: true })
+watch(layerPlan, persistForm, { deep: true })
+watch(step, persistForm)
+
onMounted(async () => {
+ restoreForm()
try {
await ensureCatalog()
await loadMarkets(draft.paths.MARKET_GPKG)
+ await restoreTask()
} catch (reason) {
error.value = reason.message
}
- await refreshTask()
+ persistReady = true
+ persistForm()
pollTimer = setInterval(refreshTask, 2000)
})
@@ -249,12 +343,16 @@ onUnmounted(() => {
-
-
-
+
+
+
+
{{ error }}
- {{ success }}
+
+ 正在处理{{ lastTask.message ? `:${lastTask.message}` : '' }}。
+ 查看日志
+