spideredit.html 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. {{include "com/inc.html"}}
  2. <!-- Main Header -->
  3. {{include "com/header.html"}}
  4. <!-- Left side column. 权限菜单 -->
  5. {{include "com/menu.html"}}
  6. <style>
  7. /* 方法1:设置textarea合适的宽高 */
  8. #jsonTextarea {
  9. float: left;
  10. margin-right: 20px;
  11. width: 40%;
  12. height: 70vh;
  13. outline: none;
  14. padding: 5px;
  15. }
  16. /* 方法2:自定义高亮样式 */
  17. #jsonPre {
  18. float: left;
  19. width: 40%;
  20. height: 70vh;
  21. outline: 1px solid #ccc;
  22. padding: 5px;
  23. overflow: scroll;
  24. }
  25. </style>
  26. <div class="content-wrapper">
  27. <section class="content-header">
  28. <h1>
  29. {{if ne .T.bid ""}}
  30. 修复数据
  31. {{else}}
  32. 新增数据
  33. {{end}}
  34. </h1>
  35. <ol class="breadcrumb">
  36. <li><a href="#"><i class="fa fa-dashboard"></i> 爬虫数据维护</a></li>
  37. <li><a href="/lua/spiderwarn"> 异常数据管理</a></li>
  38. <li><a href="#">数据维护</a></li>
  39. </ol>
  40. </section>
  41. <!-- Main content -->
  42. <section class="content">
  43. <div class="nav-tabs-custom">
  44. <ul class="nav nav-tabs edit-step">
  45. {{if ne .T.bid ""}}
  46. <button class="btn btn-primary btn-sm" style="float: right;margin-top: 7px;margin-right: 10px" onclick="updateOrSave(1)"><i class="fa fa-fw fa-file-text fa-lg"></i>修复更新</button>
  47. <button class="btn btn-primary btn-sm" style="float: right;margin-top: 7px;margin-right: 10px" onclick="updateOrSave(2)"><i class="fa fa-fw fa-file-text fa-lg"></i>无需更新</button>
  48. {{else}}
  49. <button class="btn btn-primary btn-sm" style="float: right;margin-top: 7px;margin-right: 10px" onclick="updateOrSave(3)"><i class="fa fa-fw fa-file-text fa-lg"></i>修复发布</button>
  50. <button class="btn btn-primary btn-sm" style="float: right;margin-top: 7px;margin-right: 10px" onclick="updateOrSave(4)"><i class="fa fa-fw fa-file-text fa-lg"></i>直接发布</button>
  51. <button class="btn btn-primary btn-sm" style="float: right;margin-top: 7px;margin-right: 10px" onclick="updateOrSave(2)"><i class="fa fa-fw fa-file-text fa-lg"></i>无需发布</button>
  52. {{end}}
  53. </ul>
  54. <div class="box-body">
  55. <div class="form-group">
  56. <div class="col-sm-3">
  57. <input type="text" class="form-control" id="reasons" placeholder="请输入更新原因" required>
  58. </div>
  59. </div>
  60. </div>
  61. <form class="form-horizontal">
  62. <div class="box-body">
  63. <textarea id="jsonTextarea" style="width: 100%;height: 300px"></textarea>
  64. </div>
  65. <div class="box-body">
  66. <label class="col-sm-2 control-left"><span style="color:red;">* </span>请填写detail</label>
  67. <textarea id="jsonDetail" style="width: 100%;height: 300px;padding: 5px"></textarea>
  68. <label class="col-sm-2 control-left"><span style="color:red;">* </span>请填写contenthtml</label>
  69. <textarea id="jsonContentHtml" style="width: 100%;height: 300px;padding: 5px"></textarea>
  70. </div>
  71. <div class="box-body" id="summaryDiv">
  72. <label class="col-sm-2 control-left">请填写summary</label>
  73. <textarea id="summary" style="width: 100%;height: 200px;padding: 5px"></textarea>
  74. </div>
  75. </form>
  76. </div>
  77. </section>
  78. </div>
  79. {{include "com/footer.html"}}
  80. <script>
  81. menuActive("spiderwarn");
  82. var edit_data = {{.T.data}}
  83. var edit_contentHtml = {{.T.contenthtml}}
  84. var edit_detail = {{.T.detail}}
  85. var edit_summary = {{.T.summary}}
  86. var bid = {{.T.bid}}
  87. var edit_data_tmp = {{.T.data}}//记录汇总数据
  88. edit_data_tmp["detail"] = edit_detail
  89. edit_data_tmp["contenthtml"] = edit_contentHtml
  90. edit_data_tmp["summary"] = edit_summary
  91. function parse(str) {
  92. return JSON.stringify(str, null, "\t")
  93. }
  94. $('#jsonTextarea').val(parse(edit_data)); //其他属性
  95. $('#jsonDetail').val(edit_detail); //其他属性
  96. $('#jsonContentHtml').val(edit_contentHtml); //其他属性
  97. $('#summary').val(edit_summary);
  98. function updateOrSave(stype){
  99. /*
  100. * stype:
  101. * 1:修复更新
  102. * 2:无需更新
  103. * 3:修复发布
  104. * 4:直接发布
  105. * */
  106. if (stype == 1 || stype == 3){
  107. var reason=$("#reasons").val()
  108. if (reason=="") {
  109. showMsg("请填写更新数据原因")
  110. return;
  111. }
  112. }
  113. var data = JSON.parse($("#jsonTextarea").val())
  114. // 字段非空校验
  115. if (checkAddDict(data)) {
  116. let msg = "title,site,spidercode\nhref,channel,toptype\nsubtype,area\n非空必填信息,请补充完善信息"
  117. showMsg(msg)
  118. return;
  119. }
  120. var detail = $("#jsonDetail").val()
  121. var tmp_detail = ''+detail
  122. if (tmp_detail=="") {
  123. showMsg("请填写detail")
  124. return;
  125. }
  126. var tmp_content = $("#jsonContentHtml").val()
  127. if (tmp_content=="") {
  128. showMsg("请填写contenthtml")
  129. return;
  130. }
  131. // 判断除detail、contenthtml、summary外字段是否修改
  132. var modifyinfo = {}
  133. var update = {}
  134. // 修改
  135. for (var editDataKey in edit_data) {
  136. if (typeof edit_data[editDataKey] == "object") {
  137. if (JSON.stringify(data[editDataKey]) != JSON.stringify(edit_data[editDataKey])) {
  138. modifyinfo[editDataKey] = "剑鱼维护"
  139. update[editDataKey] = data[editDataKey]
  140. edit_data_tmp[editDataKey] = data[editDataKey]
  141. }
  142. }else {
  143. if (data[editDataKey] != edit_data[editDataKey]) {
  144. modifyinfo[editDataKey] = "剑鱼维护"
  145. update[editDataKey] = data[editDataKey]
  146. edit_data_tmp[editDataKey] = data[editDataKey]
  147. }
  148. }
  149. }
  150. //新增
  151. for (var dataKey in data) {
  152. if (edit_data[dataKey] == undefined) {
  153. modifyinfo[dataKey] = "剑鱼维护"
  154. update[dataKey] = data[dataKey]
  155. edit_data_tmp[dataKey] = data[dataKey]
  156. }
  157. }
  158. //判断detail、contenthtml、summary是否修改
  159. if (edit_detail != tmp_detail) {
  160. modifyinfo["detail"] = "剑鱼维护"
  161. update["detail"] = tmp_detail
  162. edit_data_tmp["detail"] = tmp_detail
  163. }
  164. if (edit_contentHtml.replace(/(\s|\t|\n)/g,'') != tmp_content.replace(/(\s|\t|\n)/g,'')) {
  165. modifyinfo["contenthtml"] = "剑鱼维护"
  166. update["contenthtml"] = tmp_content
  167. edit_data_tmp["contenthtml"] = tmp_content
  168. }
  169. var tmp_summary = $('#summary').val();
  170. if (edit_summary != tmp_summary) {
  171. modifyinfo["summary"] = "剑鱼维护"
  172. update["summary"] = tmp_summary
  173. edit_data_tmp["summary"] = tmp_summary
  174. }
  175. if (stype ==3 || stype ==4){//修复发布、直接发布 save
  176. update = edit_data_tmp
  177. }
  178. var str = ""
  179. if (Object.keys(update).length == 0 && stype != 2) {
  180. str = "没有修改任何字段信息!"
  181. showTip(str)
  182. return
  183. }else {
  184. if(Object.keys(modifyinfo).length == 0){
  185. str = "确定操作?"
  186. if (stype ==3){
  187. showTip("没有修改任何字段信息!")
  188. return
  189. }
  190. }else{
  191. if (stype ==2){
  192. showTip("请选择修复更新!")
  193. return
  194. }
  195. str = "确定修改以下字段信息?" + "<br>"
  196. for (const modifyinfoKey in modifyinfo) {
  197. str = str + modifyinfoKey + ","
  198. }
  199. }
  200. }
  201. // console.log("---",update)
  202. // console.log("---",modifyinfo)
  203. showConfirm(str, function() {
  204. $.ajax({
  205. url: "/lua/spiersave",
  206. type: 'POST',
  207. data: {
  208. "update": JSON.stringify(update),
  209. "modifyinfo": JSON.stringify(modifyinfo),
  210. "bid": bid,
  211. "id": {{.T.id}},
  212. "reasons": reason,
  213. "stype": stype
  214. },
  215. success: function (r) {
  216. if (r.success) {
  217. showMsg("保存成功",function (){
  218. window.location.href="/lua/spiderwarn"
  219. })
  220. } else {
  221. showTip(r.rep);
  222. }
  223. }
  224. })
  225. });
  226. }
  227. function checkAddDict(data) {
  228. if (data["title"]==""||data["site"]==""||data["spidercode"]==""||
  229. data["href"]==""||data["channel"]==""|| data["toptype"]==""||
  230. data["subtype"]==""|| data["area"]==""){
  231. return true
  232. }
  233. return false
  234. }
  235. </script>