修改后

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