From 98e040c06be4e72343765c606618582f0118cd56 Mon Sep 17 00:00:00 2001 From: mediabot-pt <295750538+mediabot-pt@users.noreply.github.com> Date: Mon, 29 Jun 2026 22:55:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=85=8D=E7=BD=AE=E5=AE=A1=E6=A0=B8?= =?UTF-8?q?=E9=A1=B5=E5=A2=9E=E5=8A=A0=E6=9F=A5=E7=9C=8B=E8=AF=A6=E6=83=85?= =?UTF-8?q?=EF=BC=88=E8=AF=AD=E6=B3=95=E9=AB=98=E4=BA=AEJSON=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/api/index.js | 1 + web/src/views/Configs.vue | 89 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 89 insertions(+), 1 deletion(-) diff --git a/web/src/api/index.js b/web/src/api/index.js index 8b7dcaf..5155377 100644 --- a/web/src/api/index.js +++ b/web/src/api/index.js @@ -39,6 +39,7 @@ export default { configs: { list: () => api.get('/configs'), pending: () => api.get('/configs/pending'), + download: (siteId, version) => api.get(`/configs/${siteId}/${version}`, { responseType: 'text' }), approve: (id, comment) => api.post(`/admin/reviews/${id}/approve`, null, { params: { comment } }), reject: (id, comment) => api.post(`/admin/reviews/${id}/reject`, null, { params: { comment } }) }, diff --git a/web/src/views/Configs.vue b/web/src/views/Configs.vue index a563439..c50ef35 100644 --- a/web/src/views/Configs.vue +++ b/web/src/views/Configs.vue @@ -11,14 +11,29 @@ - + + + +
+ 站点: {{ viewing.siteId }}   + 版本: {{ viewing.version }}   + 提交者: {{ viewing.submitterId || '-' }} +
+
+

+      
+ +
@@ -27,6 +42,9 @@ import api from '../api' const pendingConfigs = ref([]) const loading = ref(false) +const viewVisible = ref(false) +const viewing = ref({}) +const configContent = ref('') const fetchPending = async () => { loading.value = true @@ -40,6 +58,48 @@ const fetchPending = async () => { } } +const handleView = async (row) => { + viewing.value = row + configContent.value = '' + viewVisible.value = true + try { + const res = await api.configs.download(row.siteId, row.version) + configContent.value = typeof res === 'string' ? res : JSON.stringify(res, null, 2) + } catch { + configContent.value = '(加载失败)' + } +} + +const highlightedJson = computed(() => { + try { + const obj = JSON.parse(configContent.value) + return syntaxHighlight(JSON.stringify(obj, null, 2)) + } catch { + return escapeHtml(configContent.value) + } +}) + +const syntaxHighlight = (json) => { + return escapeHtml(json).replace( + /("(\\u[a-fA-F0-9]{4}|\\[^u]|[^"\\])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, + (match) => { + let cls = 'number' + if (/^"/.test(match)) { + cls = /:$/.test(match) ? 'key' : 'string' + } else if (/true|false/.test(match)) { + cls = 'boolean' + } else if (/null/.test(match)) { + cls = 'null' + } + return `${match}` + } + ) +} + +const escapeHtml = (str) => { + return str.replace(/&/g, '&').replace(//g, '>') +} + const handleApprove = async (row) => { try { await ElMessageBox.confirm(`确认通过站点 ${row.siteId} 的配置版本 ${row.version}?`, '提示') @@ -68,3 +128,30 @@ const handleReject = async (row) => { onMounted(fetchPending) + +