my_article.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. function my_article_list() {
  2. $.get(
  3. "../article/list.php",
  4. {
  5. userid: getCookie("userid"),
  6. setting: "",
  7. },
  8. function (data, status) {
  9. if (status == "success") {
  10. try {
  11. let html = "";
  12. let result = JSON.parse(data);
  13. let key = 1;
  14. for (const iterator of result) {
  15. html += '<div class="file_list_row" style="padding:5px;">';
  16. html +=
  17. '<div style="max-width:2em;flex:1;"><input type="checkbox" /></div>';
  18. html += "<div style='flex:1;'>" + key++ + "</div>";
  19. html += "<div style='flex:2;'>" + iterator.title + "</div>";
  20. html +=
  21. "<div style='flex:2;'>" +
  22. render_status(iterator.status) +
  23. "</div>";
  24. html += "<div style='flex:1;'>Copy Link</div>";
  25. html +=
  26. "<div style='flex:1;'><a href='../article/my_article_edit.php?id=" +
  27. iterator.id +
  28. "'>Edit</a></div>";
  29. html +=
  30. "<div style='flex:1;'><a href='../article/?id=" +
  31. iterator.id +
  32. "' target='_blank'>Preview</a></div>";
  33. html += "<div style='flex:1;'>15</div>";
  34. html += "</div>";
  35. }
  36. $("#article_list").html(html);
  37. } catch (e) {
  38. console.error(e);
  39. }
  40. } else {
  41. console.error("ajex error");
  42. }
  43. }
  44. );
  45. }
  46. function render_status(status) {
  47. status = parseInt(status);
  48. let html = "";
  49. let objStatus = [
  50. { id: 1, name: "私有", tip: "仅自己可见" },
  51. { id: 2, name: "不公开列出", tip: "不能被搜索到,只能通过链接访问" },
  52. { id: 3, name: "公开", tip: "所有人均可看到" },
  53. ];
  54. html += '<div class="case_dropdown">';
  55. for (const iterator of objStatus) {
  56. if (iterator.id == status) {
  57. html += "<div >" + iterator.name + "</div>";
  58. }
  59. }
  60. html += '<div class="case_dropdown-content">';
  61. for (const iterator of objStatus) {
  62. let active = "";
  63. if (iterator.id == status) {
  64. active = "active";
  65. }
  66. html += "<a class='" + active + "' onclick='setStatus()'>";
  67. html += "<div style='font-size:110%'>" + iterator.name + "</div>";
  68. html += "<div style='font-size:80%'>" + iterator.tip + "</div>";
  69. html += "</a>";
  70. }
  71. html += "</div></div>";
  72. return html;
  73. }
  74. function my_article_edit(id) {
  75. $.get(
  76. "../article/get.php",
  77. {
  78. id: id,
  79. setting: "",
  80. },
  81. function (data, status) {
  82. if (status == "success") {
  83. try {
  84. let html = "";
  85. let result = JSON.parse(data);
  86. html += '<div class="" style="padding:5px;">';
  87. html += '<div style="max-width:2em;flex:1;"></div>';
  88. html += "<div style='flex:2;'>" + result.title + "</div>";
  89. html +=
  90. "<div style='flex:2;'>" + render_status(result.status) + "</div>";
  91. html += "<div style='flex:1;'>Copy Link</div>";
  92. html +=
  93. "<div style='flex:1;'><a href='../article/my_article_edit.php?id=" +
  94. result.id +
  95. "'>Edit</a></div>";
  96. html +=
  97. "<div style='flex:1;'><a href='../article/?id=" +
  98. result.id +
  99. "' target='_blank'>Preview</a></div>";
  100. html += "<div style='flex:1;'>15</div>";
  101. html += "</div>";
  102. html += "<div style='display:flex;'>";
  103. html += "<div style='flex:5;'>";
  104. html +=
  105. "<textarea style='height:500px;'>" + result.content + "</textarea>";
  106. html += "</div>";
  107. html += "<div style='flex:5;'>";
  108. html += "</div>";
  109. html += "</div>";
  110. $("#article_list").html(html);
  111. } catch (e) {
  112. console.error(e);
  113. }
  114. } else {
  115. console.error("ajex error");
  116. }
  117. }
  118. );
  119. }