fix: 修复后台文件上传无反馈
This commit is contained in:
@@ -107,6 +107,7 @@
|
|||||||
- 艺术品新建页子资源提示(2026-07-04):艺术品档案新建时仍先保存基础信息以获得 `artworkId`,溯源时间轴与认证文件是挂在作品下的子资源,必须在作品存在后维护。后台 `ArtworkEdit.vue` 新建态不再隐藏这两个区块,而是显示锁定空状态,提示保存基础信息后可维护;保存后自动跳转详情页并启用原有节点/认证文件管理。
|
- 艺术品新建页子资源提示(2026-07-04):艺术品档案新建时仍先保存基础信息以获得 `artworkId`,溯源时间轴与认证文件是挂在作品下的子资源,必须在作品存在后维护。后台 `ArtworkEdit.vue` 新建态不再隐藏这两个区块,而是显示锁定空状态,提示保存基础信息后可维护;保存后自动跳转详情页并启用原有节点/认证文件管理。
|
||||||
- 艺术品档案删除约束(2026-07-04):艺术品档案删除仅用于误建/草稿类数据,后端 `ArtworkService.remove` 仍为软删除但会先检查该档案是否已有追溯码或查询日志;一旦存在业务痕迹则返回 `ARTWORK_IN_USE`,提示改为停用或归档。后台艺术品档案列表新增删除图标,仅 `codeCount=0` 时可点,已有追溯码的档案删除按钮置灰。
|
- 艺术品档案删除约束(2026-07-04):艺术品档案删除仅用于误建/草稿类数据,后端 `ArtworkService.remove` 仍为软删除但会先检查该档案是否已有追溯码或查询日志;一旦存在业务痕迹则返回 `ARTWORK_IN_USE`,提示改为停用或归档。后台艺术品档案列表新增删除图标,仅 `codeCount=0` 时可点,已有追溯码的档案删除按钮置灰。
|
||||||
- 追溯码列表表头筛选(2026-07-04):`TraceCodePanel` 工具栏保留短码/追溯码/档案号等输入查询,批次、出库状态、分组、追溯码状态改为表头下拉筛选,支持多条件叠加;追溯码列表新增创建时间列。后端 `QueryTraceCodeDto` / `ExportTraceCodeDto` 新增 `outboundStatus=OUTBOUND|NOT_OUTBOUND`,`TraceCodeService` 用 `AND` 合并出库状态和关键词等 OR 条件,避免筛选互相覆盖;导出当前筛选会带上出库状态。
|
- 追溯码列表表头筛选(2026-07-04):`TraceCodePanel` 工具栏保留短码/追溯码/档案号等输入查询,批次、出库状态、分组、追溯码状态改为表头下拉筛选,支持多条件叠加;追溯码列表新增创建时间列。后端 `QueryTraceCodeDto` / `ExportTraceCodeDto` 新增 `outboundStatus=OUTBOUND|NOT_OUTBOUND`,`TraceCodeService` 用 `AND` 合并出库状态和关键词等 OR 条件,避免筛选互相覆盖;导出当前筛选会带上出库状态。
|
||||||
|
- 后台上传组件修复(2026-07-04):`MediaUpload.vue` 不再使用 Naive UI `n-upload` 的受控 `file-list + custom-request` 组合,改为原生文件 input + 自管上传状态。选择文件后立即显示上传占位,成功后回写 `{ key,url,name,type }`,失败时明确提示;该组件覆盖出库实况图、认证文件、动态字段图片/文件等入口。`MediaSorter.vue` 仍用于作品/节点多媒体排序上传。
|
||||||
|
|
||||||
## 当前代码基准与注意事项
|
## 当前代码基准与注意事项
|
||||||
|
|
||||||
@@ -116,6 +117,7 @@
|
|||||||
- 出库导入:以短码定位具体一套码,导入列不再包含 SKU 或手填档案编号;档案编号由作品自动生成并在日志/导出/C 端展示。
|
- 出库导入:以短码定位具体一套码,导入列不再包含 SKU 或手填档案编号;档案编号由作品自动生成并在日志/导出/C 端展示。
|
||||||
- 后台列表约定:新列表页优先复用 `apps/admin/src/composables/useTablePage.ts`,页面根容器使用 `class="page table-page"`,`n-data-table` 使用 `class="table-fill" flex-height` 且关闭内置分页,底部统一外置 `n-pagination`;后端列表查询如继承 `PaginationDto`,需遵守 `pageSize=0` 不分页语义。
|
- 后台列表约定:新列表页优先复用 `apps/admin/src/composables/useTablePage.ts`,页面根容器使用 `class="page table-page"`,`n-data-table` 使用 `class="table-fill" flex-height` 且关闭内置分页,底部统一外置 `n-pagination`;后端列表查询如继承 `PaginationDto`,需遵守 `pageSize=0` 不分页语义。
|
||||||
- 后台筛选约定:列表中输入型检索保留在工具栏;枚举/下拉型筛选优先放到对应表头下拉中,并把所有筛选条件集中到同一个 query 对象后叠加请求。
|
- 后台筛选约定:列表中输入型检索保留在工具栏;枚举/下拉型筛选优先放到对应表头下拉中,并把所有筛选条件集中到同一个 query 对象后叠加请求。
|
||||||
|
- 后台上传约定:单文件或少量附件优先复用 `MediaUpload.vue`,多图/视频排序场景使用 `MediaSorter.vue`;上传组件必须在选择文件后立即显示可见反馈,不能只依赖第三方 Upload 内部列表状态。
|
||||||
- 开发脚本约定:`python scripts/dev.py` 会启动 `nest start --watch`,API 运行时不要手动或脚本化删除 `apps/api/dist`;如遇缺模块或半残 `dist`,停止当前 dev 进程后重新运行 `python scripts/dev.py`。
|
- 开发脚本约定:`python scripts/dev.py` 会启动 `nest start --watch`,API 运行时不要手动或脚本化删除 `apps/api/dist`;如遇缺模块或半残 `dist`,停止当前 dev 进程后重新运行 `python scripts/dev.py`。
|
||||||
- 客户端:当前 `Trace.vue` 依赖 `openMediaViewer.ts` + PhotoSwipe,不再使用旧 `MediaViewer.vue`;顶部语言菜单和追溯码复制是用户当前未提交改动的一部分,后续若继续修改客户端,需保护这些改动。
|
- 客户端:当前 `Trace.vue` 依赖 `openMediaViewer.ts` + PhotoSwipe,不再使用旧 `MediaViewer.vue`;顶部语言菜单和追溯码复制是用户当前未提交改动的一部分,后续若继续修改客户端,需保护这些改动。
|
||||||
- 文案残留:`apps/client/src/locales/*` 仍保留 `privacy.note`,但当前页面不显示底部隐私说明;若按合规要求恢复,需要在 `Trace.vue` 重新渲染对应文案。
|
- 文案残留:`apps/client/src/locales/*` 仍保留 `privacy.note`,但当前页面不显示底部隐私说明;若按合规要求恢复,需要在 `Trace.vue` 重新渲染对应文案。
|
||||||
|
|||||||
@@ -1,29 +1,47 @@
|
|||||||
<template>
|
<template>
|
||||||
<n-upload
|
<div class="media-upload" :class="{ text: listType === 'text' }">
|
||||||
:list-type="listType"
|
<div v-if="listType === 'image-card'" class="image-grid">
|
||||||
:file-list="fileList"
|
<div v-for="m in items" :key="m.key" class="image-item">
|
||||||
:max="max"
|
<img v-if="isImage(m)" class="image-thumb" :src="m.url || m.key" :alt="m.name || m.key" />
|
||||||
:accept="accept"
|
<div v-else class="file-thumb">{{ fileExt(m) }}</div>
|
||||||
:custom-request="doUpload"
|
<button class="remove" type="button" :title="t('common.action.delete')" @click="remove(m.key)">×</button>
|
||||||
@remove="onRemove"
|
</div>
|
||||||
>
|
<div v-for="u in uploading" :key="u.id" class="image-item uploading">
|
||||||
<template v-if="listType === 'image-card'">
|
<n-spin size="small" />
|
||||||
<div class="upd-trigger">
|
</div>
|
||||||
|
<label v-if="canUpload" class="image-item add">
|
||||||
|
<input type="file" :accept="accept" :multiple="allowMultiple" hidden @change="onPick" />
|
||||||
<n-icon :component="AddOutline" :size="22" />
|
<n-icon :component="AddOutline" :size="22" />
|
||||||
<span>{{ t('common.action.upload') }}</span>
|
<span>{{ t('common.action.upload') }}</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else class="file-list">
|
||||||
|
<div v-for="m in items" :key="m.key" class="file-row">
|
||||||
|
<span class="file-name" :title="m.name || m.key">{{ m.name || m.key }}</span>
|
||||||
|
<n-button quaternary circle size="tiny" type="error" :title="t('common.action.delete')" @click="remove(m.key)">
|
||||||
|
×
|
||||||
|
</n-button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
<div v-for="u in uploading" :key="u.id" class="file-row uploading-row">
|
||||||
<n-button v-else>
|
<n-spin size="small" />
|
||||||
<template #icon><n-icon :component="CloudUploadOutline" /></template>
|
<span>{{ t('common.action.upload') }}...</span>
|
||||||
{{ t('common.action.upload') }}
|
</div>
|
||||||
</n-button>
|
<label v-if="canUpload" class="file-button">
|
||||||
</n-upload>
|
<input type="file" :accept="accept" :multiple="allowMultiple" hidden @change="onPick" />
|
||||||
|
<n-button tag="span">
|
||||||
|
<template #icon><n-icon :component="CloudUploadOutline" /></template>
|
||||||
|
{{ t('common.action.upload') }}
|
||||||
|
</n-button>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed } from 'vue';
|
import { computed, ref } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import type { UploadCustomRequestOptions, UploadFileInfo } from 'naive-ui';
|
import { NButton, NIcon, NSpin } from 'naive-ui';
|
||||||
import { AddOutline, CloudUploadOutline } from '@vicons/ionicons5';
|
import { AddOutline, CloudUploadOutline } from '@vicons/ionicons5';
|
||||||
import { post } from '@/api/request';
|
import { post } from '@/api/request';
|
||||||
import { message } from '@/utils/feedback';
|
import { message } from '@/utils/feedback';
|
||||||
@@ -42,50 +60,148 @@ const props = withDefaults(
|
|||||||
const emit = defineEmits<{ (e: 'update:modelValue', v: MediaItem[]): void }>();
|
const emit = defineEmits<{ (e: 'update:modelValue', v: MediaItem[]): void }>();
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
|
||||||
|
const uploading = ref<{ id: number }[]>([]);
|
||||||
|
let seq = 0;
|
||||||
|
|
||||||
|
const items = computed(() => props.modelValue || []);
|
||||||
const listType = computed(() => (props.type === 'image' ? 'image-card' : 'text'));
|
const listType = computed(() => (props.type === 'image' ? 'image-card' : 'text'));
|
||||||
const accept = computed(() =>
|
const accept = computed(() =>
|
||||||
props.type === 'image' ? 'image/*' : props.type === 'video' ? 'video/*' : 'application/pdf,image/*',
|
props.type === 'image' ? 'image/*' : props.type === 'video' ? 'video/*' : 'application/pdf,image/*',
|
||||||
);
|
);
|
||||||
|
const allowMultiple = computed(() => props.max > 1);
|
||||||
|
const canUpload = computed(() => items.value.length + uploading.value.length < props.max);
|
||||||
|
|
||||||
const fileList = computed<UploadFileInfo[]>(() =>
|
function isImage(m: MediaItem) {
|
||||||
(props.modelValue || []).map((m) => ({
|
return props.type === 'image' || /^image\//.test(m.type || '') || /\.(png|jpe?g|gif|webp|bmp|svg)$/i.test(m.url || m.key);
|
||||||
id: m.key,
|
}
|
||||||
name: m.name || m.key,
|
|
||||||
status: 'finished',
|
|
||||||
url: m.url,
|
|
||||||
})),
|
|
||||||
);
|
|
||||||
|
|
||||||
async function doUpload({ file, onFinish, onError }: UploadCustomRequestOptions) {
|
function fileExt(m: MediaItem) {
|
||||||
try {
|
const name = m.name || m.key;
|
||||||
const fd = new FormData();
|
const ext = name.split('.').pop();
|
||||||
fd.append('file', file.file as File);
|
return ext && ext.length <= 5 ? ext.toUpperCase() : 'FILE';
|
||||||
const res: any = await post(`/upload?type=${props.type}`, fd);
|
}
|
||||||
emit('update:modelValue', [
|
|
||||||
...(props.modelValue || []),
|
async function onPick(e: Event) {
|
||||||
{ key: res.key, url: res.url, name: res.name, type: props.type },
|
const input = e.target as HTMLInputElement;
|
||||||
]);
|
const files = Array.from(input.files || []);
|
||||||
onFinish();
|
input.value = '';
|
||||||
} catch (e) {
|
for (const file of files) {
|
||||||
message.error((e as Error)?.message || 'upload failed');
|
if (items.value.length + uploading.value.length >= props.max) {
|
||||||
onError();
|
message.warning(t('common.msg.maxReached', { n: props.max }));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
await uploadOne(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onRemove({ file }: { file: UploadFileInfo }) {
|
async function uploadOne(file: File) {
|
||||||
emit('update:modelValue', (props.modelValue || []).filter((m) => m.key !== file.id));
|
const holder = { id: ++seq };
|
||||||
return true;
|
uploading.value.push(holder);
|
||||||
|
try {
|
||||||
|
const fd = new FormData();
|
||||||
|
fd.append('file', file);
|
||||||
|
const res: any = await post(`/upload?type=${props.type}`, fd);
|
||||||
|
emit('update:modelValue', [
|
||||||
|
...items.value,
|
||||||
|
{ key: res.key, url: res.url, name: res.name || file.name, type: props.type },
|
||||||
|
]);
|
||||||
|
} catch (err: any) {
|
||||||
|
message.error(err?.message || 'upload failed');
|
||||||
|
} finally {
|
||||||
|
uploading.value = uploading.value.filter((u) => u.id !== holder.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function remove(key: string) {
|
||||||
|
emit('update:modelValue', items.value.filter((m) => m.key !== key));
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.upd-trigger {
|
.media-upload {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.image-grid {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
.image-item {
|
||||||
|
position: relative;
|
||||||
|
width: 96px;
|
||||||
|
height: 96px;
|
||||||
|
border-radius: 8px;
|
||||||
|
overflow: hidden;
|
||||||
|
border: 1px solid var(--n-border-color, #e0e0e6);
|
||||||
|
background: #f4f7fc;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
gap: 4px;
|
}
|
||||||
|
.image-thumb {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
.file-thumb {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
color: #6b7280;
|
color: #6b7280;
|
||||||
}
|
}
|
||||||
|
.image-item.add,
|
||||||
|
.image-item.uploading {
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 4px;
|
||||||
|
font-size: 12px;
|
||||||
|
color: #6b7280;
|
||||||
|
cursor: pointer;
|
||||||
|
border-style: dashed;
|
||||||
|
background: #fafcff;
|
||||||
|
}
|
||||||
|
.image-item.uploading {
|
||||||
|
cursor: default;
|
||||||
|
}
|
||||||
|
.remove {
|
||||||
|
position: absolute;
|
||||||
|
top: 2px;
|
||||||
|
right: 2px;
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: rgba(0, 0, 0, 0.55);
|
||||||
|
color: #fff;
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 20px;
|
||||||
|
cursor: pointer;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
.remove:hover {
|
||||||
|
background: #d03050;
|
||||||
|
}
|
||||||
|
.file-list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 8px;
|
||||||
|
align-items: flex-start;
|
||||||
|
}
|
||||||
|
.file-row {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
max-width: 100%;
|
||||||
|
min-height: 28px;
|
||||||
|
}
|
||||||
|
.file-name {
|
||||||
|
max-width: 360px;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.uploading-row {
|
||||||
|
color: #6b7280;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
.file-button {
|
||||||
|
display: inline-flex;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user