From 1ceaf89e0ffe0370a4bf7bcc9ce18b769563e901 Mon Sep 17 00:00:00 2001 From: mediabot-pt <295750538+mediabot-pt@users.noreply.github.com> Date: Sun, 5 Jul 2026 21:07:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=AB=99=E7=82=B9=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E5=8D=95=E7=AB=99=E7=BC=96=E8=BE=91+?= =?UTF-8?q?=E5=85=A8=E9=87=8F=E5=8F=AF=E8=A7=86=E5=8C=96=E8=A1=A8=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/views/Sites.vue | 82 ++++++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 37 deletions(-) diff --git a/web/src/views/Sites.vue b/web/src/views/Sites.vue index b4fdb71..9d30f08 100644 --- a/web/src/views/Sites.vue +++ b/web/src/views/Sites.vue @@ -9,23 +9,27 @@
刷新 - + 新建 - 保存 + 新建 + 保存
- -
-
pt-sites.json
+ +
+
+ {{ editSiteId ? '编辑: '+editSiteId : '选择站点编辑' }} +
- +
- + @@ -39,15 +43,16 @@ {{ s.row.status||'active' }} - + - + @@ -60,50 +65,49 @@ import api from '../api' const loading = ref(false), saving = ref(false), pendingCount = ref(0) -const editorJson = ref('[]') +const sites = ref([]), editSiteId = ref(''), editorJson = ref('{}') -const parsed = computed(() => { - try { return JSON.parse(editorJson.value) } catch { return [] } -}) +const rowClass = ({row}) => row.siteId === editSiteId.value ? 'current-row' : '' const refresh = async () => { loading.value = true try { const r = await api.raw.get('/admin/sites') - const sites = Array.isArray(r?.data) ? r.data : r || [] - editorJson.value = JSON.stringify(sites, null, 2) + sites.value = Array.isArray(r?.data) ? r.data : r || [] try { pendingCount.value = ((await api.sites.pendingChanges()).data || []).length } catch { pendingCount.value = 0 } } catch { ElMessage.error('加载失败') } finally { loading.value = false } } -const addSite = () => { - const arr = parsed.value - arr.push({ siteId: '', names: [''], urls: [''], siteType: 'nexusphp', status: 'active' }) - editorJson.value = JSON.stringify(arr, null, 2) +const editSite = (row) => { + editSiteId.value = row.siteId + editorJson.value = JSON.stringify({siteId: row.siteId, names: row.names, urls: row.urls, siteType: row.siteType, status: row.status||'active'}, null, 2) } -const removeSite = (idx) => { - const arr = parsed.value - if (arr.length <= 1) { ElMessage.warning('至少保留一个站点'); return } - arr.splice(idx, 1) - editorJson.value = JSON.stringify(arr, null, 2) +const newSite = () => { + editSiteId.value = '' + editorJson.value = JSON.stringify({siteId:'',names:[''],urls:[''],siteType:'nexusphp',status:'active'}, null, 2) } -const saveAll = async () => { +const deleteSite = async (row) => { + try { await ElMessageBox.confirm('确认删除 '+row.siteId+' ?','删除',{type:'warning'}) } catch { return } + try { + await api.raw.put('/admin/sites/'+row.siteId, {siteId:row.siteId,names:row.names,urls:row.urls,siteType:row.siteType,status:'deprecated'}) + ElMessage.success('已弃用') + refresh() + if (editSiteId.value === row.siteId) editSiteId.value = '' + } catch { ElMessage.error('操作失败') } +} + +const saveSite = async () => { saving.value = true try { - let ok = 0, fail = 0 - for (const site of parsed.value) { - if (!site.siteId) { fail++; continue } - try { - await api.raw.put('/admin/sites/'+site.siteId, { - names: site.names, urls: site.urls, siteType: site.siteType, status: site.status, - }) - ok++ - } catch { fail++ } - } - ElMessage.success('保存: '+ok+' 成功, '+fail+' 失败') + const site = JSON.parse(editorJson.value) + if (!site.siteId) { ElMessage.warning('siteId不能为空'); return } + await api.raw.put('/admin/sites/'+site.siteId, { + names: site.names||[], urls: site.urls||[], siteType: site.siteType||'unknown', status: site.status||'active', + }) + ElMessage.success('已保存') refresh() } catch { ElMessage.error('保存失败') } finally { saving.value = false } @@ -111,3 +115,7 @@ const saveAll = async () => { onMounted(refresh) + +