utils.js
2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import api from "@/api/search";
import {
buildCode
} from "@/assets/js/buildcodes";
const splitUrlOrigin = (url) => {
if (url.includes("://")) {
let temp = url.split("://")[1].split("/"),
newUrl = "";
temp.forEach((e, i) => {
if (i != 0) {
newUrl += "/" + e;
}
})
return newUrl;
} else {
return url;
}
};
export const splitUrlOriginG = splitUrlOrigin;
export const buildImgurl = (url) => {
let isHttps = window.config.https,
origin = window.location.origin;
if (isHttps) {
url.replace('http', 'https');
url.replace('20080', '20070')
}
if (!origin.includes("localhost")) {
url = origin + splitUrlOrigin(url);
}
return url;
};
export const matchDetailImg = (picUnidArr) => {
return new Promise((resolve, reject) => {
api.detailImgBatch({
pic_unids: picUnidArr,
})
.then((res) => {
let imgUnidEnum = {};
if (res.length > 0) {
res.forEach((item) => {
imgUnidEnum[item.pic_unid] = buildImgurl(item.pic_url);
});
}
resolve({
imgUnidEnum: imgUnidEnum
});
});
});
};
export const getDataList = (params, type = "") => {
let httpRequest = null;
if (type == "event") {
httpRequest = api.eventTableList;
} else {
httpRequest = api.tableList;
}
let origin = window.location.origin,
isLocalhost = false;
if (origin.includes("localhost")) {
isLocalhost = true;
}
return new Promise(async (resolve, reject) => {
const res = await httpRequest(params);
let formatterData = [],
picUnid_Arr = [];
res.list_data.forEach((item, index) => {
if (item.pics[0].pic_unid) {
picUnid_Arr.push(item.pics[0].pic_unid);
}
});
let imgUnidEnum = {};
if (picUnid_Arr.length > 0) {
const imgRes = await matchDetailImg(picUnid_Arr);
console.log('imgRes', imgRes);
imgUnidEnum = imgRes.imgUnidEnum;
}
console.log('imgUnidEnum', imgUnidEnum)
res.list_data.forEach((item, index) => {
const pic_unid = item.pics ? item.pics[0].pic_unid : null;
if (pic_unid) {
item.pics[0].src_url = imgUnidEnum[pic_unid] || "";
} else {
item.pics[0].src_url = "";
}
const videoSrc_url = item.video ? item.video[0].src_url : null;
if (videoSrc_url) {
if (!isLocalhost) {
item.video[0].src_url = origin + splitUrlOrigin(videoSrc_url);
}
}
formatterData.push(buildCode.init(item));
});
console.log('formatterData', formatterData)
resolve({
total_num: res.total_num,
formatterData: formatterData,
list_data: res.list_data
})
});
}