From a3cac47d145109668679a3a089d41aca3c7a3fa7 Mon Sep 17 00:00:00 2001 From: liwenxuan <1298531568@qq.com> Date: Fri, 5 Sep 2025 10:52:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DesignForm/public/expand/lowcodeImage.vue | 118 +++++++++++++++++- .../DesignForm/public/form/formItem.vue | 1 + 2 files changed, 115 insertions(+), 4 deletions(-) diff --git a/src/components/DesignForm/public/expand/lowcodeImage.vue b/src/components/DesignForm/public/expand/lowcodeImage.vue index 3c7328f..6d44c32 100644 --- a/src/components/DesignForm/public/expand/lowcodeImage.vue +++ b/src/components/DesignForm/public/expand/lowcodeImage.vue @@ -14,6 +14,36 @@ import { ref,useAttrs } from 'vue' import { Plus } from '@element-plus/icons-vue' import type { UploadProps, UploadUserFile } from 'element-plus' +import { useRoute } from 'vue-router'; + +import { getCurrentInstance } from 'vue'; + +const getAncestorComponentNames = () => { + const ancestorNames = []; + let currentInstance = getCurrentInstance(); + + while (currentInstance?.parent) { + currentInstance = currentInstance.parent; + ancestorNames.push(currentInstance.type.name || 'UnknownComponent'); + } + + return ancestorNames; +}; +const ancestors = getAncestorComponentNames(); + +function hasELCard(ancestors:any) { + // 先判断入参是否为数组,避免非数组参数导致错误 + if (!Array.isArray(ancestors)) { + return false; + } + + // 检查数组中是否包含"ELCard" + return ancestors.includes("ElCard"); +} + +// 获取路由对象 +const route = useRoute(); + //const attrs = useAttrs() @@ -54,14 +84,77 @@ const value = computed({ return props.modelValue ? props.modelValue : errimg; } }); */ - +const toShow = ref(false) onMounted(()=>{ if(props.data.control.useDefaultImg){ emits("update:modelValue", props.data.control.imgUrl); }else{ } + + setTimeout(()=>{ + if(props.type=='1'){ + /* if(props.data.control.useDefaultImg){ + emits("update:modelValue", props.data.control.imgUrl); + } */ + }else{ + if(props.type==2&&hasELCard(ancestors)){ + props.data.control.uploadedImgs = completionImageDetails(value.value) + if(props.data.control.useDefaultImg==false&&props.data.control.onSiteShot==""){ + toShow.value = true + } + } + } + },1000) }) + +function completionImageDetails(urlString:string) { + // 分割URL字符串 + const urls = urlString.split(',').map(url => url.trim()).filter(url => url); + + if (urls.length === 0) { + /* throw new Error('未提供有效的图片URL'); */ + return {} + } + + return urls.map(url => { + // 提取文件名 + const fileName = url.substring(url.lastIndexOf('/') + 1); + + // 提取文件扩展名 + const fileExtension = fileName.substring(fileName.lastIndexOf('.')); + + // 生成本年的毫秒级时间戳 + const now = new Date(); + const startOfYear = new Date(now.getFullYear(), 0, 1); + const timestamp = startOfYear.getTime() + Math.floor(Math.random() * (now.getTime() - startOfYear.getTime())); + + // 生成18位随机数字ID + const randomId = Math.floor(Math.random() * 9e17) + 1e17; + + return { + name: fileName, + percentage: 100, + status: "success", + uid: timestamp, + url: url, + response: { + code: 0, + data: { + id: randomId, + key: "", + name: fileName, + tag: fileExtension, + url: url, + type: 1 + }, + msg: "成功!" + } + }; + }); + } + + //组件css部分 const configStyle = computed(() => { return props.data.styles || {}; @@ -193,6 +286,7 @@ function selectFile(){ }