|
@@ -49,9 +49,14 @@
|
|
|
<div class="img-box" v-if="item.imgList">
|
|
|
<div v-for="(iItem, index) in item.imgList" :key="index" class="img-box-content">
|
|
|
<span class="type">{{ iItem.type }}</span>
|
|
|
-
|
|
|
- <img :src="iItem.url" alt="" style="height: 50px; width: 50px" />
|
|
|
- <el-image class="img-item" lazy :src="iItem.url" :preview-src-list="getPreviewList(item.previewList, index)" />
|
|
|
+ <el-image
|
|
|
+ v-loading="imgErrorLoading"
|
|
|
+ class="img-item"
|
|
|
+ @error="(err) => imgeError(err, item, index, iItem.url)"
|
|
|
+ lazy
|
|
|
+ :src="iItem.url"
|
|
|
+ :preview-src-list="getPreviewList(item.previewList, index)"
|
|
|
+ />
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
@@ -90,6 +95,7 @@ import provinces from '@/util/lib/province';
|
|
|
import citys from '@/util/lib/city';
|
|
|
import areas from '@/util/lib/area';
|
|
|
import request from '@/router/axios';
|
|
|
+import heic2any from 'heic2any';
|
|
|
|
|
|
export default {
|
|
|
name: 'index',
|
|
@@ -102,6 +108,7 @@ export default {
|
|
|
taskTypeId: 0, // 任务类型id
|
|
|
configList: [], // 配置列表
|
|
|
dictList: [], //字典
|
|
|
+ imgErrorLoading: false,
|
|
|
imgTypeList: ['jpeg', 'jpg', 'png', 'git', 'bmp'] // 能查看的文件类型
|
|
|
};
|
|
|
},
|
|
@@ -135,6 +142,49 @@ export default {
|
|
|
},
|
|
|
|
|
|
// 得出图片
|
|
|
+ imgeError(err, item, index, url) {
|
|
|
+ this.imgErrorLoading = true;
|
|
|
+ this.handleImage(url, item, index);
|
|
|
+ },
|
|
|
+
|
|
|
+ // 检查文件是否为 HEIC 格式
|
|
|
+ isHeicFile(file) {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ const reader = new FileReader();
|
|
|
+ reader.onloadend = () => {
|
|
|
+ const buffer = reader.result;
|
|
|
+ // HEIC 文件的前几个字节为 "00 00 00 18 66 74 79 70 68 65 69 63" 或 "00 00 00 20 66 74 79 70 68 65 69 63" (小端字节序)
|
|
|
+ const signature = new Uint8Array(buffer).subarray(0, 12);
|
|
|
+ const heicSignature = [0x00, 0x00, 0x00, 0x18, 0x66, 0x74, 0x79, 0x70, 0x68, 0x65, 0x69, 0x63];
|
|
|
+
|
|
|
+ const isHeic = signature.every((byte, index) => byte === heicSignature[index]);
|
|
|
+ resolve(isHeic);
|
|
|
+ };
|
|
|
+ reader.onerror = reject;
|
|
|
+ reader.readAsArrayBuffer(file);
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ async handleImage(url, item, index) {
|
|
|
+ const response = await fetch(url);
|
|
|
+ const blob = await response.blob();
|
|
|
+
|
|
|
+ if (await this.isHeicFile(blob)) {
|
|
|
+ const heicImageBlob = await fetch(url).then((res) => res.blob());
|
|
|
+
|
|
|
+ // 使用 heic2any 库将 HEIC 转换为 JPG
|
|
|
+ heic2any({ blob: heicImageBlob, toType: 'image/jpeg' }).then((convertedBlob) => {
|
|
|
+ const imgURL = URL.createObjectURL(convertedBlob);
|
|
|
+ item.imgList[index].url = imgURL;
|
|
|
+ item.previewList[index] = imgURL;
|
|
|
+ this.$forceUpdate();
|
|
|
+ this.imgErrorLoading = false;
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ this.imgErrorLoading = false;
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
// 得出图片
|
|
|
getImgList(urlStr, item) {
|
|
|
// 如果字段类型不是图片或没有 urlStr,则直接返回空数组
|
|
@@ -145,7 +195,6 @@ export default {
|
|
|
// 如果拆分后为空,也返回空数组
|
|
|
if (!urlArr.length) return [[], []];
|
|
|
|
|
|
- console.log('urlArr', urlArr);
|
|
|
// 使用 reduce 一次性构建 imgList 和 previewList
|
|
|
const [imgList, previewList] = urlArr.reduce(
|
|
|
(acc, curUrl) => {
|
|
@@ -170,8 +219,6 @@ export default {
|
|
|
[[], []]
|
|
|
);
|
|
|
|
|
|
- console.log('imgList', [imgList, previewList]);
|
|
|
-
|
|
|
return [imgList, previewList];
|
|
|
},
|
|
|
|