185 lines
8.0 KiB
Vue
185 lines
8.0 KiB
Vue
<template>
|
||
<div class="page">
|
||
<div class="page-head cp-rise">
|
||
<div>
|
||
<h3>大文件源 <span class="badge">File Sources</span></h3>
|
||
<p>内网大文件(壳子/Chrome 等)直链登记。中心机只存链接,文件本身走内网文件服务器</p>
|
||
</div>
|
||
<div class="head-actions">
|
||
<el-select v-model="filter" placeholder="按分类过滤" style="width: 150px" clearable @change="onFilterChange">
|
||
<el-option v-for="c in categories" :key="c" :label="c" :value="c" />
|
||
</el-select>
|
||
<el-button :loading="busy" :icon="Refresh" @click="refresh">刷新</el-button>
|
||
<el-button type="primary" :icon="Plus" @click="openCreate">登记链接</el-button>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="cp-card panel cp-rise">
|
||
<el-table :data="rows" v-loading="busy" size="default" style="width: 100%">
|
||
<el-table-column prop="category" label="分类" width="110">
|
||
<template #default="{ row }">
|
||
<el-tag :type="catType(row.category)" size="small" effect="light">{{ row.category }}</el-tag>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column prop="version" label="版本" width="90">
|
||
<template #default="{ row }"><span class="mono">{{ row.version }}</span></template>
|
||
</el-table-column>
|
||
<el-table-column prop="filename" label="文件" min-width="150" show-overflow-tooltip />
|
||
<el-table-column label="内网直链" min-width="260" show-overflow-tooltip>
|
||
<template #default="{ row }">
|
||
<span class="mono dim url">{{ row.url }}</span>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="SHA256" width="120">
|
||
<template #default="{ row }">
|
||
<el-button v-if="row.sha256" link type="primary" @click="copy(row.sha256, 'SHA256')">
|
||
{{ row.sha256.slice(0, 8) }}…
|
||
</el-button>
|
||
<span v-else class="dim">—</span>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="说明" min-width="140" show-overflow-tooltip>
|
||
<template #default="{ row }">{{ row.notes || '—' }}</template>
|
||
</el-table-column>
|
||
<el-table-column prop="updated_at" label="更新时间" width="160" />
|
||
<el-table-column label="启用" width="70" align="center">
|
||
<template #default="{ row }">
|
||
<el-switch :model-value="!!row.enabled" :loading="row._tog" @change="(v) => toggle(row, v)" />
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="操作" width="130" fixed="right">
|
||
<template #default="{ row }">
|
||
<el-button link type="primary" @click="copy(row.url, '链接')">复制</el-button>
|
||
<el-button link type="danger" :icon="Delete" @click="remove(row)">删除</el-button>
|
||
</template>
|
||
</el-table-column>
|
||
<template #empty>
|
||
<el-empty description="暂无登记的大文件源" :image-size="80" />
|
||
</template>
|
||
</el-table>
|
||
<PagerBar :total="total" :page="page" :page-size="pageSize" @change="onPageChange" />
|
||
</div>
|
||
|
||
<el-dialog v-model="dlg" title="登记内网直链" width="560px">
|
||
<div class="form">
|
||
<div class="fitem">
|
||
<label>分类 <span class="dim">(shell / chrome / …)</span></label>
|
||
<el-input v-model="form.category" placeholder="如 chrome" />
|
||
</div>
|
||
<div class="fitem">
|
||
<label>版本</label>
|
||
<el-input v-model="form.version" placeholder="如 1.0.0" />
|
||
</div>
|
||
<div class="fitem">
|
||
<label>文件名</label>
|
||
<el-input v-model="form.filename" placeholder="如 ChromeStandaloneSetup64.exe" />
|
||
</div>
|
||
<div class="fitem">
|
||
<label>内网直链 url</label>
|
||
<el-input v-model="form.url" placeholder="http://内网IP:8802/files/..." />
|
||
</div>
|
||
<div class="fitem">
|
||
<label>SHA256 <span class="dim">(可选)</span></label>
|
||
<el-input v-model="form.sha256" placeholder="文件校验值,客户端下载后校验" />
|
||
</div>
|
||
<div class="fitem">
|
||
<label>说明 <span class="dim">(可选)</span></label>
|
||
<el-input v-model="form.notes" type="textarea" :rows="2" placeholder="备注" />
|
||
</div>
|
||
<p class="tip">同一 分类+版本 会覆盖旧记录;删除仅移除中心机登记,不影响内网文件服务器上的文件。</p>
|
||
</div>
|
||
<template #footer>
|
||
<el-button @click="dlg = false">取消</el-button>
|
||
<el-button type="primary" :loading="saving" @click="save">保存</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup>
|
||
import { onMounted, ref, watch } from 'vue'
|
||
import { Refresh, Plus, Delete } from '@element-plus/icons-vue'
|
||
import { ElMessage as message, ElMessageBox } from 'element-plus'
|
||
import { adminFileSources, adminFileSourceCreate, adminFileSourcePatch, adminFileSourceDelete } from '../api'
|
||
import PagerBar from '../components/PagerBar.vue'
|
||
import { usePagedList } from '../composables/usePagedList'
|
||
|
||
const CATS = ['shell', 'chrome-x64', 'chrome-x86']
|
||
const categories = CATS
|
||
const filter = ref('')
|
||
const list = usePagedList((p, s) => adminFileSources(filter.value || '', p, s), { onError: e => message.error('读取失败:' + (e.message || e)) })
|
||
const { items: rows, total, page, size: pageSize, busy, load: refresh, onPageChange, reset } = list
|
||
const dlg = ref(false)
|
||
const saving = ref(false)
|
||
const form = ref({})
|
||
|
||
function onFilterChange() { reset() }
|
||
// 分类下拉:由当前页数据补充实际出现的分类
|
||
watch(rows, () => {
|
||
const seen = new Set(CATS)
|
||
;(rows.value || []).forEach((f) => seen.add(f.category))
|
||
categories.length = 0
|
||
;[...seen].sort().forEach((c) => categories.push(c))
|
||
})
|
||
|
||
function catType(c) {
|
||
return { shell: 'success', 'chrome-x64': 'warning', 'chrome-x86': 'warning', chrome: 'warning' }[c] || 'info'
|
||
}
|
||
|
||
function openCreate() {
|
||
form.value = { category: '', version: '', filename: '', url: '', sha256: '', notes: '', enabled: true }
|
||
dlg.value = true
|
||
}
|
||
|
||
async function save() {
|
||
if (!form.value.category || !form.value.category.trim()) return message.error('分类不能为空')
|
||
if (!form.value.url || !form.value.url.trim()) return message.error('内网直链不能为空')
|
||
saving.value = true
|
||
try {
|
||
const { enabled, ...rest } = form.value
|
||
const body = { ...rest, category: form.value.category.trim(), url: form.value.url.trim(), enabled: true }
|
||
await adminFileSourceCreate(body)
|
||
message.success('已登记')
|
||
dlg.value = false
|
||
await refresh()
|
||
} catch (e) { message.error('保存失败:' + (e.message || e)) }
|
||
finally { saving.value = false }
|
||
}
|
||
|
||
async function toggle(row, v) {
|
||
row._tog = true
|
||
try { await adminFileSourcePatch(row.id, { enabled: v }); row.enabled = v; message.success(v ? '已启用' : '已停用') }
|
||
catch (e) { message.error('操作失败:' + (e.message || e)) }
|
||
finally { row._tog = false }
|
||
}
|
||
|
||
async function remove(row) {
|
||
try {
|
||
await ElMessageBox.confirm(`删除「${row.category} ${row.version}」的登记?此操作仅移除中心机登记,不影响内网文件。`, '确认删除', { type: 'warning' })
|
||
} catch (_) { return }
|
||
try {
|
||
await adminFileSourceDelete(row.id)
|
||
message.success('已删除')
|
||
await refresh()
|
||
} catch (e) { message.error('删除失败:' + (e.message || e)) }
|
||
}
|
||
|
||
async function copy(text, what) {
|
||
try { await navigator.clipboard.writeText(text); message.success(what + '已复制') }
|
||
catch (_) { message.error('复制失败,请手动选择') }
|
||
}
|
||
|
||
onMounted(refresh)
|
||
</script>
|
||
|
||
<style scoped>
|
||
.panel { padding: 22px 24px 26px; }
|
||
.head-actions { display: flex; gap: 10px; align-items: center; }
|
||
.form { display: flex; flex-direction: column; gap: 14px; }
|
||
.fitem { display: flex; flex-direction: column; gap: 6px; }
|
||
.fitem label { font-size: 13px; font-weight: 700; color: var(--cp-ink-1); }
|
||
.fitem .dim { font-weight: 500; font-size: 12px; }
|
||
.dim { color: var(--cp-ink-3); }
|
||
.url { font-size: 12px; }
|
||
.tip { font-size: 12px; color: var(--cp-ink-3); margin: 0; }
|
||
</style> |