1.修改首页下载功能

This commit is contained in:
whm
2026-03-18 18:43:23 +08:00
parent c67346626a
commit b17e99eb93
4 changed files with 150 additions and 8 deletions

View File

@@ -43,14 +43,16 @@
<el-input v-model="form.download_text" placeholder="START EXPLORING" />
</el-form-item>
<el-form-item label="按钮链接">
<el-input v-model="form.download_url" placeholder="#" />
<el-input v-model="form.download_url" placeholder="#" style="flex: 1" />
<el-button type="primary" link @click="openFilePicker('download')">选择可下载文件</el-button>
</el-form-item>
<el-divider content-position="left">平台轨道</el-divider>
<el-form-item label="平台列表">
<div v-for="(p, i) in form.platforms" :key="i" style="display: flex; gap: 8px; margin-bottom: 8px">
<div v-for="(p, i) in form.platforms" :key="i" style="display: flex; gap: 8px; margin-bottom: 8px; align-items: center">
<el-input v-model="p.name" placeholder="如 WINDOWS" style="width: 140px" />
<el-input v-model="p.url" placeholder="链接" style="flex: 1" />
<el-button type="primary" link @click="openFilePicker('platform', i)">选择文件</el-button>
<el-button link type="danger" @click="form.platforms.splice(i, 1)">删除</el-button>
</div>
<el-button link type="primary" @click="form.platforms.push({ name: '', url: '#' })">+ 添加平台</el-button>
@@ -84,13 +86,31 @@
<el-empty v-else description="请先选择站点" />
</el-card>
<el-dialog v-model="filePickerVisible" title="选择可下载文件" width="640px">
<el-table
v-loading="fileListLoading"
:data="downloadableFiles"
highlight-current-row
@current-change="onSelectFile"
>
<el-table-column property="name" label="文件名" min-width="180" />
<el-table-column property="file_path" label="路径" min-width="200" show-overflow-tooltip />
<el-table-column label="操作" width="100">
<template #default="{ row }">
<el-button type="primary" link @click="confirmSelectFile(row)">选择</el-button>
</template>
</el-table-column>
</el-table>
<el-empty v-if="!fileListLoading && downloadableFiles.length === 0" description="暂无可下载文件,请在文件管理中上传并勾选“允许下载”" />
</el-dialog>
</div>
</template>
<script setup>
import { ref, reactive, onMounted, watch } from 'vue'
import { ElMessage } from 'element-plus'
import { getSites, getOfficialSite, getHomepage, updateHomepage } from '../../api/admin'
import { getSites, getOfficialSite, getHomepage, updateHomepage, getDownloadableAssets } from '../../api/admin'
import { useAuthStore } from '../../stores/auth'
const siteId = ref('')
@@ -98,6 +118,10 @@ const sites = ref([])
const saving = ref(false)
const downloading = ref(false)
const formRef = ref(null)
const filePickerVisible = ref(false)
const fileListLoading = ref(false)
const downloadableFiles = ref([])
const filePickerTarget = ref({ type: 'download' }) // { type: 'download' } | { type: 'platform', index: number }
const defaultForm = () => ({
logo_text: 'YUHENG ONE',
@@ -203,6 +227,45 @@ const handleDownload = async () => {
}
}
function openFilePicker(type, index) {
filePickerTarget.value = type === 'platform' ? { type: 'platform', index } : { type: 'download' }
filePickerVisible.value = true
fetchDownloadableFiles()
}
async function fetchDownloadableFiles() {
if (!siteId.value) return
fileListLoading.value = true
try {
const res = await getDownloadableAssets(siteId.value)
downloadableFiles.value = res.list || []
} catch (e) {
ElMessage.error(e.message)
downloadableFiles.value = []
} finally {
fileListLoading.value = false
}
}
function buildDownloadUrl(asset) {
return `/api/web/sites/${siteId.value}/assets/${asset.id}/download`
}
function confirmSelectFile(asset) {
const url = buildDownloadUrl(asset)
if (filePickerTarget.value.type === 'download') {
form.download_url = url
} else {
form.platforms[filePickerTarget.value.index].url = url
}
filePickerVisible.value = false
ElMessage.success('已选择:' + asset.name)
}
function onSelectFile(row) {
if (row) confirmSelectFile(row)
}
onMounted(() => {
fetchSites().then(() => fetchData())
})