index_mydoc.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. var my_file_title = "";
  2. var my_file_status = "all"; //recycle
  3. var my_file_order = "DESC"; //ASC
  4. function file_search_keyup() {
  5. file_list_refresh();
  6. }
  7. function recycleInit() {
  8. ntf_init();
  9. file_list_refresh();
  10. }
  11. function indexInit() {
  12. ntf_init();
  13. file_list_refresh();
  14. }
  15. function time_standardize(date) {
  16. var today_date = new Date();
  17. var Local_time = date.toLocaleTimeString();
  18. //將時間去掉秒的信息
  19. if (Local_time && Local_time.split(":").length == 3) {
  20. var Local_time_string = Local_time.split(":")[0] + ":" + Local_time.split(":")[1];
  21. Local_time_string += Local_time.split(":")[2].slice(2);
  22. } else {
  23. var Local_time_string = d.toLocaleTimeString();
  24. }
  25. if (date.toLocaleDateString() == today_date.toLocaleDateString()) {
  26. //如果是今天的消息,只显示时间
  27. return Local_time_string;
  28. } else if (date.toLocaleDateString().slice(0, 5) == today_date.toLocaleDateString().slice(0, 5)) {
  29. //如果是今年但非今天的消息,只显示月日
  30. var date_length = date.toLocaleDateString().length;
  31. return date.toLocaleDateString().slice(5, date_length);
  32. } else {
  33. //如果不是今年的消息,显示年月日
  34. return date.toLocaleDateString();
  35. }
  36. }
  37. //显示最近查看列表
  38. function file_list_refresh() {
  39. var d = new Date();
  40. $.get(
  41. "getfilelist.php",
  42. {
  43. t: d.getTime(),
  44. keyword: my_file_title,
  45. status: $("#id_index_status").val(),
  46. orderby: "accese_time",
  47. order: "DESC",
  48. currLanguage: $("#id_language").val(),
  49. },
  50. function (data, status) {
  51. try {
  52. let file_list = JSON.parse(data);
  53. let html = "";
  54. for (x in file_list) {
  55. html += '<div class="file_list_row">';
  56. html += '<div class="file_list_col_1">';
  57. html += "<input id='file_check_" + x + '\' type="checkbox" />';
  58. html += "<input id='file_id_" + x + "' value='" + file_list[x].uid + '\' type="hidden" />';
  59. html += "</div>";
  60. html += '<div class="file_list_col_2">';
  61. if (
  62. (file_list[x].parent_id == null || file_list[x].parent_id == "") &&
  63. parseInt(file_list[x].share) == 1
  64. ) {
  65. //shared
  66. html += "<span onclick=\"file_show_coop_win('" + file_list[x].uid + "')\">";
  67. } else {
  68. html += "<span>";
  69. }
  70. html += "<svg class='icon' style='margin: 0 5px;'>";
  71. if (file_list[x].parent_id == null || file_list[x].parent_id == "") {
  72. if (parseInt(file_list[x].share) == 1) {
  73. //shared
  74. html += '<use xlink:href="./svg/icon.svg#share_to_other"></use>';
  75. } else {
  76. //my document
  77. html += '<use xlink:href="./svg/icon.svg#ic_person"></use>';
  78. }
  79. } else {
  80. //fork
  81. html += '<use xlink:href="./svg/icon.svg#other_share_to_me"></use>';
  82. }
  83. html += "</svg>";
  84. html += "</span>";
  85. html += "<div id='coop_show_" + file_list[x].uid + "' style='display:inline;'></div>";
  86. let $link;
  87. if (file_list[x].doc_info && file_list[x].doc_info.length > 1) {
  88. $link = "<a href='./editor.php?op=opendb&fileid=" + file_list[x].uid + "' target='_blank'>";
  89. } else {
  90. $link = "<a href='./editor.php?op=open&fileid=" + file_list[x].uid + "' target='_blank'>";
  91. }
  92. html += $link + "<span id='title_" + file_list[x].uid + "'>" + file_list[x].title;
  93. html += "</span></a>";
  94. //html +="<input type='input' style='diaplay:none;' id='input_title_"+file_list[x].id+"' value='"+file_list[x].title+"' />"
  95. html += '<span class="icon_btn_div hidden_function">';
  96. html +=
  97. '<span class="icon_btn_tip" style="margin-top: 0.7em;margin-left: 2.5em;">' +
  98. gLocal.gui.rename +
  99. "</span>";
  100. html +=
  101. "<button id='edit_title' type='button' class='icon_btn' onclick=\"title_change('" +
  102. file_list[x].uid +
  103. "','" +
  104. file_list[x].title +
  105. "')\" >";
  106. html += ' <svg class="icon">';
  107. html += ' <use xlink:href="./svg/icon.svg#ic_rename"></use>';
  108. html += " </svg>";
  109. html += "</button>";
  110. html += "</span> ";
  111. html += "</div>";
  112. html += '<div class="file_list_col_3">';
  113. if (
  114. (file_list[x].parent_id && file_list[x].parent_id.length > 10) ||
  115. parseInt(file_list[x].share) == 1
  116. ) {
  117. html += "<svg class='icon'>";
  118. html += '<use xlink:href="./svg/icon.svg#ic_two_person"></use>';
  119. html += "</svg>";
  120. }
  121. html += "</div>";
  122. html += '<div class="file_list_col_4">';
  123. let d = new Date();
  124. let today_date = d.toLocaleDateString();
  125. d.setTime(file_list[x].accese_time);
  126. let Local_time = "";
  127. Local_time = time_standardize(d);
  128. /*
  129. if(d.getHours()<=9){
  130. Local_time +=":0"+d.getHours();
  131. }
  132. else{
  133. Local_time += ":"+d.getHours();
  134. }
  135. if(d.getMinutes()<=9){
  136. Local_time +=":0"+d.getMinutes();
  137. }
  138. else{
  139. Local_time += ":"+d.getMinutes();
  140. }
  141. let Local_date = d.toLocaleDateString();
  142. if(today_date==Local_date){
  143. html += gLocal.gui.today+Local_time;
  144. }
  145. else{
  146. html += Local_date;
  147. }
  148. */
  149. html += Local_time;
  150. html += "</div>";
  151. html += '<div class="file_list_col_5">';
  152. if (file_list[x].file_size < 102) {
  153. $str_size = file_list[x].file_size + "B";
  154. } else if (file_list[x].file_size < 1024 * 902) {
  155. $str_size = (file_list[x].file_size / 1024).toFixed(0) + "KB";
  156. } else {
  157. $str_size = (file_list[x].file_size / (1024 * 1024)).toFixed(1) + "MB";
  158. }
  159. html += $str_size;
  160. if (!(file_list[x].doc_info && file_list[x].doc_info.length > 1)) {
  161. html +=
  162. "<a href='../doc/pcs2db.php?doc_id=" +
  163. file_list[x].uid +
  164. "' target='_blank'>转数据库格式</a>";
  165. }
  166. html += "</div>";
  167. html += "<div>";
  168. html += '<span class="icon_btn_div hidden_function">';
  169. html += '<span class="icon_btn_tip">' + gLocal.gui.copy_share_link + "</span>";
  170. html +=
  171. "<button id='edit_title' type='button' class='icon_btn' onclick=\"share_link_copy_to_clipboard('" +
  172. file_list[x].uid +
  173. "')\" >";
  174. //html +=' <svg class="icon">';
  175. //html +=' <use xlink:href="./svg/icon.svg#ic_rename"></use>';
  176. //html +=' </svg>';
  177. html +=
  178. '<svg t="1611985739555" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="6173" width="200" height="200"><path d="M423.198 640a83.84 83.84 0 0 1-64-28.8 259.84 259.84 0 0 1-26.88-308.48L441.118 128a261.12 261.12 0 1 1 448 272l-35.2 57.6a83.84 83.84 0 1 1-145.92-90.24l35.2-57.6a92.8 92.8 0 0 0-158.72-96.64l-107.52 176.64a92.8 92.8 0 0 0 9.6 109.44 83.84 83.84 0 0 1-64 139.52z" p-id="6174"></path><path d="M357.918 1024a261.12 261.12 0 0 1-222.72-397.44l31.36-50.56a83.84 83.84 0 1 1 144 87.68l-31.36 51.2a92.8 92.8 0 0 0 30.72 128 91.52 91.52 0 0 0 70.4 10.88 92.16 92.16 0 0 0 57.6-41.6l107.52-177.92a93.44 93.44 0 0 0-6.4-105.6 83.84 83.84 0 1 1 134.4-103.68 262.4 262.4 0 0 1 17.28 296.96L581.278 896a259.84 259.84 0 0 1-163.84 120.32 263.68 263.68 0 0 1-59.52 7.68z" p-id="6175"></path></svg>';
  179. html += "</button>";
  180. html += "</span> ";
  181. html += "</div>";
  182. html += "</div>";
  183. }
  184. html += "<input id='file_count' type='hidden' value='" + file_list.length + "'/>";
  185. $("#userfilelist").html(html);
  186. } catch (e) {
  187. console.error(e.message);
  188. }
  189. }
  190. );
  191. }
  192. function showUserFilaList() {
  193. file_list_refresh();
  194. }
  195. function title_change(id, title) {
  196. let newTitle = prompt("新的标题", title);
  197. if (newTitle) {
  198. _doc_info_title_change(id, newTitle, function (data, status) {
  199. let result = JSON.parse(data);
  200. if (result.error == false) {
  201. $("#title_" + id).text(newTitle);
  202. } else {
  203. alert(result.message);
  204. }
  205. });
  206. }
  207. }
  208. function share_link_copy_to_clipboard(id) {
  209. let host = location.protocol + '//' + location.host;
  210. copy_to_clipboard(host+"/app/studio/project.php?op=open&doc_id=" + id);
  211. }
  212. function mydoc_file_select(doSelect) {
  213. if (doSelect) {
  214. $("#file_tools").show();
  215. $("#file_filter").hide();
  216. $(".file_select_checkbox").show();
  217. $(".file_select_checkbox").css("display", "inline-block");
  218. if ($("#id_index_status").val() == "recycle") {
  219. $("#button_group_recycle").show();
  220. $("#button_group_nomal").hide();
  221. } else {
  222. $("#button_group_recycle").hide();
  223. $("#button_group_nomal").show();
  224. }
  225. } else {
  226. $("#file_tools").hide();
  227. $("#file_filter").show();
  228. $(".file_select_checkbox").hide();
  229. }
  230. }
  231. function file_del() {
  232. var file_list = new Array();
  233. var file_count = $("#file_count").val();
  234. for (var i = 0; i < file_count; i++) {
  235. if (document.getElementById("file_check_" + i).checked) {
  236. file_list.push($("#file_id_" + i).val());
  237. }
  238. }
  239. if (file_list.length > 0) {
  240. $.post(
  241. "./file_index.php",
  242. {
  243. op: "delete",
  244. file: file_list.join(),
  245. },
  246. function (data, status) {
  247. ntf_show(data);
  248. file_list_refresh();
  249. }
  250. );
  251. }
  252. }
  253. //彻底删除
  254. function file_remove() {
  255. var file_list = new Array();
  256. var file_count = $("#file_count").val();
  257. for (var i = 0; i < file_count; i++) {
  258. if (document.getElementById("file_check_" + i).checked) {
  259. file_list.push($("#file_id_" + i).val());
  260. }
  261. }
  262. if (file_list.length > 0) {
  263. $.post(
  264. "./file_index.php",
  265. {
  266. op: "remove",
  267. file: file_list.join(),
  268. },
  269. function (data, status) {
  270. ntf_show(data);
  271. file_list_refresh();
  272. }
  273. );
  274. }
  275. }
  276. //从回收站中恢复
  277. function file_restore() {
  278. var file_list = new Array();
  279. var file_count = $("#file_count").val();
  280. for (var i = 0; i < file_count; i++) {
  281. if (document.getElementById("file_check_" + i).checked) {
  282. file_list.push($("#file_id_" + i).val());
  283. }
  284. }
  285. if (file_list.length > 0) {
  286. $.post(
  287. "./file_index.php",
  288. {
  289. op: "restore",
  290. file: file_list.join(),
  291. },
  292. function (data, status) {
  293. ntf_show(data);
  294. file_list_refresh();
  295. }
  296. );
  297. }
  298. }
  299. function file_share(isShare) {
  300. var file_list = new Array();
  301. var file_count = $("#file_count").val();
  302. for (var i = 0; i < file_count; i++) {
  303. if (document.getElementById("file_check_" + i).checked) {
  304. file_list.push($("#file_id_" + i).val());
  305. }
  306. }
  307. if (file_list.length > 0) {
  308. if (isShare) {
  309. var share = 1;
  310. } else {
  311. var share = 0;
  312. }
  313. $.post(
  314. "./file_index.php",
  315. {
  316. op: "share",
  317. share: share,
  318. file: file_list.join(),
  319. },
  320. function (data, status) {
  321. alert(data);
  322. //mydoc_file_select(false);
  323. file_list_refresh();
  324. }
  325. );
  326. }
  327. }
  328. function file_show_coop_win(doc_id) {
  329. let xFileHead = document.getElementById("coop_show_" + doc_id);
  330. let xCoopWin = document.getElementById("rs_doc_coop_win");
  331. xFileHead.appendChild(xCoopWin);
  332. coop_init(doc_id, "rs_doc_coop_win_inner");
  333. coop_list();
  334. }
  335. function file_coop_win_close() {
  336. let xShell = document.getElementById("rs_doc_coop_shell");
  337. let xCoopWin = document.getElementById("rs_doc_coop_win");
  338. xShell.appendChild(xCoopWin);
  339. }