feat: 支持编辑 QGIS 工程模板图层
This commit is contained in:
@@ -0,0 +1,168 @@
|
||||
<script setup>
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { getJSON, putJSON } from '../api'
|
||||
|
||||
const props = defineProps({
|
||||
show: { type: Boolean, default: false },
|
||||
path: { type: String, default: '' },
|
||||
})
|
||||
const emit = defineEmits(['update:show'])
|
||||
|
||||
const loading = ref(false)
|
||||
const saving = ref(false)
|
||||
const error = ref('')
|
||||
const layers = ref([])
|
||||
|
||||
const visible = computed({
|
||||
get: () => props.show,
|
||||
set: (value) => emit('update:show', value),
|
||||
})
|
||||
|
||||
watch(() => props.show, (open) => {
|
||||
if (open) load()
|
||||
})
|
||||
|
||||
async function load() {
|
||||
if (!props.path) {
|
||||
error.value = '请先填写 QGIS 工程模板。'
|
||||
layers.value = []
|
||||
return
|
||||
}
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
const data = await getJSON(`/api/project?path=${encodeURIComponent(props.path)}`)
|
||||
layers.value = data.layers || []
|
||||
} catch (reason) {
|
||||
layers.value = []
|
||||
error.value = reason.message
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function move(index, step) {
|
||||
const next = index + step
|
||||
if (next < 0 || next >= layers.value.length) return
|
||||
const copy = layers.value.slice()
|
||||
const [item] = copy.splice(index, 1)
|
||||
copy.splice(next, 0, item)
|
||||
layers.value = copy
|
||||
}
|
||||
|
||||
function remove(index) {
|
||||
layers.value = layers.value.filter((_, item) => item !== index)
|
||||
}
|
||||
|
||||
function add(kind) {
|
||||
const xyz = kind === 'xyz'
|
||||
layers.value.unshift({
|
||||
id: `new:${crypto.randomUUID()}`,
|
||||
name: xyz ? 'XYZ 图层' : kind === 'raster' ? '栅格' : '矢量',
|
||||
checked: true,
|
||||
source: '',
|
||||
url: xyz ? 'https://example.com/{z}/{x}/{y}.png' : '',
|
||||
xyz,
|
||||
kind,
|
||||
zmin: xyz ? '0' : '',
|
||||
zmax: xyz ? '18' : '',
|
||||
referer: '',
|
||||
header: xyz,
|
||||
encoding: xyz ? 'quoted' : 'file',
|
||||
provider: xyz ? 'wms' : kind === 'raster' ? 'gdal' : 'ogr',
|
||||
geometry: kind === 'vector' ? 'Polygon' : 'raster',
|
||||
})
|
||||
}
|
||||
|
||||
async function save() {
|
||||
saving.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
const data = await putJSON('/api/project', {
|
||||
path: props.path,
|
||||
layers: layers.value.map((layer) => ({
|
||||
id: layer.id,
|
||||
name: layer.name,
|
||||
checked: layer.checked,
|
||||
source: layer.source,
|
||||
url: layer.url || '',
|
||||
xyz: !!layer.xyz,
|
||||
kind: layer.kind || '',
|
||||
zmin: layer.zmin || '',
|
||||
zmax: layer.zmax || '',
|
||||
referer: layer.referer || '',
|
||||
header: !!layer.header,
|
||||
encoding: layer.encoding || '',
|
||||
})),
|
||||
})
|
||||
layers.value = data.layers || []
|
||||
visible.value = false
|
||||
} catch (reason) {
|
||||
error.value = reason.message
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<n-modal
|
||||
v-model:show="visible"
|
||||
preset="card"
|
||||
title="QGIS 工程模板"
|
||||
style="width: min(920px, 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-button size="small" @click="add('vector')">新增矢量</n-button>
|
||||
<n-button size="small" @click="add('raster')">新增栅格</n-button>
|
||||
<n-button size="small" @click="add('xyz')">新增 XYZ</n-button>
|
||||
</div>
|
||||
<p class="muted">上面的图层画在上面。XYZ 地址按可读的 URL 编辑,保存时再编码成 QGIS 工程里的写法。出图时仍会按样式可见性配置调整部分图层的勾选,并加入专题和 online。</p>
|
||||
<n-spin :show="loading" class="list-spin">
|
||||
<div class="rows">
|
||||
<div v-for="(layer, index) in layers" :key="layer.id" class="layer">
|
||||
<div class="layer-head">
|
||||
<n-checkbox v-model:checked="layer.checked">显示</n-checkbox>
|
||||
<n-input v-model:value="layer.name" />
|
||||
<n-button size="small" :disabled="index === 0" @click="move(index, -1)">上移</n-button>
|
||||
<n-button size="small" :disabled="index === layers.length - 1" @click="move(index, 1)">下移</n-button>
|
||||
<n-button size="small" type="error" secondary :disabled="layers.length === 1" @click="remove(index)">删除</n-button>
|
||||
</div>
|
||||
<p class="muted">{{ layer.provider || '未知数据源' }}<template v-if="layer.geometry"> · {{ layer.geometry }}</template></p>
|
||||
<template v-if="layer.xyz">
|
||||
<n-input v-model:value="layer.url" type="textarea" placeholder="https://.../{z}/{x}/{y}.png" :autosize="{ minRows: 1, maxRows: 4 }" />
|
||||
<div class="zoom">
|
||||
<span class="muted">最小级别</span>
|
||||
<n-input v-model:value="layer.zmin" placeholder="0" />
|
||||
<span class="muted">最大级别</span>
|
||||
<n-input v-model:value="layer.zmax" placeholder="18" />
|
||||
</div>
|
||||
</template>
|
||||
<n-input v-else v-model:value="layer.source" type="textarea" placeholder="./图层.gpkg|layername=图层名" :autosize="{ minRows: 1, maxRows: 4 }" />
|
||||
</div>
|
||||
<p v-if="!loading && !layers.length" class="muted">没有图层。</p>
|
||||
</div>
|
||||
</n-spin>
|
||||
</div>
|
||||
<template #footer>
|
||||
<n-space justify="end">
|
||||
<n-button @click="visible = false">取消</n-button>
|
||||
<n-button type="primary" :loading="saving" :disabled="!layers.length" @click="save">保存</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; }
|
||||
.zoom { display: grid; grid-template-columns: auto minmax(0, 80px) auto minmax(0, 80px); gap: 8px; align-items: center; }
|
||||
.list-spin { flex: 1; min-height: 0; }
|
||||
.rows { max-height: 56vh; overflow: auto; display: flex; flex-direction: column; gap: 8px; }
|
||||
.layer { border: 1px solid #e4ebf1; border-radius: 8px; background: #fff; padding: 8px 10px; display: flex; flex-direction: column; gap: 6px; }
|
||||
.layer-head { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto auto; gap: 8px; align-items: center; }
|
||||
</style>
|
||||
@@ -2,6 +2,7 @@
|
||||
import { computed, onMounted, onUnmounted, reactive, ref, watch } from 'vue'
|
||||
import FileField from '../components/FileField.vue'
|
||||
import LayerEditor from '../components/LayerEditor.vue'
|
||||
import ProjectEditor from '../components/ProjectEditor.vue'
|
||||
import TaskCard from '../components/TaskCard.vue'
|
||||
import { getJSON, postJSON } from '../api'
|
||||
|
||||
@@ -35,6 +36,7 @@ const error = ref('')
|
||||
const success = ref('')
|
||||
const submitting = ref(false)
|
||||
const editingBoundary = ref(false)
|
||||
const editingProject = ref(false)
|
||||
const loadingMarkets = ref(false)
|
||||
const lastTask = ref(null)
|
||||
let marketTicket = 0
|
||||
@@ -184,8 +186,9 @@ onUnmounted(() => {
|
||||
: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 #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>
|
||||
</div>
|
||||
@@ -194,6 +197,7 @@ onUnmounted(() => {
|
||||
:path="draft.paths.MARKET_GPKG || ''"
|
||||
@changed="loadMarkets(draft.paths.MARKET_GPKG)"
|
||||
/>
|
||||
<ProjectEditor v-model:show="editingProject" :path="draft.paths.GIS_PROJECT_SOURCE || ''" />
|
||||
<h2 class="section-title">2 · 选择市场与参数</h2>
|
||||
<n-alert v-if="marketError" type="warning">{{ marketError }}</n-alert>
|
||||
<n-spin :show="loadingMarkets" size="small">
|
||||
|
||||
Reference in New Issue
Block a user