welcome.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. var content = $('#cmdString').val().trim().split('\n');
  94. if (content === "") {
  95. layer.msg("使用默认命令", {time: 5000});
  96. }
  97. fetchJSON("/restoreES",
  98. content,
  99. "post",
  100. function (ret) {
  101. layer.msg(ret.data, {time: 5000});
  102. })
  103. });
  104. $('#saveWordFile').on('click', function () {
  105. if ($("#wordList").val().trim() === "") {
  106. layer.msg("待上传分词库内容为空。请先载入分词库文件,或在下面输入框中输入需要上传的分词。每行一词。", {time: 5000});
  107. return;
  108. }
  109. var content = $('#wordList').val().trim().split('\n');
  110. fetchJSON("/uploadWordFile",
  111. content,
  112. "post",
  113. function (ret) {
  114. if (ret.code === 0) {
  115. layer.msg('上传成功');
  116. } else {
  117. layer.msg('上传失败: ' + ret.msg, {time: 5000});
  118. }
  119. })
  120. });
  121. $('#failure').on('click', function (e) {
  122. window.open('failure.html');
  123. });
  124. var intervalId;
  125. $('#checkDataIntegrity').on('click', function (e) {
  126. $('#checkDataInfo').css('display', 'inline');
  127. $('#checkDataIntegrity').addClass('layui-btn-disabled');
  128. intervalId = setInterval(function () {
  129. fetchJSON("/getCheckDataProgress", {}, "post", function (ret) {
  130. $('#checkDataInfo').html('正在检查...' + ((ret.data > 1 ? 1 : ret.data) * 100).toFixed(2) + "%");
  131. console.log(ret.data);
  132. });
  133. }, 1000);
  134. fetchJSON("/checkDataIntegrity", {}, "post", function (ret) {
  135. if (ret.code === 0) {
  136. clearInterval(intervalId);
  137. layer.msg('数据完整性检查完成');
  138. $('#checkDataInfo').html('检查成功');
  139. $('#checkDataIntegrity').removeClass('layui-btn-disabled');
  140. } else if (ret.code === 8) {
  141. clearInterval(intervalId);
  142. intervalId = setInterval(function () {
  143. fetchJSON("/getCheckDataProgress", {}, "post", function (ret) {
  144. $('#checkDataInfo').html('正在检查...' + ((ret.data > 1 ? 1 : ret.data) * 100).toFixed(2) + "%");
  145. console.log(ret.data);
  146. if (ret.data >= 1) {
  147. clearInterval(intervalId);
  148. layer.msg('数据完整性检查完成');
  149. $('#checkDataIntegrity').removeClass('layui-btn-disabled');
  150. }
  151. });
  152. }, 1000);
  153. } else {
  154. clearInterval(intervalId);
  155. layer.msg('数据完整性检查发生错误: ' + ret.msg, {time: 5000});
  156. $('#checkDataInfo').html('检查失败: ' + ret.msg);
  157. $('#checkDataIntegrity').removeClass('layui-btn-disabled');
  158. }
  159. });
  160. })
  161. });
  162. });