修改后

This commit is contained in:
熊丽君
2021-08-16 08:46:44 +08:00
parent 6adc027fe1
commit d27bf459d1

View File

@ -1,29 +1,37 @@
import { handlePic } from '@/api/home/notice';
export function formatRichText(url, id) {
// let src = document.querySelectorAll('#text .ql-editor img');
/**
* 不需要判断域名存不存在
*/
let status = true;
let src = document.querySelectorAll('#text img');
let endUrl = [];
for (let i = 0; i < src.length; i++) {
const string = src[i].getAttribute('src');
endUrl.push(string);
// 包括
const flag = string.includes('http://');
// 不包括
if (!flag) src[i].setAttribute('src', url + string);
}
if (url == 'http://drc.hefei.gov.cn') {
const data = {
startUrl: url,
policyId: id,
endUrl
};
handlePic(data).then(({ data: res }) => {
res.map(item => {
for (let i = 0; i < src.length; i++) {
src[i].setAttribute('src', item.name);
}
});
});
// 域名存在
if (status) {
if (i == src.length - 1) {
const data = {
startUrl: url,
policyId: id,
endUrl
};
handlePic(data).then(({ data: res }) => {
console.log(res);
for (let i = 0; i < src.length; i++) {
src[i].setAttribute('src', res[i].name);
}
});
}
} else {
// 域名不存在并且不包含http
if (!flag) src[i].setAttribute('src', url + string);
}
}
// let src2 = document.querySelectorAll('#text .ql-editor a');
let src2 = document.querySelectorAll('#text a');