Няма описание

viewcount.js 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /**
  2. * Created by TT on 2017/9/22.
  3. */
  4. ;
  5. spa_define(function () {
  6. return $.use(["spa", "code", "form", "util", "dict"], function (spa, code, form, util, dict) {
  7. return {
  8. main: function () {
  9. var root = spa.findInMain(".sys_article_viewcount");
  10. var qf = form.build(root.find(".queryForm"));
  11. var cr = code.parseCode(root.find(".dt-tpl"));
  12. var queryBtn = root.find(".queryForm .opt-query");
  13. var tableData = {data: []},
  14. allData = [],
  15. $data = {tn: "article"};
  16. Date.prototype.format = function (fmt) {
  17. var o = {
  18. "M+": this.getMonth() + 1, //月份
  19. "d+": this.getDate(), //日
  20. "h+": this.getHours(), //小时
  21. "m+": this.getMinutes(), //分
  22. "s+": this.getSeconds(), //秒
  23. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  24. "S": this.getMilliseconds() //毫秒
  25. };
  26. if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  27. for (var k in o)
  28. if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  29. return fmt;
  30. };
  31. var now = new Date(),
  32. nbt = new Date();
  33. nbt.setDate(now.getDate() - 7);
  34. var et1 = now.format("yyyyMMdd"),
  35. bt1 = nbt.format("yyyyMMdd");
  36. qf.val({bt: bt1, et: et1});
  37. $data.bt = bt1;
  38. $data.et = et1;
  39. var caption = function (dicts, code) {
  40. var items = dict.get(dicts);
  41. var cp = dict.getCap(items, code.toString());
  42. if (cp) {
  43. return cp;
  44. }else {
  45. return "不可翻译的";
  46. }
  47. // return dict.get(dicts)[code].caption;
  48. },
  49. showDay = function (day) {
  50. if (day) {
  51. return day.substring(0, 4) + "年" + day.substring(4, 6) + "月" + day.substring(6, 8) + "日";
  52. } else return "";
  53. },
  54. loadContent = function () {
  55. root.find(".hand-id").each(function () {
  56. var $e = $(this);
  57. var articleId = $e.attr("articleId");
  58. if (articleId) {
  59. util.get("../ajax/article/id",{id:articleId}, function (data) {
  60. if (data) {
  61. $e.parent().find(".articleTitle").text(data.articleTitle);
  62. $e.parent().find(".professorName").text(data.professorName || data.organizationName);
  63. $e.parent().find(".subject").text(data.subject);
  64. $e.parent().find(".colNum").text(caption("banner", data.colNum));
  65. $e.parent().find(".publishTime").text(showDay(data.publishTime));
  66. $e.parent().find(".sortNum").text(data.sortNum);
  67. $e.parent().find(".pageViews").text(data.pageViews);
  68. $e.parent().find(".articleAgree").text(data.articleAgree);
  69. }
  70. }, {});
  71. // // $e.removeClass("hand-id");
  72. }
  73. });
  74. },
  75. load = function () {
  76. console.log($data);
  77. $.ajax({
  78. type: "GET",
  79. url: "http://www.ekexiu.com:8082/log/jsonp/qs",
  80. data: $data,
  81. dataType: "jsonp",
  82. success: function (data) {
  83. console.log(data);
  84. allData = data.data || [];
  85. // allData = [{
  86. // id: "8F08D2EB366140BC85A6A4CE344A15A4"
  87. // }, {
  88. // id: "8DE678A43FFB4097B3E0DFF9C48CC737"
  89. // }];
  90. tableData.data = allData;
  91. cr.val(tableData.data);
  92. loadContent();
  93. }
  94. });
  95. },
  96. query = function () {
  97. // if (qf.val().bt || qf.val().et) {
  98. $data.bt = qf.val().bt;
  99. $data.et = qf.val().et;
  100. // }else {
  101. // $data.bt = "";
  102. // $data.et = "";
  103. // }
  104. load();
  105. };
  106. queryBtn.on("click", query);
  107. load();
  108. root.find(".dt-tpl").on("click", "th.opt-check>i.icon-st-check", function () {
  109. var $this = $(this);
  110. $this.toggleClass("checked");
  111. if ($this.hasClass("checked")) {
  112. root.find(".dt-tpl td.opt-check>i.icon-st-check").addClass("checked");
  113. } else {
  114. root.find(".dt-tpl td.opt-check>i.icon-st-check").removeClass("checked");
  115. }
  116. });
  117. root.find(".dt-tpl").on("click", "td.opt-check>i.icon-st-check", function () {
  118. var $this = $(this);
  119. $this.toggleClass("checked");
  120. });
  121. root.find(".opt-count").on("click", function () {
  122. var $article = root.find("td.opt-check>i.checked");
  123. if ($article.length) {
  124. if ($article.length>1) {
  125. util.alert("只能选择一篇文章");
  126. }else {
  127. spa.showModal("sys_article_count", {
  128. id: $article.attr("articleId"),
  129. hand: function () {
  130. pdg.reload();
  131. }
  132. });
  133. }
  134. }else {
  135. util.alert("请选择一篇文章");
  136. }
  137. });
  138. },
  139. mainDestory: function () {
  140. }
  141. };
  142. });
  143. });