数通互联化工云平台
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.

131 lines
3.7 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";
import errimg from "@/assets/404_images/imgNotFound.png";
import { uploadUrl, getRequest } from "@/api/DesignForm";
const props = withDefaults(
1 year ago
defineProps<{
modelValue?: string;
disabled?: boolean;
tablekey?: Object;
data?: Object;
formTableSetUp?: Object;
imgUrl?: string;
}>(),
{}
);
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;
} else {
return props.data.control.imgUrl;
}
},
set: (newVal: any) => {
emits("update:modelValue", newVal);
return newVal;
},
});
//组件css部分
const configStyle = computed(() => {
1 year ago
return props.data.styles || {};
});
1 year ago
const imgLoading = ref(false);
const imgPath = ref(errimg);
//文件上传的格式与大小
const beforeAvatarUpload = (rawFile) => {
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;
};
//上传成功回调
1 year ago
const handleAvatarSuccess = (response, uploadFile) => {
// 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);
}
};
</script>
<template>
1 year ago
<el-upload
v-bind="$props"
class="upload-demo"
:action="uploadUrl"
:show-file-list="false"
:on-success="handleAvatarSuccess"
:before-upload="beforeAvatarUpload"
v-loading="imgLoading"
>
<!-- <img referrerpolicy="no-referrer" :src="url" :style="styleObject" :fit="fit" :class="[boderAndShadowClassIsActive ? boderAndShadowClass : '', radiusClassIsActive ? radiusClass : '',mp, floatFlag ? floatStyle : '']" /> -->
<img
v-if="value"
:src="value"
class="avatar"
:style="getFormItemInputStyle(configStyle, 2)"
/>
<el-icon v-else class="avatar-uploader-icon"><Plus /></el-icon>
</el-upload>
</template>
1 year ago
<style lang="scss" scoped>
.upload-demo {
img {
min-width: 150px;
max-width: 300px;
1 year ago
}
}
.avatar {
width: 150px;
}
</style>