贴片模版组件更新
This commit is contained in:
@@ -20,14 +20,14 @@
|
||||
:accept="'.html,.htm'"
|
||||
:on-change="(file: any) => handleTemplateUpload(index, file)"
|
||||
>
|
||||
<el-button size="small" type="primary" :disabled="!!template.url">
|
||||
<el-icon><Upload /></el-icon> 上传模板
|
||||
<el-button size="small" type="primary" :loading="uploadingIndex === index" :disabled="uploadingIndex !== null">
|
||||
<el-icon><Upload /></el-icon> {{ uploadingIndex === index ? '上传中...' : (template.url ? '替换模板' : '上传模板') }}
|
||||
</el-button>
|
||||
</el-upload>
|
||||
<el-button size="small" @click="handleDownload">
|
||||
<el-icon><Download /></el-icon> 下载参考模板
|
||||
</el-button>
|
||||
<el-tag v-if="template.url" type="success" size="small" class="uploaded-tag">已上传</el-tag>
|
||||
<el-tag v-if="template.url" :type="template.url === DEFAULT_TEMPLATE_URL ? 'info' : 'success'" size="small" class="uploaded-tag">{{ template.url === DEFAULT_TEMPLATE_URL ? '已有默认模板' : '已上传' }}</el-tag>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -166,6 +166,8 @@ function nextImageKey(template: PatchTemplate): string | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
const DEFAULT_TEMPLATE_URL = 'https://cdn.redpowerfuture.com/tenantid-1/template_example1.html';
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue: PatchTemplate[];
|
||||
}>();
|
||||
@@ -177,6 +179,8 @@ const emit = defineEmits<{
|
||||
// 图片预览
|
||||
const previewVisible = ref(false);
|
||||
const previewUrl = ref('');
|
||||
// 模板文件上传状态(记录正在上传的模板索引)
|
||||
const uploadingIndex = ref<number | null>(null);
|
||||
|
||||
const previewImage = (url: string) => {
|
||||
previewUrl.value = url;
|
||||
@@ -189,7 +193,7 @@ const updateTemplates = (newTemplates: PatchTemplate[]) => {
|
||||
|
||||
const addTemplate = () => {
|
||||
const newTemplate: PatchTemplate = {
|
||||
url: '',
|
||||
url: DEFAULT_TEMPLATE_URL,
|
||||
start: 0,
|
||||
end: 0,
|
||||
data: {
|
||||
@@ -244,6 +248,7 @@ const removeProductImage = (template: PatchTemplate, imgIdx: number) => {
|
||||
const handleTemplateUpload = async (index: number, file: any) => {
|
||||
const raw = file.raw;
|
||||
if (!raw) return;
|
||||
uploadingIndex.value = index;
|
||||
|
||||
try {
|
||||
const uploadRes = await uploadFile(raw, { timeout: 0 });
|
||||
@@ -255,9 +260,10 @@ const handleTemplateUpload = async (index: number, file: any) => {
|
||||
newList[index].url = fileUrl;
|
||||
updateTemplates(newList);
|
||||
|
||||
ElMessage.success('模板上传成功');
|
||||
} catch (error: any) {
|
||||
ElMessage.error(error?.message || '模板上传失败');
|
||||
ElMessage.error(error?.message || "模板上传失败");
|
||||
} finally {
|
||||
uploadingIndex.value = null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user