feat: 默认页面模板增加上传按钮+对应后端接口

This commit is contained in:
mediabot-pt
2026-07-06 00:35:30 +08:00
parent c635d6459e
commit cf4c97daf5
2 changed files with 29 additions and 1 deletions

View File

@@ -46,6 +46,7 @@
<h2 style="margin:0">编辑: {{ editSiteId }}</h2>
<div style="display:flex;gap:8px">
<el-button size="small" type="primary" @click="savePages" :loading="saving">保存</el-button>
<el-button v-if="isDefaultEditor" size="small" @click="uploadPages" :loading="uploading">上传</el-button>
<el-button size="small" type="danger" @click="deletePages" :loading="deleting">删除</el-button>
<el-button size="small" @click="editSiteId=''">返回列表</el-button>
</div>
@@ -86,9 +87,10 @@
<script setup>
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 loading = ref(false), saving = ref(false), uploading = ref(false), deleting = ref(false), sites = ref([]), pagesMap = ref({}), sitesList = ref([])
const editSiteId = ref(''), editorJson = ref('[]')
const defaultTypes = ['nexusphp','mtorrent','gazelle','unit3d']
const isDefaultEditor = computed(() => editSiteId.value.startsWith('default:'))
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}') || ''
@@ -134,6 +136,16 @@ const deletePages = async () => {
finally { deleting.value = false }
}
const uploadPages = async () => {
uploading.value = true
try {
const type = editSiteId.value.replace('default:','')
await api.raw.put('/admin/default-pages/'+type+'/upload', { entries: parsed.value })
ElMessage.success('已上传到云存储')
} catch { ElMessage.error('上传失败') }
finally { uploading.value = false }
}
const savePages = async () => {
saving.value = true
try {