my_article.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. var _display = "para";
  2. var share_win;
  3. function my_article_init() {
  4. my_article_list();
  5. share_win = iframe_win_init({ container: "share_win", name: "share", width: "500px" });
  6. article_add_dlg_init("article_add_div");
  7. }
  8. function my_article_list() {
  9. $.get(
  10. "../article/list.php",
  11. {
  12. userid: getCookie("userid"),
  13. setting: "",
  14. },
  15. function (data, status) {
  16. if (status == "success") {
  17. try {
  18. let html = "";
  19. let result = JSON.parse(data);
  20. let key = 1;
  21. //表头
  22. html += '<div class="file_list_row" style="padding:5px;">';
  23. html += '<div style="max-width:2em;flex:1;"><input type="checkbox" /></div>';
  24. html += "<div style='flex:0.5;'>" + key++ + "</div>";
  25. html += "<div style='flex:2;'>" + gLocal.gui.title + "</div>";
  26. html += "<div style='flex:2;'>" + gLocal.gui.privacy + "</div>";
  27. html += "<div style='flex:1;'>" + gLocal.gui.copy_link + "</div>";
  28. html += "<div style='flex:1;'>" + gLocal.gui.edit + "</a></div>";
  29. html += "<div style='flex:1;'>" + gLocal.gui.preview + "</a></div>";
  30. html += "<div style='flex:1;'></div>";
  31. html += "</div>";
  32. //列表
  33. for (const iterator of result) {
  34. html += '<div class="file_list_row" style="padding:5px;">';
  35. html += '<div style="max-width:2em;flex:1;"><input type="checkbox" /></div>';
  36. html += "<div style='flex:0.5;'>" + key++ + "</div>";
  37. html += "<div style='flex:2;'>" + iterator.title + "</div>";
  38. html += "<div style='flex:2;'>" + render_status(iterator.status) + "</div>";
  39. html += "<div style='flex:1;'>" + gLocal.gui.copy_link + "</div>";
  40. html +=
  41. "<div style='flex:1;'><a href='../article/my_article_edit.php?id=" +
  42. iterator.id +
  43. "'>" +
  44. gLocal.gui.edit +
  45. "</a></div>";
  46. html +=
  47. "<div style='flex:1;'><a href='../article/?id=" +
  48. iterator.id +
  49. "' target='_blank'>" +
  50. gLocal.gui.preview +
  51. "</a></div>";
  52. html += "<div style='flex:1;'>";
  53. html += "<a onclick=\"article_share('" + iterator.id + "')\">share</a>";
  54. html += "</div>";
  55. html += "</div>";
  56. }
  57. $("#article_list").html(html);
  58. } catch (e) {
  59. console.error(e);
  60. }
  61. } else {
  62. console.error("ajex error");
  63. }
  64. }
  65. );
  66. }
  67. function article_share(id) {
  68. share_win.show("../share/share.php?id=" + id + "&type=3");
  69. }
  70. function render_status(status) {
  71. status = parseInt(status);
  72. let html = "";
  73. let objStatus = [
  74. {
  75. id: 1,
  76. name:
  77. "<svg class='icon'><use xlink:href='../studio/svg/icon.svg#ic_lock'></use></svg>" + gLocal.gui.private,
  78. tip: gLocal.gui.private_note,
  79. },
  80. {
  81. id: 2,
  82. name:
  83. "<svg class='icon'><use xlink:href='../studio/svg/icon.svg#eye_disable'></use></svg>" +
  84. gLocal.gui.unlisted,
  85. tip: gLocal.gui.unlisted_note,
  86. },
  87. {
  88. id: 3,
  89. name:
  90. "<svg class='icon'><use xlink:href='../studio/svg/icon.svg#eye_enable'></use></svg>" +
  91. gLocal.gui.public,
  92. tip: gLocal.gui.public_note,
  93. },
  94. ];
  95. html += '<div class="case_dropdown" style="flex:7;">';
  96. html += '<input type="hidden" name="status" value ="' + status + '" />';
  97. for (const iterator of objStatus) {
  98. if (iterator.id == status) {
  99. html += "<div >" + iterator.name + "</div>";
  100. }
  101. }
  102. html +=
  103. '<div id="privacy_list" class="case_dropdown-content" style="background-color: var(--detail-color); color: var(--btn-color);">';
  104. for (const iterator of objStatus) {
  105. let active = "";
  106. if (iterator.id == status) {
  107. active = "active";
  108. }
  109. html += "<a class='" + active + "' onclick='setStatus(this)'>";
  110. html += "<div style='font-size:110%'>" + iterator.name + "</div>";
  111. html += "<div style='font-size:80%'>" + iterator.tip + "</div>";
  112. html += "</a>";
  113. }
  114. html += "</div></div>";
  115. return html;
  116. }
  117. function setStatus(obj) {}
  118. function my_article_edit(id) {
  119. $.get(
  120. "../article/get.php",
  121. {
  122. id: id,
  123. setting: "",
  124. },
  125. function (data, status) {
  126. if (status == "success") {
  127. try {
  128. let html = "";
  129. let result = JSON.parse(data);
  130. $("#article_collect").attr("a_id", result.id);
  131. html += "<div style='display:flex;'>";
  132. html += "<div style='flex:4;'>";
  133. html += '<div class="" style="padding:5px;">';
  134. html += '<div style="max-width:2em;flex:1;"></div>';
  135. html += "<input type='hidden' name='id' value='" + result.id + "'/>";
  136. html += "<input type='hidden' name='tag' value='" + result.tag + "'/>";
  137. html += "<input type='hidden' name='status' value='" + result.status + "'/>";
  138. html += "<input type='checkbox' name='import' />" + gLocal.gui.import + gLocal.gui.text;
  139. html += "<div>";
  140. //html += "<div id='article_collect' vui='collect-dlg' ></div>"
  141. html += "<div style='display:flex;'>";
  142. html += "<span style='flex:3;margin:auto;'>" + gLocal.gui.title + "</span>";
  143. html += '<span id="article_title" style="flex:7;"></span></div>';
  144. html += "<div id='channal_selector' form_name='channal' style='display:none;'></div>";
  145. html += "<div id='aritcle_status' style='display: flex; '></div>";
  146. html +=
  147. '<div style="display:none;width:100%;" ><span style="flex:3;margin: auto;">' +
  148. gLocal.gui.language_select +
  149. '</span> <input id="article_lang_select" style="flex:7;width:100%;" type="input" onchange="article_lang_change()" placeholder="' +
  150. gLocal.gui.input +
  151. " & " +
  152. gLocal.gui.language_select +
  153. "," +
  154. gLocal.gui.example +
  155. ':Engilish" code="' +
  156. result.lang +
  157. '" value="' +
  158. result.lang +
  159. '" > <input id="article_lang" type="hidden" name="lang" value=""></div>';
  160. html += "<div style='display:flex;'>";
  161. html += "<span style='flex:3;margin:auto;'>" + gLocal.gui.introduction + "</span>";
  162. html += "<textarea style='flex:7;' name='summary' >" + result.summary + "</textarea></div>";
  163. html += "</div>";
  164. html += "</div>";
  165. html +=
  166. "<textarea id='article_content' name='content' style='height:500px;max-height: 40vh;'>" +
  167. result.content +
  168. "</textarea>";
  169. html += "</div>";
  170. html += "<div id='preview_div'>";
  171. html += "<div id='preview_inner' ></div>";
  172. html += "</div>";
  173. html += "</div>";
  174. $("#article_list").html(html);
  175. channal_select_init("channal_selector");
  176. tran_lang_select_init("article_lang_select");
  177. $("#aritcle_status").html(render_status(result.status));
  178. let html_title =
  179. "<input id='input_article_title' type='input' name='title' value='" + result.title + "' />";
  180. $("#article_title").html(html_title);
  181. $("#preview_inner").html(note_init(result.content));
  182. note_refresh_new();
  183. add_to_collect_dlg_init();
  184. } catch (e) {
  185. console.error(e);
  186. }
  187. } else {
  188. console.error("ajex error");
  189. }
  190. }
  191. );
  192. }
  193. function article_lang_change() {
  194. let lang = $("#article_lang_select").val();
  195. if (lang.split("-").length == 3) {
  196. $("#article_lang").val(lang.split("_")[2]);
  197. } else {
  198. $("#article_lang").val(lang);
  199. }
  200. }
  201. function article_preview() {
  202. $("#preview_inner").html(note_init($("#article_content").val()));
  203. note_refresh_new();
  204. }
  205. function my_article_save() {
  206. $.ajax({
  207. type: "POST", //方法类型
  208. dataType: "json", //预期服务器返回的数据类型
  209. url: "../article/my_article_post.php", //url
  210. data: $("#article_edit").serialize(),
  211. success: function (result) {
  212. console.log(result); //打印服务端返回的数据(调试用)
  213. if (result.status == 0) {
  214. alert(gLocal.gui.saved + gLocal.gui.successful);
  215. } else {
  216. alert("error:" + result.message);
  217. }
  218. },
  219. error: function (data, status) {
  220. alert("异常!" + data.responseText);
  221. switch (status) {
  222. case "timeout":
  223. break;
  224. case "error":
  225. break;
  226. case "notmodified":
  227. break;
  228. case "parsererror":
  229. break;
  230. default:
  231. break;
  232. }
  233. },
  234. });
  235. }
  236. function course_validate_required(field, alerttxt) {
  237. with (field) {
  238. if (value == null || value == "") {
  239. alert(alerttxt);
  240. return false;
  241. } else {
  242. return true;
  243. }
  244. }
  245. }
  246. function course_validate_form(thisform) {
  247. with (thisform) {
  248. if (course_validate_required(title, gLocal.gui.title_necessary + "!") == false) {
  249. title.focus();
  250. return false;
  251. }
  252. }
  253. }