2
0

historay.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. * 显示句子历史记录窗口
  3. */
  4. function historay_init() {
  5. $("body").append('<div id="sent_history_dlg" title="History"><div id="sent_history_content"></div></div>');
  6. $("#sent_history_dlg").dialog({
  7. autoOpen: false,
  8. width: 550,
  9. buttons: [
  10. {
  11. text: "Save",
  12. click: function () {
  13. $(this).dialog("close");
  14. },
  15. },
  16. {
  17. text: "Cancel",
  18. click: function () {
  19. $(this).dialog("close");
  20. },
  21. },
  22. ],
  23. });
  24. }
  25. function history_show(id) {
  26. $.get(
  27. "../usent/historay_get.php",
  28. {
  29. id: id,
  30. },
  31. function (data) {
  32. let result = JSON.parse(data);
  33. let html = "";
  34. if (result.status == 0) {
  35. let currDate = new Date();
  36. for (const iterator of result.data) {
  37. let pass = currDate.getTime() - iterator.date;
  38. let strPassTime = "";
  39. if (pass < 60 * 1000) {
  40. //一分钟内
  41. strPassTime = Math.floor(pass / 1000) + "秒前";
  42. } else if (pass < 3600 * 1000) {
  43. //一小时内
  44. strPassTime = Math.floor(pass / 1000 / 60) + "分钟前";
  45. } else if (pass < 3600 * 24 * 1000) {
  46. //一天内
  47. strPassTime = Math.floor(pass / 1000 / 3600) + "小时前";
  48. } else if (pass < 3600 * 24 * 7 * 1000) {
  49. //一周内
  50. strPassTime = Math.floor(pass / 1000 / 3600 / 24) + "天前";
  51. } else if (pass < 3600 * 24 * 30 * 1000) {
  52. //一个月内
  53. strPassTime = Math.floor(pass / 1000 / 3600 / 24 / 7) + "周前";
  54. } else {
  55. //超过一个月
  56. strPassTime = Math.floor(pass / 1000 / 3600 / 24 / 30) + "月前";
  57. }
  58. if (iterator.userinfo.username == getCookie("username")) {
  59. html += "<div class=''>You</div>";
  60. } else {
  61. html += "<div class=''>" + iterator.userinfo.nickname + "</div>";
  62. }
  63. html += "<div class=''>" + strPassTime + "</div>";
  64. html += "<div class=''>" + iterator.text + "</div>";
  65. }
  66. $("#sent_history_content").html(html);
  67. $("#sent_history_dlg").dialog("open");
  68. } else {
  69. ntf_show(result.error);
  70. }
  71. }
  72. );
  73. }