welcome.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. $(function () {
  2. fetchJSON("api/user/info", {}, "get", function (data) {
  3. if (data.code === 0) {
  4. $("#username").html(
  5. data.data.userAccount + (data.data.realName === null ? "" : " ( " + data.data.realName + " ) ")
  6. );
  7. } else {
  8. console.log(data.msg);
  9. }
  10. });
  11. setInterval(function () {
  12. var time = new Date();
  13. $("#clock").html("当前时间:" + time.toLocaleString());
  14. }, 1000);
  15. // 角色数
  16. fetchJSON("api/role/roleCount", {}, "get", function (data) {
  17. if (data.code === 0) {
  18. $("#roleCount").html(data.data);
  19. } else {
  20. console.log(data.msg);
  21. }
  22. });
  23. // 用户数
  24. fetchJSON("api/user/userCount", {}, "get", function (data) {
  25. if (data.code === 0) {
  26. $("#userCount").html(data.data);
  27. } else {
  28. console.log(data.msg);
  29. }
  30. });
  31. // 资源总数
  32. fetchJSON("api/resource/resourceCount", {}, "get", function (data) {
  33. if (data.code === 0) {
  34. $("#resourceCount").html(data.data);
  35. } else {
  36. console.log(data.msg);
  37. }
  38. });
  39. // 单位总数
  40. fetchJSON("api/resource/deptCount", {}, "get", function (data) {
  41. if (data.code === 0) {
  42. $("#deptCount").html(data.data);
  43. } else {
  44. console.log(data.msg);
  45. }
  46. });
  47. // 作者数
  48. fetchJSON("api/resource/authorCount", {}, "get", function (data) {
  49. if (data.code === 0) {
  50. $("#authorCount").html(data.data);
  51. } else {
  52. console.log(data.msg);
  53. }
  54. });
  55. $("a").on("click", function (e) {
  56. var index = parseInt($(this).attr("data-index"));
  57. var title = $(this).attr("data-title");
  58. var url = $(this).attr("data-url");
  59. if (url === "" || url === undefined || url === null) return;
  60. if (index !== null && index !== undefined && !isNaN(index)) {
  61. e.preventDefault();
  62. var indexed = parseInt(index) + 1;
  63. for (var i = 0; i < parent.xframe.length; i++) {
  64. var tabId = parent.xframe.eq(i).attr("tab-id");
  65. if (parseInt(tabId) === parseInt(indexed)) {
  66. parent.windowTab.tabChange(parseInt(indexed));
  67. return;
  68. }
  69. }
  70. parent.windowTab.tabAdd(title, url, parseInt(indexed));
  71. parent.windowTab.tabChange(parseInt(indexed));
  72. }
  73. });
  74. layui.use(['upload', 'layer'], function () {
  75. var upload = layui.upload;
  76. var layer = layui.layer;
  77. var uploadInst = upload.render({
  78. elem: '#loadWordFile',
  79. accept: 'file',
  80. exts: 'txt',
  81. auto: false,
  82. choose: function (obj) {
  83. obj.preview(function (index, file, result) {
  84. var fileReader = new FileReader();
  85. fileReader.readAsText(file);
  86. fileReader.onload = function () {
  87. $("#wordList").val(this.result);
  88. };
  89. });
  90. }
  91. });
  92. $('#restoreES').on('click', function () {
  93. if ($("#curlCMD").val().trim() === "") {
  94. layer.msg("使用默认恢复命令!", {time: 5000});
  95. }
  96. var content = $('#curlCMD').val().trim();
  97. fetchJSON("/restoreES?data="+content,
  98. {},
  99. "post",
  100. function (ret) {
  101. if (ret.code === 0) {
  102. if (ret.data.length < 50)
  103. layer.msg("成功", {time: 5000});
  104. else
  105. layer.msg(ret.data, {time: 5000});
  106. }
  107. })
  108. });
  109. $('#restoreDB').on('click', function () {
  110. fetchJSON("/restoreDB",
  111. {},
  112. "post",
  113. function (ret) {
  114. if (ret.code === 0) {
  115. if (ret.data.length < 20)
  116. layer.msg(ret.data, {time: 5000});
  117. else
  118. layer.msg(ret.data, {time: 5000});
  119. }
  120. })
  121. });
  122. $('#saveWordFile').on('click', function () {
  123. if ($("#wordList").val().trim() === "") {
  124. layer.msg("待上传分词库内容为空。请先载入分词库文件,或在下面输入框中输入需要上传的分词。每行一词。", {time: 5000});
  125. return;
  126. }
  127. var content = $('#wordList').val().trim().split('\n');
  128. fetchJSON("/uploadWordFile",
  129. content,
  130. "post",
  131. function (ret) {
  132. if (ret.code === 0) {
  133. layer.msg('上传成功');
  134. } else {
  135. layer.msg('上传失败: ' + ret.msg, {time: 5000});
  136. }
  137. })
  138. });
  139. $('#failure').on('click', function (e) {
  140. window.open('failure.html');
  141. });
  142. var intervalId;
  143. $('#checkDataIntegrity').on('click', function (e) {
  144. $('#checkDataInfo').css('display', 'inline');
  145. $('#checkDataIntegrity').addClass('layui-btn-disabled');
  146. intervalId = setInterval(function () {
  147. fetchJSON("/getCheckDataProgress", {}, "post", function (ret) {
  148. $('#checkDataInfo').html('正在检查...' + ((ret.data > 1 ? 1 : ret.data) * 100).toFixed(2) + "%");
  149. console.log(ret.data);
  150. });
  151. }, 1000);
  152. fetchJSON("/checkDataIntegrity", {}, "post", function (ret) {
  153. if (ret.code === 0) {
  154. clearInterval(intervalId);
  155. layer.msg('数据完整性检查完成');
  156. $('#checkDataInfo').html('检查成功');
  157. $('#checkDataIntegrity').removeClass('layui-btn-disabled');
  158. } else if (ret.code === 8) {
  159. clearInterval(intervalId);
  160. intervalId = setInterval(function () {
  161. fetchJSON("/getCheckDataProgress", {}, "post", function (ret) {
  162. $('#checkDataInfo').html('正在检查...' + ((ret.data > 1 ? 1 : ret.data) * 100).toFixed(2) + "%");
  163. console.log(ret.data);
  164. if (ret.data >= 1) {
  165. clearInterval(intervalId);
  166. layer.msg('数据完整性检查完成');
  167. $('#checkDataIntegrity').removeClass('layui-btn-disabled');
  168. }
  169. });
  170. }, 1000);
  171. } else {
  172. clearInterval(intervalId);
  173. layer.msg('数据完整性检查发生错误: ' + ret.msg, {time: 5000});
  174. $('#checkDataInfo').html('检查失败: ' + ret.msg);
  175. $('#checkDataIntegrity').removeClass('layui-btn-disabled');
  176. }
  177. });
  178. })
  179. });
  180. });