数通互联化工云平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

517 lines
15 KiB

<!--
@ 作者: 秦东
@ 时间: 2024-09-12 10:44:17
@ 备注: 图片
-->
1 year ago
<script lang="ts" setup>
import {
AnalysisCss,
AnalysisInputCss,
} from "@/components/DesignForm/public/form/calculate/cssInfo.ts";
1 year ago
import errimg from "@/assets/404_images/imgNotFound.png";
import { uploadUrl, getRequest } from "@/api/DesignForm";
7 months ago
import { ref,useAttrs } from 'vue'
import { Plus } from '@element-plus/icons-vue'
import type { UploadProps, UploadUserFile } from 'element-plus'
7 months ago
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();
7 months ago
7 months ago
//const attrs = useAttrs()
const props = withDefaults(
1 year ago
defineProps<{
modelValue?: string;
disabled?: boolean;
tablekey?: Object;
data?: Object;
formTableSetUp?: Object;
imgUrl?: string;
7 months ago
type: string;
1 month ago
isEdit: boolean;
1 year ago
}>(),
{}
);
const emits = defineEmits<{
1 year ago
(e: "update:modelValue", value: string): void;
}>();
const value = computed({
1 year ago
get: () => {
if (props.data.control.imgUrl == "") {
return props.modelValue ? props.modelValue : errimg;
7 months ago
//return props.modelValue ? props.modelValue : '';
1 year ago
} else {
return props.data.control.imgUrl;
}
},
set: (newVal: any) => {
emits("update:modelValue", newVal);
return newVal;
},
});
7 months ago
/* const value = computed(() => {
if(props.data.control.useDefaultImg){
return props.data.control.imgUrl
}else{
return props.modelValue ? props.modelValue : errimg;
}
}); */
7 months ago
const toShow = ref(false)
7 months ago
onMounted(()=>{
if(props.data.control.useDefaultImg){
emits("update:modelValue", props.data.control.imgUrl);
}else{
}
7 months ago
setTimeout(()=>{
if(props.type=='1'){
/* if(props.data.control.useDefaultImg){
emits("update:modelValue", props.data.control.imgUrl);
} */
}else{
if(props.type==2&&hasELCard(ancestors)){
7 months ago
if(value.value=="/src/assets/404_images/imgNotFound.png"){
}else{
props.data.control.uploadedImgs = completionImageDetails(value.value)
if(props.data.control.useDefaultImg==false&&props.data.control.onSiteShot==""){
toShow.value = true
}
7 months ago
}
7 months ago
7 months ago
}
}
7 months ago
},100)
7 months ago
})
7 months ago
function completionImageDetails(urlString:string) {
// 分割URL字符串
const urls = urlString.split(',').map(url => url.trim()).filter(url => url);
7 months ago
//console.log(urls)
7 months ago
if (urls.length === 0) {
/* throw new Error('未提供有效的图片URL'); */
7 months ago
return {}
7 months ago
}
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;
7 months ago
if(url=="/src/assets/404_images/imgNotFound.png"){
return {}
}else{
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: "成功!"
}
};
}
7 months ago
});
}
//组件css部分
const configStyle = computed(() => {
1 year ago
return props.data.styles || {};
});
1 year ago
const imgLoading = ref(false);
const imgPath = ref(errimg);
//文件上传的格式与大小
7 months ago
const beforeAvatarUpload = (rawFile: { type: string; size: number; }) => {
1 year ago
imgLoading.value = true;
// console.log("文件上传的格式与大小",rawFile.type)
1 year ago
let imgType = ["image/jpeg", "image/jpg", "image/png", "image/gif", "image/svg"];
if (!imgType.includes(rawFile.type)) {
1 year ago
ElMessage.error("您上传的不是图片!");
imgLoading.value = false;
return false;
} else if (rawFile.size / 1024 / 1024 > 200) {
1 year ago
ElMessage.error("您上传到额图片大于 200MB!");
imgLoading.value = false;
return false;
}
1 year ago
return true;
};
//上传成功回调
7 months ago
const handleAvatarSuccess = (response: { data: { url: string; }; }, uploadFile: any) => {
// imageUrl.value = URL.createObjectURL(uploadFile.raw!)
// console.log("上传成功回调", value);
1 year ago
emits("update:modelValue", response.data.url);
imgPath.value = response.data.url;
value.value = response.data.url;
// console.log("上传成功回调---------->", value.value);
1 year ago
// let oldFormSetUp = props.formTableSetUp
// if(props.formTableSetUp && props.formTableSetUp.list && props.formTableSetUp.list.length > 0){
// oldFormSetUp.list.forEach((item)=>{
// if(item.name && item.name == props.data.name){
// // value.value = response.data.url
// // item.control.link = response.data.url
// value.set(response.data.url)
// emits('update:modelValue', response.data.url)
// console.log("上传成功回调------>",response.data.url)
// }
// })
// }
// props.setimgurl=response.data.url
// emits("update:imgUrl",response.data.url)
// console.log("上传成功回调------>",url.value)
// emits("updateCont",response.data.url)
imgLoading.value = false;
};
const getFormItemInputStyle = (ele: any, sty: number) => {
if (ele?.inputStyle) {
// console.log("返回栅格宽度4", AnalysisInputCss(ele?.inputStyle, sty));
1 year ago
return AnalysisInputCss(ele?.inputStyle, sty);
}
};
7 months ago
const showUpload = computed(() => {
if(!value||value.value == ""||value.value=="/src/assets/404_images/imgNotFound.png"){
return true
}else{
return false
}
});
const handleRemove: UploadProps['onRemove'] = (uploadFile, uploadFiles) => {
console.log(uploadFile, uploadFiles)
let arrStr = ''
uploadFiles.forEach((element) => {
//console.log(element.response.data.url)
arrStr+= element.response.data.url+","
});
arrStr = arrStr.slice(0, -1);
console.log(arrStr)
emits("update:modelValue", arrStr);
}
const handlePictureCardPreview: UploadProps['onPreview'] = (uploadFile) => {
dialogImageUrl.value = uploadFile.url!
dialogVisible.value = true
}
const dialogImageUrl = ref('')
const dialogVisible = ref(false)
const valueArr = computed(()=>{
return value.value.split(',');
})
//上传成功回调
const handleAvatarSuccess1 = (response: any, uploadFile: any) => {
// imageUrl.value = URL.createObjectURL(uploadFile.raw!)
// console.log("上传成功回调", value);
/* console.log(response.data.url)
console.log(uploadFile) */
let arrStr = ''
props.data.control.uploadedImgs.forEach((element: { url: any; }) => {
//console.log(element.response.data.url)
arrStr+= element.response.data.url+","
});
arrStr = arrStr.slice(0, -1);
console.log(arrStr)
emits("update:modelValue", arrStr);
/*imgPath.value = response.data.url;
value.value = response.data.url; */
imgLoading.value = false;
};
const fileUpload = ref(null);
function selectFile(){
//fileUpload.value.$refs.input.click();
//console.log()
//fileUpload.handleStart();
fileUpload.value.$el.querySelector('input[type="file"]').click();
}
6 months ago
//const fit = props.data.styles.divStyle.objectFit!=undefined ? props.data.styles.divStyle.objectFit : 'fill'
const fit = computed(()=>{
if(props.data.styles.divStyle&&props.data.styles.divStyle.objectFit){
return props.data.styles.divStyle.objectFit
}else{
return 'fill'
}
})
</script>
<template>
6 months ago
<el-image
v-if="(!hasELCard(ancestors))&&props.data.control.useDefaultImg&&props.type==5"
7 months ago
:src="value"
class="avatar"
:style="getFormItemInputStyle(configStyle, 2)"
6 months ago
:fit="fit"
7 months ago
/>
7 months ago
6 months ago
<el-image
7 months ago
v-if="props.data.control.useDefaultImg&&props.type==4"
:src="props.modelValue"
class="avatar"
:style="getFormItemInputStyle(configStyle, 2)"
6 months ago
:fit="fit"
7 months ago
/>
6 months ago
<el-image
v-if="props.data.control.useDefaultImg&&props.type!=4&&props.type!=5&&props.data.control.defaultAllowsChange=='0'"
:src="props.modelValue"
class="avatar"
:style="getFormItemInputStyle(configStyle, 2)"
6 months ago
:fit="fit"
/>
7 months ago
7 months ago
<el-upload
1 month ago
v-if="props.type!=4&&props.type!=5&&props.data.control.defaultAllowsChange==''&&!props.isEdit"
7 months ago
v-bind="$props"
class="upload-demo"
:action="uploadUrl"
:show-file-list="false"
:on-success="handleAvatarSuccess"
:before-upload="beforeAvatarUpload"
v-loading="imgLoading"
1 month ago
:disabled="props.isEdit"
7 months ago
>
6 months ago
<el-image
7 months ago
v-if="props.data.control.useDefaultImg"
:src="props.modelValue"
class="avatar"
:style="getFormItemInputStyle(configStyle, 2)"
6 months ago
:fit="fit"
7 months ago
/>
</el-upload>
<el-upload
1 month ago
v-if="props.type==1&&!props.isEdit"
v-bind="$props"
class="upload-demo"
:action="uploadUrl"
:show-file-list="false"
:on-success="handleAvatarSuccess"
:before-upload="beforeAvatarUpload"
v-loading="imgLoading"
1 month ago
:disabled="props.isEdit"
>
<el-image
:src="props.modelValue?props.modelValue:NoImgPage"
class="avatar"
:style="getFormItemInputStyle(configStyle, 2)"
:fit="fit"
/>
7 months ago
</el-upload>
7 months ago
<!-- <img referrerpolicy="no-referrer" :src="url" :style="styleObject" :fit="fit" :class="[boderAndShadowClassIsActive ? boderAndShadowClass : '', radiusClassIsActive ? radiusClass : '',mp, floatFlag ? floatStyle : '']" /> -->
<!-- <div></div> -->
<!-- <el-upload
1 year ago
v-bind="$props"
class="upload-demo"
:action="uploadUrl"
:show-file-list="false"
:on-success="handleAvatarSuccess"
:before-upload="beforeAvatarUpload"
v-loading="imgLoading"
>
7 months ago
<el-icon v-if="!props.data.control.useDefaultImg" class="avatar-uploader-icon"><Plus /></el-icon>
</el-upload> -->
<!--
-->
<!-- <el-upload
v-if="!props.data.control.useDefaultImg"
v-model:file-list="props.data.control.uploadedImgs"
:action="uploadUrl"
list-type="picture-card"
:on-preview="handlePictureCardPreview"
:on-remove="handleRemove"
:before-upload="beforeAvatarUpload"
v-loading="imgLoading"
:on-success="handleAvatarSuccess1"
>
<el-icon><Plus /></el-icon>
</el-upload> -->
7 months ago
<div v-if="!props.data.control.useDefaultImg&&props.type!=4&&props.data.control.onSiteShot==''" style="width: 100%; padding-bottom: 2px;">
7 months ago
<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>
7 months ago
<div v-if="!props.data.control.useDefaultImg&&props.type!=4&&props.data.control.onSiteShot&&props.data.control.onSiteShot=='1'" style="width: 100%; color:orangered;padding-top: 4px !important;padding-bottom: 5px;">
7 months ago
7 months ago
<div v-if="props.type!=5&&hasELCard(ancestors)"><span v-if="props.type==2">不可修改 </span>仅允许现场手机拍照上传</div>
7 months ago
<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>
7 months ago
<el-upload
ref="fileUpload"
class="upload-demo"
7 months ago
v-if="(!props.data.control.useDefaultImg)&&props.data.control.onSiteShot==''"
7 months ago
:auto-upload="true"
v-model:file-list="props.data.control.uploadedImgs"
:action="uploadUrl"
list-type="picture-card"
:on-preview="handlePictureCardPreview"
:on-remove="handleRemove"
:before-upload="beforeAvatarUpload"
v-loading="imgLoading"
:on-success="handleAvatarSuccess1"
style="margin-top: 10px;"
1 month ago
:disabled="props.isEdit"
7 months ago
>
<template #trigger>
<div style="display: none;">
<el-button>默认选择按钮</el-button>
</div>
</template>
1 year ago
</el-upload>
7 months ago
<!-- 详情页略缩图列表 -->
<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" style="min-height: 42px;display: flex; align-items: center; justify-content: center;">
7 months ago
<el-image
v-if="url!='/src/assets/404_images/imgNotFound.png'"
7 months ago
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"
/>
<span v-else style="display: inline-block;"></span>
7 months ago
</div>
7 months ago
<!-- 详情页略缩图列表 -->
<!-- <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>
-->
7 months ago
7 months ago
<el-dialog v-model="dialogVisible" style="width:90%">
7 months ago
<img w-full :src="dialogImageUrl" alt="Preview Image" />
</el-dialog>
</template>
7 months ago
<style lang="scss" >
/* .upload-demo {
1 year ago
img {
min-width: 150px;
max-width: 300px;
1 year ago
}
7 months ago
} */
.avatar {
7 months ago
width: 100%
}
.el-upload-list--picture-card {
--el-upload-list-picture-card-size: 109px;
}
.el-upload--picture-card {
--el-upload-picture-card-size: 0px !important;
align-items: center;
background-color: var(--el-fill-color-lighter);
border: 0px dashed var(--el-border-color-darker) !important;
border-radius: 6px;
box-sizing: border-box;
cursor: none !important;
display: inline-flex;
height: var(--el-upload-picture-card-size);
justify-content: center;
vertical-align: top;
width: var(--el-upload-picture-card-size);
}
.upload-demo .el-upload-list__item.is-success:focus:not(:hover){
display: none !important;
}
</style>