historay.js 1.9 KB

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