feat: 新增客户端作品展示模块
This commit is contained in:
@@ -0,0 +1,357 @@
|
||||
<template>
|
||||
<div class="showcase-editor">
|
||||
<div class="showcase-list">
|
||||
<div
|
||||
v-for="(item, index) in list"
|
||||
:key="item.key"
|
||||
class="showcase-row"
|
||||
:class="{ over: overIndex === index, readonly: disabled }"
|
||||
@dragover.prevent="overIndex = index"
|
||||
@drop="onDrop(index)"
|
||||
>
|
||||
<button type="button" class="showcase-preview" @click="preview(index)">
|
||||
<img :src="mediaSrc(item)" :alt="item.name || t('pages.artwork.showcase')" loading="lazy" />
|
||||
<span class="showcase-order">{{ index + 1 }}</span>
|
||||
</button>
|
||||
|
||||
<div class="showcase-fields">
|
||||
<n-input
|
||||
size="small"
|
||||
:value="item.name"
|
||||
:maxlength="120"
|
||||
:disabled="disabled"
|
||||
:placeholder="t('pages.artwork.showcaseImageTitle')"
|
||||
@update:value="(value) => updateItem(index, 'name', value)"
|
||||
/>
|
||||
<n-input
|
||||
size="small"
|
||||
type="textarea"
|
||||
:value="item.description"
|
||||
:maxlength="1000"
|
||||
:disabled="disabled"
|
||||
:autosize="{ minRows: 2, maxRows: 5 }"
|
||||
:placeholder="t('pages.artwork.showcaseImageDescription')"
|
||||
@update:value="(value) => updateItem(index, 'description', value)"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div v-if="!disabled" class="showcase-actions">
|
||||
<n-tooltip>
|
||||
<template #trigger>
|
||||
<n-button
|
||||
quaternary
|
||||
circle
|
||||
size="small"
|
||||
:disabled="index === 0"
|
||||
:aria-label="t('common.action.moveUp')"
|
||||
@click="move(index, -1)"
|
||||
>
|
||||
<template #icon><n-icon :component="ArrowUpOutline" /></template>
|
||||
</n-button>
|
||||
</template>
|
||||
{{ t('common.action.moveUp') }}
|
||||
</n-tooltip>
|
||||
<n-tooltip>
|
||||
<template #trigger>
|
||||
<n-button
|
||||
quaternary
|
||||
circle
|
||||
size="small"
|
||||
:disabled="index === list.length - 1"
|
||||
:aria-label="t('common.action.moveDown')"
|
||||
@click="move(index, 1)"
|
||||
>
|
||||
<template #icon><n-icon :component="ArrowDownOutline" /></template>
|
||||
</n-button>
|
||||
</template>
|
||||
{{ t('common.action.moveDown') }}
|
||||
</n-tooltip>
|
||||
<n-tooltip>
|
||||
<template #trigger>
|
||||
<n-button
|
||||
quaternary
|
||||
circle
|
||||
size="small"
|
||||
type="error"
|
||||
:aria-label="t('common.action.delete')"
|
||||
@click="remove(index)"
|
||||
>
|
||||
<template #icon><n-icon :component="TrashOutline" /></template>
|
||||
</n-button>
|
||||
</template>
|
||||
{{ t('common.action.delete') }}
|
||||
</n-tooltip>
|
||||
<button
|
||||
type="button"
|
||||
class="drag-handle"
|
||||
draggable="true"
|
||||
:title="t('pages.artwork.showcaseDrag')"
|
||||
:aria-label="t('pages.artwork.showcaseDrag')"
|
||||
@dragstart="dragIndex = index"
|
||||
@dragend="onDragEnd"
|
||||
>
|
||||
⋮⋮
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-for="holder in uploading" :key="holder.id" class="showcase-row showcase-uploading">
|
||||
<div class="showcase-loading"><n-spin size="small" /></div>
|
||||
<span>{{ t('common.action.upload') }}...</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<label v-if="!disabled && list.length + uploading.length < max" class="showcase-add">
|
||||
<input type="file" accept="image/jpeg,image/png,image/webp,image/gif" multiple hidden @change="onPick" />
|
||||
<n-icon :component="AddOutline" :size="24" />
|
||||
<span>{{ t('pages.artwork.addShowcaseImages') }}</span>
|
||||
</label>
|
||||
<div class="showcase-hint">{{ t('pages.artwork.showcaseHint', { n: max }) }}</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { NButton, NIcon, NInput, NSpin, NTooltip } from 'naive-ui';
|
||||
import { AddOutline, ArrowDownOutline, ArrowUpOutline, TrashOutline } from '@vicons/ionicons5';
|
||||
import { post } from '@/api/request';
|
||||
import { openMediaViewer } from '@/composables/openMediaViewer';
|
||||
import { message } from '@/utils/feedback';
|
||||
import { resolveMediaUrl } from '@/utils/mediaUrl';
|
||||
|
||||
interface ShowcaseImage {
|
||||
key: string;
|
||||
url?: string;
|
||||
name?: string;
|
||||
type?: string;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{ modelValue: ShowcaseImage[]; max?: number; disabled?: boolean }>(),
|
||||
{ max: 30, disabled: false },
|
||||
);
|
||||
const emit = defineEmits<{ (event: 'update:modelValue', value: ShowcaseImage[]): void }>();
|
||||
const { t } = useI18n();
|
||||
|
||||
const list = computed(() => props.modelValue || []);
|
||||
const uploading = ref<Array<{ id: number }>>([]);
|
||||
const dragIndex = ref<number | null>(null);
|
||||
const overIndex = ref<number | null>(null);
|
||||
let uploadSequence = 0;
|
||||
|
||||
function mediaSrc(item: ShowcaseImage) {
|
||||
return resolveMediaUrl(item.url || item.key);
|
||||
}
|
||||
|
||||
function updateItem(index: number, field: 'name' | 'description', value: string) {
|
||||
emit(
|
||||
'update:modelValue',
|
||||
list.value.map((item, itemIndex) => (itemIndex === index ? { ...item, [field]: value } : item)),
|
||||
);
|
||||
}
|
||||
|
||||
function move(index: number, offset: number) {
|
||||
const target = index + offset;
|
||||
if (target < 0 || target >= list.value.length) return;
|
||||
const next = [...list.value];
|
||||
const [item] = next.splice(index, 1);
|
||||
next.splice(target, 0, item);
|
||||
emit('update:modelValue', next);
|
||||
}
|
||||
|
||||
function remove(index: number) {
|
||||
emit('update:modelValue', list.value.filter((_, itemIndex) => itemIndex !== index));
|
||||
}
|
||||
|
||||
function preview(index: number) {
|
||||
void openMediaViewer(
|
||||
list.value.map((item) => ({ url: mediaSrc(item), name: item.name || item.key, type: 'image' })),
|
||||
index,
|
||||
);
|
||||
}
|
||||
|
||||
function onDrop(target: number) {
|
||||
const source = dragIndex.value;
|
||||
if (source === null || source === target) return onDragEnd();
|
||||
const next = [...list.value];
|
||||
const [item] = next.splice(source, 1);
|
||||
next.splice(target, 0, item);
|
||||
emit('update:modelValue', next);
|
||||
onDragEnd();
|
||||
}
|
||||
|
||||
function onDragEnd() {
|
||||
dragIndex.value = null;
|
||||
overIndex.value = null;
|
||||
}
|
||||
|
||||
async function onPick(event: Event) {
|
||||
const input = event.target as HTMLInputElement;
|
||||
const files = Array.from(input.files || []);
|
||||
input.value = '';
|
||||
for (const file of files) {
|
||||
if (list.value.length + uploading.value.length >= props.max) {
|
||||
message.warning(t('common.msg.maxReached', { n: props.max }));
|
||||
break;
|
||||
}
|
||||
await uploadOne(file);
|
||||
}
|
||||
}
|
||||
|
||||
async function uploadOne(file: File) {
|
||||
const holder = { id: ++uploadSequence };
|
||||
uploading.value.push(holder);
|
||||
try {
|
||||
const body = new FormData();
|
||||
body.append('file', file);
|
||||
const result: any = await post('/upload?type=image', body);
|
||||
emit('update:modelValue', [
|
||||
...list.value,
|
||||
{
|
||||
key: result.key,
|
||||
url: resolveMediaUrl(result.url),
|
||||
name: '',
|
||||
description: '',
|
||||
type: 'image',
|
||||
},
|
||||
]);
|
||||
} catch {
|
||||
message.error(t('common.msg.uploadFailed'));
|
||||
} finally {
|
||||
uploading.value = uploading.value.filter((item) => item.id !== holder.id);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.showcase-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
.showcase-row {
|
||||
display: grid;
|
||||
grid-template-columns: 132px minmax(0, 1fr) auto;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
padding: 10px;
|
||||
border: 1px solid var(--n-border-color, #e0e0e6);
|
||||
border-radius: 8px;
|
||||
background: var(--n-color, #fff);
|
||||
transition: border-color 0.15s ease;
|
||||
}
|
||||
.showcase-row.over {
|
||||
border-color: var(--brand, #138a72);
|
||||
}
|
||||
.showcase-row.readonly {
|
||||
grid-template-columns: 132px minmax(0, 1fr);
|
||||
}
|
||||
.showcase-preview {
|
||||
position: relative;
|
||||
width: 132px;
|
||||
height: 104px;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
border-radius: 6px;
|
||||
overflow: hidden;
|
||||
background: #eef2f6;
|
||||
cursor: zoom-in;
|
||||
}
|
||||
.showcase-preview img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: block;
|
||||
object-fit: contain;
|
||||
}
|
||||
.showcase-order {
|
||||
position: absolute;
|
||||
left: 6px;
|
||||
bottom: 6px;
|
||||
min-width: 22px;
|
||||
height: 22px;
|
||||
padding: 0 6px;
|
||||
border-radius: 4px;
|
||||
background: rgba(0, 0, 0, 0.62);
|
||||
color: #fff;
|
||||
font-size: 12px;
|
||||
line-height: 22px;
|
||||
}
|
||||
.showcase-fields {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
min-width: 0;
|
||||
}
|
||||
.showcase-actions {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, 32px);
|
||||
gap: 2px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.drag-handle {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
border-radius: 6px;
|
||||
background: transparent;
|
||||
color: #8b95a5;
|
||||
font-size: 18px;
|
||||
cursor: grab;
|
||||
}
|
||||
.drag-handle:hover {
|
||||
background: rgba(19, 138, 114, 0.08);
|
||||
}
|
||||
.showcase-add {
|
||||
min-height: 88px;
|
||||
margin-top: 10px;
|
||||
border: 1px dashed var(--n-border-color, #d8dce5);
|
||||
border-radius: 8px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
color: #667085;
|
||||
cursor: pointer;
|
||||
background: #fafcff;
|
||||
}
|
||||
.showcase-add:hover {
|
||||
color: var(--brand, #138a72);
|
||||
border-color: currentColor;
|
||||
}
|
||||
.showcase-uploading {
|
||||
grid-template-columns: 40px minmax(0, 1fr);
|
||||
min-height: 64px;
|
||||
color: #8b95a5;
|
||||
}
|
||||
.showcase-loading {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
.showcase-hint {
|
||||
margin-top: 8px;
|
||||
color: #98a2b3;
|
||||
font-size: 12px;
|
||||
}
|
||||
@media (max-width: 640px) {
|
||||
.showcase-row {
|
||||
grid-template-columns: 104px minmax(0, 1fr);
|
||||
align-items: start;
|
||||
}
|
||||
.showcase-preview {
|
||||
width: 104px;
|
||||
height: 104px;
|
||||
}
|
||||
.showcase-actions {
|
||||
grid-column: 1 / -1;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
.showcase-row.readonly {
|
||||
grid-template-columns: 104px minmax(0, 1fr);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -31,7 +31,9 @@
|
||||
"open": "Open",
|
||||
"changePassword": "Change Password",
|
||||
"logout": "Logout",
|
||||
"filter": "Filter"
|
||||
"filter": "Filter",
|
||||
"moveUp": "Move up",
|
||||
"moveDown": "Move down"
|
||||
},
|
||||
"label": {
|
||||
"keyword": "Keyword",
|
||||
@@ -320,9 +322,16 @@
|
||||
"selectArtwork": "Select Artwork",
|
||||
"selectArtworkTip": "Search by archive no. / title to pick an artwork",
|
||||
"images": "Artwork",
|
||||
"coverMedia": "Hero Artwork Media",
|
||||
"mediaHint": "Images and videos supported. Drag to reorder (order = display order on the consumer page).",
|
||||
"mediaHintCaption": "Images and videos supported. Add a caption per item (e.g. Sketch, Blank selection). Drag to reorder (= display order on the consumer page).",
|
||||
"imageCaption": "Caption",
|
||||
"showcase": "Artwork Showcase",
|
||||
"addShowcaseImages": "Upload Showcase Images",
|
||||
"showcaseImageTitle": "Image title (optional)",
|
||||
"showcaseImageDescription": "Image description (optional)",
|
||||
"showcaseDrag": "Drag to reorder",
|
||||
"showcaseHint": "Images only, up to {n}. Drag or use the arrow buttons to set the order shown on the consumer page.",
|
||||
"nodeMedia": "Node Images / Videos",
|
||||
"basicInfo": "Basic Info",
|
||||
"dynamicFields": "Fields",
|
||||
|
||||
@@ -31,7 +31,9 @@
|
||||
"open": "打开",
|
||||
"changePassword": "修改密码",
|
||||
"logout": "退出登录",
|
||||
"filter": "筛选"
|
||||
"filter": "筛选",
|
||||
"moveUp": "上移",
|
||||
"moveDown": "下移"
|
||||
},
|
||||
"label": {
|
||||
"keyword": "关键词",
|
||||
@@ -320,9 +322,16 @@
|
||||
"selectArtwork": "选择作品",
|
||||
"selectArtworkTip": "搜索档案号 / 作品名选择作品(款)",
|
||||
"images": "作品",
|
||||
"coverMedia": "首屏作品图",
|
||||
"mediaHint": "支持图片与视频,拖拽可调整顺序(顺序即客户端展示顺序)",
|
||||
"mediaHintCaption": "支持图片与视频,可为每张填写标题(如设计稿、选胚图),拖拽调整顺序(即客户端展示顺序)",
|
||||
"imageCaption": "图片标题",
|
||||
"showcase": "作品展示",
|
||||
"addShowcaseImages": "上传作品展示图",
|
||||
"showcaseImageTitle": "图片标题(选填)",
|
||||
"showcaseImageDescription": "图片说明(选填)",
|
||||
"showcaseDrag": "拖拽调整顺序",
|
||||
"showcaseHint": "仅支持图片,最多 {n} 张;可拖拽或使用上下按钮排序,客户端将按此顺序纵向展示。",
|
||||
"nodeMedia": "节点图片 / 视频",
|
||||
"basicInfo": "基础信息",
|
||||
"dynamicFields": "动态字段",
|
||||
|
||||
@@ -143,12 +143,23 @@
|
||||
</n-form-item-gi>
|
||||
</n-grid>
|
||||
|
||||
<n-divider style="margin: 4px 0 16px">{{ t('pages.artwork.images') }}</n-divider>
|
||||
<n-divider style="margin: 4px 0 16px">{{ t('pages.artwork.coverMedia') }}</n-divider>
|
||||
<media-sorter v-model="form.images" :max="12" />
|
||||
</n-form>
|
||||
</n-card>
|
||||
</n-grid-item>
|
||||
|
||||
<!-- 作品展示 -->
|
||||
<n-grid-item>
|
||||
<n-card :title="t('pages.artwork.showcase')" :bordered="false">
|
||||
<artwork-showcase-editor
|
||||
v-model="form.showcaseImages"
|
||||
:max="30"
|
||||
:disabled="!auth.canWrite"
|
||||
/>
|
||||
</n-card>
|
||||
</n-grid-item>
|
||||
|
||||
<!-- 溯源时间轴 -->
|
||||
<n-grid-item>
|
||||
<n-card :title="t('pages.artwork.nodes')" :bordered="false">
|
||||
@@ -343,6 +354,7 @@ import { artworkApi, templateApi } from '@/api';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import MediaUpload from '@/components/MediaUpload.vue';
|
||||
import MediaSorter from '@/components/MediaSorter.vue';
|
||||
import ArtworkShowcaseEditor from '@/components/ArtworkShowcaseEditor.vue';
|
||||
import { openMediaViewer } from '@/composables/openMediaViewer';
|
||||
import { message, dialog } from '@/utils/feedback';
|
||||
import { fmtDate, fmtSecond } from '@/utils/format';
|
||||
@@ -364,6 +376,7 @@ const form = reactive<any>({
|
||||
status: ArtworkStatus.DRAFT,
|
||||
dynamicFields: {},
|
||||
images: [],
|
||||
showcaseImages: [],
|
||||
showOutboundTimeline: false,
|
||||
});
|
||||
const submitReviewForm = reactive({ title: '', reason: '' });
|
||||
@@ -497,6 +510,11 @@ function applyArtworkToForm(a: any) {
|
||||
...m,
|
||||
type: m.type || (isVideoMedia(m) ? 'video' : 'image'),
|
||||
}));
|
||||
form.showcaseImages = (a.showcaseImages || []).map((m: any) => ({
|
||||
...m,
|
||||
type: 'image',
|
||||
description: m.description || '',
|
||||
}));
|
||||
}
|
||||
|
||||
function applySnapshotToForm(snapshot: any) {
|
||||
@@ -507,6 +525,7 @@ function applySnapshotToForm(snapshot: any) {
|
||||
artist: snapshot.artwork.artist,
|
||||
status: snapshot.artwork.status,
|
||||
showOutboundTimeline: snapshot.artwork.showOutboundTimeline ?? false,
|
||||
showcaseImages: snapshot.artwork.showcaseImages ?? [],
|
||||
dynamicFields: snapshot.artwork.dynamicFields,
|
||||
images: snapshot.artwork.images,
|
||||
});
|
||||
@@ -600,6 +619,12 @@ async function saveArtwork(asDraft: boolean) {
|
||||
name: m.name,
|
||||
type: m.type || (isVideoMedia(m) ? 'video' : 'image'),
|
||||
})),
|
||||
showcaseImages: form.showcaseImages.map((m: any) => ({
|
||||
key: m.key,
|
||||
name: m.name,
|
||||
description: m.description,
|
||||
type: 'image',
|
||||
})),
|
||||
revisionTitle: submitReviewForm.title || undefined,
|
||||
revisionReason: submitReviewForm.reason || undefined,
|
||||
traceNodes: buildNodePayload(),
|
||||
@@ -633,6 +658,7 @@ function buildComparableSnapshot() {
|
||||
showOutboundTimeline: form.showOutboundTimeline === true,
|
||||
dynamicFields: normalizeJson(form.dynamicFields || {}),
|
||||
images: normalizeMedia(form.images),
|
||||
showcaseImages: normalizeMedia(form.showcaseImages),
|
||||
},
|
||||
traceNodes: nodes.value.map((node, index) => ({
|
||||
nodeType: node.nodeType,
|
||||
@@ -659,6 +685,7 @@ function normalizeMedia(items?: any[]) {
|
||||
key: item.key || item.url || '',
|
||||
name: item.name || '',
|
||||
type: item.type || '',
|
||||
description: item.description || '',
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user