feat: 页面配置页增加按站点类型默认模板编辑入口

This commit is contained in:
mediabot-pt
2026-07-06 00:29:02 +08:00
parent c140105cdc
commit c635d6459e

View File

@@ -5,6 +5,21 @@
<h2 style="margin:0">页面配置</h2>
<el-button size="small" @click="fetchAll" :icon="Refresh">刷新</el-button>
</div>
<!-- 默认模板 -->
<el-card style="margin-bottom:12px">
<template #header><span style="font-weight:500">站点类型默认模板</span></template>
<div style="display:flex;gap:12px;flex-wrap:wrap">
<div v-for="dt in defaultTypes" :key="dt" style="border:1px solid #ebeef5;border-radius:4px;padding:8px 12px;min-width:140px">
<div style="display:flex;align-items:center;gap:8px;justify-content:space-between">
<span><el-tag size="small">{{ dt }}</el-tag></span>
<el-button size="small" @click="editPage({siteId:'default:'+dt})">编辑</el-button>
</div>
</div>
</div>
</el-card>
<!-- 站点列表 -->
<el-table :data="merged" stripe v-loading="loading" border empty-text="暂无站点" style="font-size:13px" :row-style="{height:'44px'}">
<el-table-column prop="siteId" label="站点" width="140" />
<el-table-column label="名称" min-width="130">
@@ -73,6 +88,7 @@ import api from '../api'; import { Refresh } from '@element-plus/icons-vue'
const loading = ref(false), saving = ref(false), deleting = ref(false), sites = ref([]), pagesMap = ref({}), sitesList = ref([])
const editSiteId = ref(''), editorJson = ref('[]')
const defaultTypes = ['nexusphp','mtorrent','gazelle','unit3d']
const fmt = (t) => t ? (t.substring(0,19)||'').replace('T',' ') : '-'
const parsed = computed(() => { try { return JSON.parse(editorJson.value) } catch { return [] } })
const resolveUrl = (url) => url?.replace('{base}', sitesList.value.find(s=>s.siteId===editSiteId.value)?.urls?.[0] || '{base}') || ''
@@ -100,7 +116,10 @@ const fetchAll = async () => {
const editPage = async (row) => {
editSiteId.value = row.siteId
try { const r = await api.raw.get('/admin/site-pages/'+row.siteId); editorJson.value = (r?.data||r)?.entries ? JSON.stringify((r.data||r).entries, null, 2) : '[]' }
const url = row.siteId.startsWith('default:')
? '/admin/default-pages/' + row.siteId.replace('default:','')
: '/admin/site-pages/' + row.siteId
try { const r = await api.raw.get(url); editorJson.value = (r?.data||r)?.entries ? JSON.stringify((r.data||r).entries, null, 2) : '[]' }
catch { editorJson.value = '[]' }
}
@@ -117,8 +136,13 @@ const deletePages = async () => {
const savePages = async () => {
saving.value = true
try { await api.raw.put('/sites/'+editSiteId.value+'/pages', { entries: parsed.value }); ElMessage.success('已保存'); editSiteId.value=''; fetchAll() }
catch { ElMessage.error('保存失败') }
try {
const url = editSiteId.value.startsWith('default:')
? '/admin/default-pages/' + editSiteId.value.replace('default:','')
: '/sites/' + editSiteId.value + '/pages'
await api.raw.put(url, { entries: parsed.value })
ElMessage.success('已保存'); editSiteId.value=''; fetchAll()
} catch { ElMessage.error('保存失败') }
finally { saving.value = false }
}
onMounted(fetchAll)