feat: 节点图片支持逐张标题与默认收缩展开,修复C端放大后无法拖动
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,44 +1,54 @@
|
||||
<template>
|
||||
<div class="media-sorter">
|
||||
<div class="grid">
|
||||
<div
|
||||
v-for="(m, i) in list"
|
||||
:key="m.key"
|
||||
class="cell"
|
||||
:class="{ dragging: dragIndex === i, over: overIndex === i }"
|
||||
draggable="true"
|
||||
@dragstart="onDragStart(i)"
|
||||
@dragover.prevent="onDragOver(i)"
|
||||
@drop="onDrop(i)"
|
||||
@dragend="onDragEnd"
|
||||
>
|
||||
<video v-if="isVideo(m)" class="thumb" :src="m.url" muted preload="metadata" />
|
||||
<img v-else class="thumb" :src="m.url" :alt="m.name" />
|
||||
<div v-if="isVideo(m)" class="play"><n-icon :component="PlayCircleOutline" :size="26" /></div>
|
||||
<div class="order">{{ i + 1 }}</div>
|
||||
<button class="del" type="button" :title="t('common.action.delete')" @click="remove(i)">×</button>
|
||||
<div v-for="(m, i) in list" :key="m.key" class="item">
|
||||
<div
|
||||
class="cell"
|
||||
:class="{ dragging: dragIndex === i, over: overIndex === i }"
|
||||
draggable="true"
|
||||
@dragstart="onDragStart(i)"
|
||||
@dragover.prevent="onDragOver(i)"
|
||||
@drop="onDrop(i)"
|
||||
@dragend="onDragEnd"
|
||||
>
|
||||
<video v-if="isVideo(m)" class="thumb" :src="m.url" muted preload="metadata" />
|
||||
<img v-else class="thumb" :src="m.url" :alt="m.name" />
|
||||
<div v-if="isVideo(m)" class="play"><n-icon :component="PlayCircleOutline" :size="26" /></div>
|
||||
<div class="order">{{ i + 1 }}</div>
|
||||
<button class="del" type="button" :title="t('common.action.delete')" @click="remove(i)">×</button>
|
||||
</div>
|
||||
<n-input
|
||||
v-if="captionable"
|
||||
size="small"
|
||||
:value="m.name"
|
||||
:placeholder="t('pages.artwork.imageCaption')"
|
||||
class="caption-input"
|
||||
@update:value="(v) => updateCaption(i, v)"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 上传中占位 -->
|
||||
<div v-for="u in uploading" :key="u.id" class="cell uploading">
|
||||
<n-spin size="small" />
|
||||
<div v-for="u in uploading" :key="u.id" class="item">
|
||||
<div class="cell uploading"><n-spin size="small" /></div>
|
||||
</div>
|
||||
|
||||
<!-- 上传按钮 -->
|
||||
<label v-if="list.length + uploading.length < max" class="cell add">
|
||||
<input ref="inputRef" type="file" accept="image/*,video/*" multiple hidden @change="onPick" />
|
||||
<n-icon :component="AddOutline" :size="22" />
|
||||
<span>{{ t('common.action.upload') }}</span>
|
||||
<label v-if="list.length + uploading.length < max" class="item">
|
||||
<span class="cell add">
|
||||
<input ref="inputRef" type="file" accept="image/*,video/*" multiple hidden @change="onPick" />
|
||||
<n-icon :component="AddOutline" :size="22" />
|
||||
<span>{{ t('common.action.upload') }}</span>
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="hint">{{ t('pages.artwork.mediaHint') }}</div>
|
||||
<div class="hint">{{ captionable ? t('pages.artwork.mediaHintCaption') : t('pages.artwork.mediaHint') }}</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { NIcon, NSpin } from 'naive-ui';
|
||||
import { NIcon, NSpin, NInput } from 'naive-ui';
|
||||
import { AddOutline, PlayCircleOutline } from '@vicons/ionicons5';
|
||||
import { post } from '@/api/request';
|
||||
import { message } from '@/utils/feedback';
|
||||
@@ -50,10 +60,18 @@ interface MediaItem {
|
||||
type?: string;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<{ modelValue: MediaItem[]; max?: number }>(), { max: 12 });
|
||||
const props = withDefaults(
|
||||
defineProps<{ modelValue: MediaItem[]; max?: number; captionable?: boolean }>(),
|
||||
{ max: 12, captionable: false },
|
||||
);
|
||||
const emit = defineEmits<{ (e: 'update:modelValue', v: MediaItem[]): void }>();
|
||||
const { t } = useI18n();
|
||||
|
||||
function updateCaption(i: number, v: string) {
|
||||
const arr = list.value.map((m, idx) => (idx === i ? { ...m, name: v } : m));
|
||||
emit('update:modelValue', arr);
|
||||
}
|
||||
|
||||
const inputRef = ref<HTMLInputElement | null>(null);
|
||||
const list = computed<MediaItem[]>(() => props.modelValue || []);
|
||||
const uploading = ref<{ id: number }[]>([]);
|
||||
@@ -86,7 +104,7 @@ async function uploadOne(file: File) {
|
||||
const res: any = await post(`/upload?type=${type}`, fd);
|
||||
emit('update:modelValue', [
|
||||
...list.value,
|
||||
{ key: res.key, url: res.url, name: res.name, type },
|
||||
{ key: res.key, url: res.url, name: props.captionable ? '' : res.name, type },
|
||||
]);
|
||||
} catch (err) {
|
||||
message.error((err as Error)?.message || 'upload failed');
|
||||
@@ -129,6 +147,14 @@ function onDragEnd() {
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
}
|
||||
.item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
.caption-input {
|
||||
width: 96px;
|
||||
}
|
||||
.cell {
|
||||
position: relative;
|
||||
width: 96px;
|
||||
|
||||
Reference in New Issue
Block a user