nex_animation/frontend/src/components/VersionPanel.vue

149 lines
8.3 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<script setup lang="ts">
/**
* 版本管理抽屉(挂在预览器右侧)。
*
* 之前「设为默认 / 删除某一版」只能先在预览器顶部下拉里逐版切换再点按钮,
* 入口太隐蔽:想删掉中间某一版,得先把它翻出来预览。这里把全部版本摊成一列,
* 每一行自带「设为默认 / 删除」,不用来回切版本。
* 动作复用 preview.ts 里的 setCurrentVersion / deleteVersion —— 平台母版和
* 项目资产走的是两个接口,逻辑只有一份。
*/
import { computed } from 'vue'
import { fmtBytes, fmtTime } from '../format'
import { thumbUrl } from '../media'
import { chooseVersion, current, deleteVersion, setCurrentVersion, versionBusy, versionChoice, viewedVersion } from '../preview'
const emit = defineEmits<{ (e: 'close'): void }>()
const item = current
const kind = computed(() => item.value?.kind || 'none')
/** 新版本在上,和下拉里的顺序一致 */
const rows = computed(() => [...(item.value?.versions || [])].sort((a, b) => b.version_no - a.version_no))
const currentNo = computed(() => item.value?.version || 1)
const chosen = computed(() => (item.value ? versionChoice.value[item.value.key] || currentNo.value : 0))
const previewing = computed(() => viewedVersion(item.value)?.version_no || 0)
const onlyOne = computed(() => rows.value.length < 2)
function coverOf(url: string) {
return kind.value === 'image' || kind.value === 'video' ? thumbUrl(url, 128) : ''
}
function infoOf(row: any) {
const bits: string[] = []
if (row.width && row.height) bits.push(`${row.width}×${row.height}`)
if (row.size_bytes) bits.push(fmtBytes(row.size_bytes))
if (row.duration_ms) bits.push(`${Math.round(row.duration_ms / 100) / 10}s`)
return bits.join(' · ') || '—'
}
function preview(row: any) {
chooseVersion(row.version_no)
}
function makeCurrent(row: any) {
if (row.exists === false || row.current) return
void setCurrentVersion(row.version_no)
}
function remove(row: any) {
if (!item.value || onlyOne.value) return
const fileNote = row.exists === false ? '该版本的文件已经不在磁盘上,这次只清理记录。' : '该版本的记录与文件会一并删除,不可恢复。'
const tail = row.current || row.version_no === currentNo.value ? '它正是当前默认版本,删除后自动回落到剩余最新版本。' : ''
const ask = `确认删除「${item.value.title}」的 v${row.version_no}?${fileNote}${tail}`
if (window.confirm(ask)) void deleteVersion(row.version_no)
}
</script>
<template>
<aside v-if="item" class="vp" role="complementary" :aria-label="'版本管理:' + item.title">
<header class="vp-head">
<div class="grow">
<p class="eyebrow">VERSIONS · 版本管理</p>
<h4>{{ item.title }}</h4>
<p class="cnt">共 {{ rows.length }} 版 · 当前默认 <b class="mono">v{{ currentNo }}</b></p>
</div>
<button class="ghost tiny" title="关闭版本管理" @click="emit('close')">✕</button>
</header>
<p class="vp-note">
<b>设为默认</b>:平台母版与之后引入项目的素材都取这一版;项目里已锁定的快照不会自动改版。<br />
<b>删除</b>:连同文件一起清理;若仍被生成记录引用,只删记录并保留文件。
</p>
<div class="vp-list">
<div v-for="row in rows" :key="row.version_no" class="vp-row"
:class="{ on: row.version_no === previewing, def: row.version_no === currentNo, gone: row.exists === false }">
<button class="vp-thumb" :title="'预览 v' + row.version_no" @click="preview(row)">
<img v-if="coverOf(row.url)" :src="coverOf(row.url)" :alt="'v' + row.version_no" loading="lazy" decoding="async" />
<b v-else>{{ kind === 'audio' ? '♫' : kind === 'video' ? '▶' : '▤' }}</b>
</button>
<div class="vp-main">
<div class="vp-line">
<b class="mono vp-no">v{{ row.version_no }}</b>
<span v-if="row.version_no === currentNo" class="tag ok">当前默认</span>
<span v-if="row.version_no === previewing" class="tag">预览中</span>
<span v-if="row.exists === false" class="tag bad">文件已丢失</span>
</div>
<p class="vp-meta mono">{{ fmtTime(row.created_at) }} · {{ infoOf(row) }}</p>
<p v-if="row.note" class="vp-note-line">{{ row.note }}</p>
</div>
<div class="vp-acts">
<button class="ghost tiny" :disabled="row.version_no === previewing || versionBusy"
:title="row.version_no === previewing ? '已经在预览这一版' : '切到这一版看看'"
@click="preview(row)">预览</button>
<button class="ghost tiny star" :disabled="row.version_no === currentNo || row.exists === false || versionBusy"
:title="row.version_no === currentNo ? '这一版已经是当前默认'
: (row.exists === false ? '文件已丢失,无法设为默认,可以先删掉它' : '把这一版设为当前默认版本')"
@click="makeCurrent(row)">{{ versionBusy ? '处理中…' : '★ 设为默认' }}</button>
<button class="btn-del" :disabled="onlyOne || versionBusy"
:title="onlyOne ? '只剩一个版本,如需清理请直接删除该素材' : '删除这一版(含文件),不可恢复'"
@click="remove(row)">删除</button>
</div>
</div>
</div>
</aside>
</template>
<style scoped>
/* 抽屉贴在预览舞台右侧:不遮挡顶部的版本下拉,也不改弹窗整体尺寸 */
.vp {
position: absolute; z-index: 3; top: 0; right: 0; bottom: 0; width: min(400px, 74%);
display: flex; flex-direction: column; min-height: 0; gap: 8px; padding: 11px 12px;
border-left: 1px solid var(--c-line-strong); background: var(--c-bg-panel);
box-shadow: -14px 0 30px var(--c-shade-2);
}
.vp-head { display: flex; gap: 8px; align-items: flex-start; flex: 0 0 auto }
.vp-head p { margin: 0 }
.vp-head h4 { margin: 2px 0 0; font-size: 13px; line-height: 1.3; word-break: break-all }
.grow { flex: 1 1 auto; min-width: 0 }
.cnt { margin: 4px 0 0; font-size: 10px; color: var(--c-text-3) }
.cnt b { color: var(--c-accent-bright) }
.vp-note { margin: 0; flex: 0 0 auto; padding: 7px 8px; border: 1px solid var(--c-line); border-radius: 8px;
background: var(--c-bg-sunken); font-size: 10px; line-height: 1.55; color: var(--c-text-3) }
.vp-note b { color: var(--c-text-2) }
.vp-list { flex: 1 1 auto; min-height: 0; overflow: auto; display: flex; flex-direction: column; gap: 6px;
margin: 0 -4px; padding: 0 4px }
.vp-row { display: flex; gap: 8px; align-items: flex-start; padding: 7px; border: 1px solid var(--c-line);
border-radius: 9px; background: var(--c-bg-card) }
.vp-row.on { border-color: var(--c-accent-line); background: var(--c-accent-tint) }
.vp-row.def { border-left: 2px solid var(--c-accent-line) }
.vp-row.gone { opacity: .72 }
.vp-thumb { flex: 0 0 auto; width: 52px; height: 40px; padding: 0; overflow: hidden; border: 1px solid var(--c-line);
border-radius: 7px; background: var(--c-bg-sunken); color: var(--c-text-muted); font-size: 15px;
display: grid; place-items: center; cursor: zoom-in }
.vp-thumb img { width: 100%; height: 100%; object-fit: cover; display: block }
.vp-main { flex: 1 1 auto; min-width: 0 }
.vp-line { display: flex; align-items: center; gap: 5px; flex-wrap: wrap }
.vp-no { font-size: 11.5px; font-weight: 700; color: var(--c-text) }
.vp-meta { margin: 3px 0 0; font-size: 10px; color: var(--c-text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap }
.vp-note-line { margin: 3px 0 0; font-size: 10px; color: var(--c-text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap }
.vp-acts { display: flex; flex-direction: column; gap: 4px; flex: 0 0 auto; align-items: stretch }
.vp-acts .ghost, .vp-acts .btn-del { justify-content: center; width: 84px }
.tag { font-size: 10px; padding: 1px 5px; border-radius: 5px; border: 1px solid var(--c-line-strong);
color: var(--c-text-3); background: var(--c-bg-sunken) }
.tag.ok { color: var(--c-accent-bright); border-color: var(--c-accent-line); background: var(--c-accent-tint) }
.tag.bad { color: var(--c-danger-bright); border-color: var(--c-danger-line) }
.muted { color: var(--c-text-faint) }
</style>