From cf093c0d471fd736a42cb151788e61c29f17bfb4 Mon Sep 17 00:00:00 2001 From: air <30444667+sszdot@users.noreply.github.com> Date: Tue, 23 Sep 2025 18:10:18 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E7=B1=BB=20=20=E5=9E=8B=E3=80=91?= =?UTF-8?q?=EF=BC=9Afix=20=E3=80=90=E5=8E=9F=20=20=E5=9B=A0=E3=80=91?= =?UTF-8?q?=EF=BC=9A=E5=9C=B0=E5=9B=BE=E6=B7=BB=E5=8A=A0=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=20=E3=80=90=E8=BF=87=20=20=E7=A8=8B=E3=80=91=EF=BC=9A=20?= =?UTF-8?q?=E3=80=90=E5=BD=B1=20=20=E5=93=8D=E3=80=91=EF=BC=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/index.js | 94 +++++++++- src/styles/index.scss | 4 + .../layout/components/main/mapstyle/add.vue | 160 +++++++----------- 3 files changed, 159 insertions(+), 99 deletions(-) diff --git a/src/store/index.js b/src/store/index.js index 63becd8..ec7a544 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1213,9 +1213,11 @@ const store = new Vuex.Store({ if (res.data.status === 1) { const host = rootState.settings.host const list = res.data.mapStyleList.map(style => { - const tiles = Array.isArray(style.tiles) ? style.tiles : JSON.parse(style.tiles) + // 使用 url 字段,并包装成数组 + const tiles = style.url ? [style.url] : (Array.isArray(style.tiles) ? style.tiles : []) const sourceKey = 'default' const spriteUrl = style.sprite && String(style.sprite).trim() ? style.sprite : `${host}/Public/map/sprite` + const glyphs = style.glyphs || 'mapbox://fonts/mapbox/{fontstack}/{range}.pbf' return { // 附带原始字段,便于管理端展示和操作 @@ -1224,13 +1226,13 @@ const store = new Vuex.Store({ sort_order: Number(style.sort_order ?? 0), name: style.name, sprite: spriteUrl, - glyphs: 'mapbox://fonts/mapbox/{fontstack}/{range}.pbf', + glyphs: glyphs, version: 8, sources: { [sourceKey]: { type: 'raster', tileSize: 256, - tiles, + tiles: tiles, attribution: '' } }, @@ -1238,7 +1240,13 @@ const store = new Vuex.Store({ id: `${sourceKey}Layer`, type: 'raster', source: sourceKey - }] + }], + // 保存原始URL用于编辑 + _original: { + url: style.url || (tiles.length > 0 ? tiles[0] : ''), + sprite: style.sprite, + glyphs: style.glyphs + } } }) commit('setMapStyleList', list) @@ -1307,6 +1315,84 @@ const store = new Vuex.Store({ } return Promise.reject(new Error('用户取消删除')) } + }, + /** + * @description: 添加地图样式 + * @param {Object} form 地图样式表单数据 + * @param {string} form.name 样式名称 + * @param {string} form.url 样式URL + * @param {string} form.thumbnail 缩略图URL + * @param {number} form.sort_order 排序值 + * @return {Promise} 返回包含服务器响应的Promise + */ + async addMapStyle ({ dispatch }, form) { + // 参数验证 + if (!form || typeof form !== 'object') { + throw new Error('无效的表单数据') + } + + if (!form.name || !form.name.trim()) { + throw new Error('样式名称不能为空') + } + + if (!form.url || !form.url.trim()) { + throw new Error('样式URL不能为空') + } + + // 处理form参数为URLSearchParams格式 + const params = new URLSearchParams() + params.append('name', form.name) + params.append('sprite', form.sprite || '') + params.append('glyphs', form.glyphs || 'mapbox://fonts/mapbox/{fontstack}/{range}.pbf') + params.append('url', form.url) + params.append('is_active', form.is_active ? 1 : 0) + params.append('sort_order', form.sort_order || 0) + + // 发送请求 + const res = await api.post('addMapStyle', params, 'Plane') + + // 检查响应状态 + if (res.data.status === 1) { + await dispatch('fetchMapStyleList') // 刷新列表 + Message.success(res.data.msg) + } else { + Message.error(res.data.msg) + } + return res + }, + + async saveMapStyle ({ dispatch }, form) { + // 参数验证 + if (!form || typeof form !== 'object') { + throw new Error('无效的表单数据') + } + + if (!form.id) { + throw new Error('缺少样式ID') + } + + // 处理form参数为URLSearchParams格式 + const params = new URLSearchParams() + params.append('id', form.id) + + if (form.name !== undefined) params.append('name', form.name) + if (form.sprite !== undefined) params.append('sprite', form.sprite) + if (form.glyphs !== undefined) params.append('glyphs', form.glyphs) + if (form.url !== undefined) params.append('url', form.url) + if (form.is_active !== undefined) params.append('is_active', form.is_active ? 1 : 0) + if (form.sort_order !== undefined) params.append('sort_order', form.sort_order) + + // 发送请求 + const res = await api.post('saveMapStyle', params, 'Plane') + + // 检查响应状态 + if (res.data.status === 1) { + await dispatch('fetchMapStyleList') // 刷新列表 + Message.success(res.data.msg) + } else { + Message.error(res.data.msg) + } + return res } }, modules: { diff --git a/src/styles/index.scss b/src/styles/index.scss index 10986d1..da9e2cc 100644 --- a/src/styles/index.scss +++ b/src/styles/index.scss @@ -141,6 +141,10 @@ label { padding-left: 25px !important; } +.el-form-item__error { + left: 25px !important; +} + /* 当屏幕宽度小于等于480px时 */ @media (max-width: 480px) { .el-dialog { diff --git a/src/views/layout/components/main/mapstyle/add.vue b/src/views/layout/components/main/mapstyle/add.vue index 93b5577..d9dd5d8 100644 --- a/src/views/layout/components/main/mapstyle/add.vue +++ b/src/views/layout/components/main/mapstyle/add.vue @@ -10,7 +10,8 @@ - +
@@ -19,11 +20,7 @@
- - - - - + @@ -35,29 +32,28 @@
- 资源与源配置 + 资源与源配置(84坐标系)
- + - - + + - + {{ pageState === 'add' ? '创建' : '更新' }} @@ -71,7 +67,7 @@ - +