stu-cmd.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. var tipShow = false, __campNo, __groupNo, __enabeTip = true, __roleHandleApi;
  2. $(function () {
  3. resizeHeight_Cmd();
  4. window.addEventListener('resize', resizeHeight_Cmd);
  5. getGroupRole();
  6. getRunningScene();
  7. bindTxtChange();
  8. });
  9. function setCampGroup(campNo, groupNo, enableTip, roleHandleApi) {
  10. __campNo = campNo;
  11. __groupNo = groupNo;
  12. __enabeTip = enableTip;
  13. __roleHandleApi = roleHandleApi;
  14. }
  15. function getGroupRole() {
  16. $.iwbAjax4({
  17. url: abp.appUrl + `Query/GetGroupRoleSelectStr?no=${__groupNo}`,
  18. success: function (res) {
  19. var str = "<option value='self'>自定义角色</option>"
  20. if (res) {
  21. res += str
  22. $('#role-select').html(res).select2({ minimumResultsForSearch: -1 });
  23. } else {
  24. $('#role-select').html(str).select2({ minimumResultsForSearch: -1 });
  25. }
  26. }
  27. });
  28. }
  29. function getRunningScene() {
  30. $('.scene-box').html(`<div class="loading">加载中...</div>`)
  31. $.iwbAjax5({
  32. url: abp.appUrl + `Query/GetGroupRunningScenes?no=${__groupNo}`,
  33. success: function (res) {
  34. formateRunningScene(res);
  35. resizeHeight_Cmd();
  36. }
  37. });
  38. }
  39. function formateRunningScene(data) {
  40. $('.scene-box').empty()
  41. if (data && data.length) {
  42. var str = "";
  43. for (var i = 0; i < data.length; i++) {
  44. var item = data[i];
  45. var active = i == 0 ? "active" : "";
  46. str += `<div class="scene vb-btn ${active}" data-no="${item.id}" data-path="${item.path}" data-name="${item.name}" onclick="changeScene(this)">${item.name}</div>`
  47. }
  48. $('.scene-box').html(str);
  49. } else {
  50. $('.scene-box').html(`<div class="end">本轮演练已结束</div>`);
  51. $(".log-cmd-box #log-box").html("<div class='end'>本轮演练已结束</div>");
  52. }
  53. }
  54. function changeScene(that) {
  55. $(that).closest(".scene-box").find(".scene").removeClass("active");
  56. $(that).addClass("active");
  57. GetTipInfo();
  58. }
  59. function ShowTips(that) {
  60. if (tipShow) {
  61. $(that).removeClass("close-tip").text("打开辅助提示");
  62. $(".tip-box").removeClass("show");
  63. } else {
  64. $(that).addClass("close-tip").text("关闭辅助提示");
  65. $(".tip-box").addClass("show");
  66. }
  67. tipShow = !tipShow;
  68. GetTipInfo();
  69. }
  70. function GetTipInfo() {
  71. if (!__enabeTip) {
  72. return;
  73. }
  74. if (!tipShow) {
  75. return;
  76. }
  77. var role = $(".role-box .form-control[name='role']").val()
  78. if (!role || role == "self") {
  79. return;
  80. }
  81. var sceneNo = $(".scene-box .scene.active").data("no");
  82. if (!sceneNo) {
  83. return;
  84. }
  85. $('.tip-box tip-body').html(`<div class="loading">加载中...</div>`)
  86. $.iwbAjax4({
  87. url: abp.appUrl + `Query/GetStuTipsByRoleScene?campNo=${__campNo}&sceneNo=${sceneNo}&roleName=${role}`,
  88. success: function (res) {
  89. formateTips(res);
  90. }
  91. });
  92. }
  93. function formateTips(data) {
  94. $('.tip-box tip-body').empty()
  95. if (data && data.length) {
  96. var str = "";
  97. for (var i = 0; i < data.length; i++) {
  98. var item = data[i];
  99. str += `<div class="tip" onclick="SelectTip(this)">${item.content}</div>`
  100. }
  101. $('.tip-box .tip-body').html(str);
  102. } else {
  103. $('.tip-box .tip-body').html(`<div class="empty">暂无提示</div>`);
  104. }
  105. }
  106. function SelectTip(that) {
  107. $(that).closest(".tip-body").find(".tip").removeClass("active");
  108. $(that).addClass("active");
  109. var text = $(that).text()
  110. if (text) {
  111. var $txt = $(that).closest('.cmd-form').find('.cmd-box .txt');
  112. text = $txt.val() + text;
  113. if (text.length < 500) {
  114. $txt.val(text);
  115. } else {
  116. abp.message.warn('指令输入不超过500字符。');
  117. }
  118. }
  119. }
  120. function bindTxtChange() {
  121. $('.cmd-form .txt').keydown(function (e) {
  122. var theEvent = window.event || e;
  123. var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
  124. if (code == 13) {
  125. RoleHandle(this);
  126. }
  127. });
  128. }
  129. function RoleHandle(that) {
  130. var $that = $(that).closest('.cmd-form'),
  131. role = $that.find('.form-control[name="role"]').val(),
  132. logId = $that.find('.form-control[name="id"]').val() || "",
  133. word = $that.find('textarea').val();
  134. if (!role) {
  135. abp.message.warn('请选择角色后再提交!');
  136. return;
  137. }
  138. if (role == 'self') {
  139. role = $that.find('.form-control[name="self-role"]').val()
  140. if (!role) {
  141. abp.message.warn('请填写角色后再提交!');
  142. return;
  143. }
  144. }
  145. if (!word) {
  146. abp.message.warn('请输入指令后再提交!');
  147. return;
  148. }
  149. if (word.length >= 500) {
  150. abp.message.warn('指令输入不超过500字符。');
  151. return;
  152. }
  153. var scenePath = $(".scene-box .scene.active").data("path");
  154. var sceneName = $(".scene-box .scene.active").data("name");
  155. if (!scenePath) {
  156. abp.message.warn('未选择情景!');
  157. return;
  158. }
  159. $.iwbAjax4({
  160. url: abp.appUrl + `Eval/${__roleHandleApi}`,
  161. data: { groupNo: __groupNo, behaviorRole: role, behaviorWord: word, logId: logId, scenePath: scenePath, sceneName: sceneName },
  162. success: function () {
  163. $that.find('textarea').val('').focus();
  164. if (logId && UpdateSuccessCallBack) {
  165. UpdateSuccessCallBack(logId);
  166. }
  167. }
  168. });
  169. }
  170. var refreshTimer;
  171. function RefeshRunningScene(isNow) {
  172. clearTimeout(refreshTimer);
  173. if (isNow) {
  174. getRunningScene();
  175. return;
  176. }
  177. refreshTimer = setTimeout(function () {
  178. //console.log('RefeshRunningScene');
  179. getRunningScene();
  180. }, 3000);
  181. }