2024-04-28 10:10:03 +08:00
|
|
|
<template>
|
2024-11-25 13:57:24 +08:00
|
|
|
<view>
|
|
|
|
|
<l-upload
|
|
|
|
|
ref="imgUpload"
|
|
|
|
|
uploadType="img"
|
|
|
|
|
:serverUrl="BASE_URL"
|
|
|
|
|
:formData="{ isImg: 'true' }"
|
|
|
|
|
:width="110"
|
|
|
|
|
:height="110"
|
|
|
|
|
:images="_value || []"
|
|
|
|
|
:header="header"
|
|
|
|
|
:max-size="props.formProps.maxSize"
|
|
|
|
|
:disableAdd="readonly"
|
|
|
|
|
:limit="props.formProps.maxNumber"
|
|
|
|
|
@complete="complete"
|
|
|
|
|
@remove="remove"
|
|
|
|
|
:disable="readonly"
|
|
|
|
|
>
|
|
|
|
|
</l-upload>
|
|
|
|
|
<view v-if="!readonly" style="color: #999999; font-size: 26rpx"
|
|
|
|
|
>{{ props.formProps.placeholder || "请上传图片" }}
|
|
|
|
|
{{ sizeTip }}
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
2024-04-28 10:10:03 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2024-11-25 13:57:24 +08:00
|
|
|
import { ref, computed } from "vue";
|
|
|
|
|
import { BASE_URL } from "@/api/request.js";
|
|
|
|
|
import { checkfaceHikvisionApi } from "@/api/imageApi";
|
|
|
|
|
const imageStyles = {
|
|
|
|
|
width: 80,
|
|
|
|
|
height: 80,
|
|
|
|
|
padding: "19rpx",
|
|
|
|
|
};
|
2024-04-28 10:10:03 +08:00
|
|
|
|
2024-11-25 13:57:24 +08:00
|
|
|
const header = ref({
|
|
|
|
|
Authorization: "Bearer " + uni.getStorageSync("wflow-token"),
|
|
|
|
|
});
|
2024-04-28 10:10:03 +08:00
|
|
|
|
2024-11-25 13:57:24 +08:00
|
|
|
const props = defineProps({
|
|
|
|
|
formProps: {
|
|
|
|
|
type: Object,
|
|
|
|
|
default: () => {
|
|
|
|
|
return {};
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
modelValue: Array,
|
|
|
|
|
readonly: Boolean,
|
|
|
|
|
title: String,
|
|
|
|
|
});
|
|
|
|
|
const originVal = ref([]);
|
|
|
|
|
const _value = computed({
|
|
|
|
|
get() {
|
2025-03-25 14:52:27 +08:00
|
|
|
return props.modelValue;
|
2024-11-25 13:57:24 +08:00
|
|
|
let dealArr = [];
|
|
|
|
|
// console.log(JSON.stringify(props.modelValue),123)
|
|
|
|
|
// console.log(JSON.stringify(originVal.value),456)
|
|
|
|
|
// console.log(JSON.stringify(dealArr),111222)
|
|
|
|
|
if (JSON.stringify(props.modelValue) == JSON.stringify(originVal.value)) {
|
|
|
|
|
return originVal.value;
|
|
|
|
|
}
|
|
|
|
|
originVal.value.length = 0;
|
|
|
|
|
if (props.modelValue) {
|
|
|
|
|
originVal.value = props.modelValue;
|
|
|
|
|
console.log(JSON.stringify(originVal.value), 888);
|
|
|
|
|
originVal.value.map((item) => {
|
|
|
|
|
if (
|
|
|
|
|
item.url.indexOf("http://") != -1 ||
|
|
|
|
|
item.url.indexOf("https://") != -1
|
|
|
|
|
) {
|
|
|
|
|
dealArr.push({
|
|
|
|
|
...item,
|
|
|
|
|
id: item.name,
|
|
|
|
|
url: item.name,
|
2025-03-25 14:52:27 +08:00
|
|
|
// isImage: true,
|
|
|
|
|
// contentType: "image/png",
|
2024-11-25 13:57:24 +08:00
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
dealArr.push({
|
|
|
|
|
...item,
|
|
|
|
|
id: item.url,
|
|
|
|
|
url: item.url,
|
2025-03-25 14:52:27 +08:00
|
|
|
// isImage: true,
|
|
|
|
|
// contentType: "image/png",
|
2024-11-25 13:57:24 +08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return dealArr;
|
|
|
|
|
} else {
|
|
|
|
|
return props.modelValue;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
set(val) {
|
|
|
|
|
emits("update:modelValue", val);
|
|
|
|
|
},
|
|
|
|
|
});
|
2024-04-28 10:10:03 +08:00
|
|
|
|
2024-11-25 13:57:24 +08:00
|
|
|
const sizeTip = computed(() => {
|
|
|
|
|
return props.formProps.maxSize > 0
|
|
|
|
|
? `| 每张图不超过${props.formProps.maxSize}MB`
|
|
|
|
|
: "";
|
|
|
|
|
});
|
2024-04-28 10:10:03 +08:00
|
|
|
|
2024-11-25 13:57:24 +08:00
|
|
|
const emits = defineEmits(["update:modelValue", "resize"]);
|
2024-04-28 10:10:03 +08:00
|
|
|
|
2024-11-25 13:57:24 +08:00
|
|
|
const imgUpload = ref();
|
2024-04-28 10:10:03 +08:00
|
|
|
|
2024-11-25 13:57:24 +08:00
|
|
|
function resizeCollapse() {
|
|
|
|
|
setTimeout(() => emits("resize"), 800);
|
|
|
|
|
}
|
2024-06-05 21:35:18 +08:00
|
|
|
|
2024-11-25 13:57:24 +08:00
|
|
|
async function complete(e) {
|
|
|
|
|
console.log(JSON.stringify(e), 666777);
|
|
|
|
|
console.log(props.title, 666778);
|
|
|
|
|
if (props.title == "人脸采集图片") {
|
|
|
|
|
const imgInfo = e.imageArr[0];
|
|
|
|
|
if (
|
|
|
|
|
imgInfo.contentType != "image/jpeg" &&
|
|
|
|
|
imgInfo.contentType != "image/jpg"
|
|
|
|
|
// file.type != "image/png"
|
|
|
|
|
) {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
icon: "none",
|
|
|
|
|
title: "请上传jpg格式图片",
|
|
|
|
|
});
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
let imgSize = Number(imgInfo.size / 1024);
|
2024-06-05 21:35:18 +08:00
|
|
|
|
2024-11-25 13:57:24 +08:00
|
|
|
if (imgSize <= 10 || imgSize >= 200) {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
icon: "none",
|
|
|
|
|
title: "文件大小不能超过200kb小于10kb,请重新上传!",
|
|
|
|
|
});
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
let data = { fileUrl: imgInfo.url };
|
|
|
|
|
const result = await checkfaceHikvisionApi(data);
|
2024-04-28 10:10:03 +08:00
|
|
|
|
2024-11-25 13:57:24 +08:00
|
|
|
if (result.data.code == 200 && result.data.result.checkType == "1") {
|
|
|
|
|
_value.value = e.imageArr;
|
|
|
|
|
} else {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
icon: "none",
|
|
|
|
|
title: result.data.result.message,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
_value.value = e.imageArr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((_value.value || []).length < e.imageArr.length) {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
icon: "none",
|
|
|
|
|
title: "上传图片成功",
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
icon: "none",
|
|
|
|
|
title: "移除图片成功",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
resizeCollapse();
|
|
|
|
|
}
|
2024-04-28 10:10:03 +08:00
|
|
|
|
2024-11-25 13:57:24 +08:00
|
|
|
function remove(i) {
|
|
|
|
|
if (!props.readonly) {
|
|
|
|
|
_value.value.splice(i, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
2024-04-28 10:10:03 +08:00
|
|
|
|
2024-11-25 13:57:24 +08:00
|
|
|
<style></style>
|