Browse Source

图片

qin_26
liwenxuan 3 months ago
parent
commit
a3cac47d14
  1. 118
      src/components/DesignForm/public/expand/lowcodeImage.vue
  2. 1
      src/components/DesignForm/public/form/formItem.vue

118
src/components/DesignForm/public/expand/lowcodeImage.vue

@ -14,6 +14,36 @@ import { ref,useAttrs } from 'vue'
import { Plus } from '@element-plus/icons-vue' import { Plus } from '@element-plus/icons-vue'
import type { UploadProps, UploadUserFile } from 'element-plus' 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() //const attrs = useAttrs()
@ -54,14 +84,77 @@ const value = computed({
return props.modelValue ? props.modelValue : errimg; return props.modelValue ? props.modelValue : errimg;
} }
}); */ }); */
const toShow = ref(false)
onMounted(()=>{ onMounted(()=>{
if(props.data.control.useDefaultImg){ if(props.data.control.useDefaultImg){
emits("update:modelValue", props.data.control.imgUrl); emits("update:modelValue", props.data.control.imgUrl);
}else{ }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()));
// 18ID
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 //css
const configStyle = computed(() => { const configStyle = computed(() => {
return props.data.styles || {}; return props.data.styles || {};
@ -193,6 +286,7 @@ function selectFile(){
} }
</script> </script>
<template> <template>
<el-upload <el-upload
v-bind="$props" v-bind="$props"
class="upload-demo" class="upload-demo"
@ -248,7 +342,7 @@ function selectFile(){
</div> </div>
<div v-if="!props.data.control.useDefaultImg&&props.type!=4&&props.data.control.onSiteShot&&props.data.control.onSiteShot=='1'" style="width: 100%; color:orangered"> <div v-if="!props.data.control.useDefaultImg&&props.type!=4&&props.data.control.onSiteShot&&props.data.control.onSiteShot=='1'" style="width: 100%; color:orangered">
<div v-if="props.type!=5">仅允许现场手机拍照上传</div> <div v-if="props.type!=5&&hasELCard(ancestors)"><span v-if="props.type==2">不可修改 </span>仅允许现场手机拍照上传</div>
<div v-else ><el-button @click="selectFile" style="color:grey;font-weight: bolder;"><el-icon style="margin-right: 7px;font-weight: bolder;"><Plus /></el-icon></el-button></div> <div v-else ><el-button @click="selectFile" style="color:grey;font-weight: bolder;"><el-icon style="margin-right: 7px;font-weight: bolder;"><Plus /></el-icon></el-button></div>
</div> </div>
@ -256,7 +350,7 @@ function selectFile(){
<el-upload <el-upload
ref="fileUpload" ref="fileUpload"
class="upload-demo" class="upload-demo"
v-if="!props.data.control.useDefaultImg" v-if="(!props.data.control.useDefaultImg)&&props.data.control.onSiteShot==''"
:auto-upload="true" :auto-upload="true"
v-model:file-list="props.data.control.uploadedImgs" v-model:file-list="props.data.control.uploadedImgs"
:action="uploadUrl" :action="uploadUrl"
@ -276,7 +370,7 @@ function selectFile(){
</el-upload> </el-upload>
<!-- 详情页略缩图列表 --> <!-- 详情页略缩图列表 -->
<div v-if ="!props.data.control.useDefaultImg&&props.type==4" v-for="url in valueArr" class="demo-image__preview"> <div v-if ="(!props.data.control.useDefaultImg)&&((props.type==2&&props.data.control.onSiteShot=='1')||props.type==4)" v-for="url in valueArr" class="demo-image__preview">
<el-image <el-image
style="width: 100px; height: 100px;margin: 4px;border: #DCDFE6 1px solid; border-radius: 8px;" style="width: 100px; height: 100px;margin: 4px;border: #DCDFE6 1px solid; border-radius: 8px;"
:src="url" :src="url"
@ -291,6 +385,22 @@ function selectFile(){
</div> </div>
<!-- 详情页略缩图列表 -->
<!-- <div v-if ="(!props.data.control.useDefaultImg)&&props.data.control.onSiteShot=='1'&&props.type==undefined&&hasELCard(ancestors)&&props.type!=1" v-for="url in valueArr" class="demo-image__preview">
<el-image
style="width: 100px; height: 100px;margin: 4px;border: #DCDFE6 1px solid; border-radius: 8px;"
:src="url"
:zoom-rate="1.2"
:max-scale="7"
:min-scale="0.2"
:preview-src-list="valueArr"
show-progress
:initial-index="4"
fit="cover"
/>
</div>
-->
<el-dialog v-model="dialogVisible"> <el-dialog v-model="dialogVisible">

1
src/components/DesignForm/public/form/formItem.vue

@ -1482,6 +1482,7 @@ const diGuiJilian = (val: any, options: any[]) => {
: '请选择' + getLabel(data.item) : '请选择' + getLabel(data.item)
" "
:data="data" :data="data"
:type="type"
:tablekey="props.tablekey" :tablekey="props.tablekey"
:form-table-set-up="props.alldata" :form-table-set-up="props.alldata"
v-model="value" v-model="value"

Loading…
Cancel
Save