jscodetpl.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //模板
  2. export const TemplateJsCode={
  3. ListJsCode:`
  4. var ret = []
  5. document.querySelectorAll("{{.ListItemCss}}").forEach((v, i) => {
  6. let item = {}
  7. if ("{{.ListLinkCss}}" != "") {
  8. let link = v.querySelector("{{.ListLinkCss}}")
  9. if (link) {
  10. var href = link.href
  11. if (!href.startsWith("http")) href = window.location.origin + "/" + href
  12. let title = link.getAttribute("title") || link.innerText
  13. item = { "title": title, "href": href, "no": i }
  14. } else {
  15. item = { "no": i }
  16. }
  17. }
  18. if ("{{.ListPubtimeCss}}" != "") {
  19. let pubtime = v.querySelector("{{.ListPubtimeCss}}")
  20. if (pubtime) {
  21. item["pubtime"] = pubtime.innerText
  22. }
  23. }
  24. ret.push(item)
  25. })
  26. ret
  27. `,
  28. ContentJsCode:`
  29. //执行JS代码
  30. var ret = {}
  31. var tmp = null
  32. if ("{{.TitleCss}}" != "") {//标题
  33. tmp = document.querySelector("{{.TitleCss}}")
  34. if (tmp) ret["title"] = tmp.getAttribute("title") || tmp.innerText
  35. }
  36. if ("{{.PublishUnitCss}}" != "") {//采购单位
  37. tmp = document.querySelector("{{.PublishUnitCss}}")
  38. if (tmp) ret["publishUnit"] = tmp.getAttribute("title") || tmp.innerText
  39. }
  40. if ("{{.PublishTimeCss}}" != "") {//发布时间
  41. tmp = document.querySelector("{{.PublishTimeCss}}")
  42. if (tmp) ret["publishTime"] = tmp.getAttribute("title") || tmp.innerText
  43. }
  44. if ("{{.ContentCss}}" != "") {//正文内容
  45. tmp = document.querySelector("{{.ContentCss}}")
  46. if (tmp) {
  47. ret["content"] = tmp.innerText
  48. ret["contentHtml"] = tmp.innerHTML
  49. }
  50. }
  51. if("{{.AttachCss}}"!=""){//附件
  52. tmp = document.querySelectorAll("{{.AttachCss}} a")
  53. let attach=[]
  54. if(tmp){
  55. tmp.forEach((v,i)=>{
  56. attach.push([v.getAttribute("title")||v.innerText,v.href])
  57. })
  58. }
  59. ret["attachLinks"]=attach
  60. }
  61. ret
  62. `,
  63. AttachJsCode:`
  64. //附件下载以及提交
  65. `,
  66. ListTurnPageJsCode: `
  67. //列表页翻页代码
  68. `
  69. }