load_content.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. var ret = {}
  2. var tmp = null
  3. if ("{{.TitleCss}}" != "") {//标题
  4. tmp = document.querySelector("{{.TitleCss}}")
  5. if (tmp) ret["title"] = tmp.getAttribute("title") || tmp.innerText
  6. }
  7. if ("{{.PublishUnitCss}}" != "") {//采购单位
  8. tmp = document.querySelector("{{.PublishUnitCss}}")
  9. if (tmp) ret["publishUnit"] = tmp.getAttribute("title") || tmp.innerText
  10. }
  11. if ("{{.PublishTimeCss}}" != "") {//发布时间
  12. tmp = document.querySelector("{{.PublishTimeCss}}")
  13. if (tmp) ret["publishTime"] = tmp.getAttribute("title") || tmp.innerText
  14. }
  15. if ("{{.ContentCss}}" != "") {//正文内容
  16. tmp = document.querySelector("{{.ContentCss}}")
  17. if (tmp) {
  18. ret["content"] = tmp.innerText
  19. ret["contentHtml"] = tmp.innerHTML
  20. var patchContent = false
  21. //处理详情页中的大图,大图作为附件使用
  22. const images = tmp.querySelectorAll("img");
  23. images.forEach((img, i) => {
  24. if (img.width > 300) {
  25. patchContent = true
  26. const a = document.createElement("a");
  27. a.href = img.src;
  28. a.innerText = img.src;
  29. tmp.appendChild(a);
  30. }
  31. })
  32. }
  33. }
  34. if("{{.AttachCss}}"!=""){//附件
  35. tmp = document.querySelectorAll("{{.AttachCss}} a")
  36. let attach=[]
  37. if(tmp){
  38. tmp.forEach((v,i)=>{
  39. attach.push({title:v.getAttribute("title")||v.innerText,href:v.href})
  40. })
  41. }
  42. ret["attachLinks"]=attach
  43. }
  44. //检查中文字符个数,少于20,修正正文内容
  45. let regex = /[\u4e00-\u9fa5]/g;
  46. let chineseCharacters = ret["content"]?ret["content"].match(regex):[];
  47. let chineseCharactersLen=chineseCharacters ? chineseCharacters.length : 0;
  48. if (chineseCharactersLen < 20 && ret["attachLinks"] && ret["attachLinks"].length > 0) ret["content"] = '详情请访问原网页!'
  49. ret