var tipShow = false, __campNo, __groupNo, __enabeTip = true, __roleHandleApi; $(function () { resizeHeight_Cmd(); window.addEventListener('resize', resizeHeight_Cmd); getGroupRole(); getRunningScene(); bindTxtChange(); }); function setCampGroup(campNo, groupNo, enableTip, roleHandleApi) { __campNo = campNo; __groupNo = groupNo; __enabeTip = enableTip; __roleHandleApi = roleHandleApi; } function getGroupRole() { $.iwbAjax4({ url: abp.appUrl + `Query/GetGroupRoleSelectStr?no=${__groupNo}`, success: function (res) { var str = "" if (res) { res += str $('#role-select').html(res).select2({ minimumResultsForSearch: -1 }); } else { $('#role-select').html(str).select2({ minimumResultsForSearch: -1 }); } } }); } function getRunningScene() { $('.scene-box').html(`
加载中...
`) $.iwbAjax5({ url: abp.appUrl + `Query/GetGroupRunningScenes?no=${__groupNo}`, success: function (res) { formateRunningScene(res); resizeHeight_Cmd(); } }); } function formateRunningScene(data) { $('.scene-box').empty() if (data && data.length) { var str = ""; for (var i = 0; i < data.length; i++) { var item = data[i]; var active = i == 0 ? "active" : ""; str += `
${item.name}
` } $('.scene-box').html(str); } else { $('.scene-box').html(`
本轮演练已结束
`); $(".log-cmd-box #log-box").html("
本轮演练已结束
"); } } function changeScene(that) { $(that).closest(".scene-box").find(".scene").removeClass("active"); $(that).addClass("active"); GetTipInfo(); } function ShowTips(that) { if (tipShow) { $(that).removeClass("close-tip").text("打开辅助提示"); $(".tip-box").removeClass("show"); } else { $(that).addClass("close-tip").text("关闭辅助提示"); $(".tip-box").addClass("show"); } tipShow = !tipShow; GetTipInfo(); } function GetTipInfo() { if (!__enabeTip) { return; } if (!tipShow) { return; } var role = $(".role-box .form-control[name='role']").val() if (!role || role == "self") { return; } var sceneNo = $(".scene-box .scene.active").data("no"); if (!sceneNo) { return; } $('.tip-box tip-body').html(`
加载中...
`) $.iwbAjax4({ url: abp.appUrl + `Query/GetStuTipsByRoleScene?campNo=${__campNo}&sceneNo=${sceneNo}&roleName=${role}`, success: function (res) { formateTips(res); } }); } function formateTips(data) { $('.tip-box tip-body').empty() if (data && data.length) { var str = ""; for (var i = 0; i < data.length; i++) { var item = data[i]; str += `
${item.content}
` } $('.tip-box .tip-body').html(str); } else { $('.tip-box .tip-body').html(`
暂无提示
`); } } function SelectTip(that) { $(that).closest(".tip-body").find(".tip").removeClass("active"); $(that).addClass("active"); var text = $(that).text() if (text) { var $txt = $(that).closest('.cmd-form').find('.cmd-box .txt'); text = $txt.val() + text; if (text.length < 500) { $txt.val(text); } else { abp.message.warn('指令输入不超过500字符。'); } } } function bindTxtChange() { $('.cmd-form .txt').keydown(function (e) { var theEvent = window.event || e; var code = theEvent.keyCode || theEvent.which || theEvent.charCode; if (code == 13) { RoleHandle(this); } }); } function RoleHandle(that) { var $that = $(that).closest('.cmd-form'), role = $that.find('.form-control[name="role"]').val(), logId = $that.find('.form-control[name="id"]').val() || "", word = $that.find('textarea').val(); if (!role) { abp.message.warn('请选择角色后再提交!'); return; } if (role == 'self') { role = $that.find('.form-control[name="self-role"]').val() if (!role) { abp.message.warn('请填写角色后再提交!'); return; } } if (!word) { abp.message.warn('请输入指令后再提交!'); return; } if (word.length >= 500) { abp.message.warn('指令输入不超过500字符。'); return; } var scenePath = $(".scene-box .scene.active").data("path"); var sceneName = $(".scene-box .scene.active").data("name"); if (!scenePath) { abp.message.warn('未选择情景!'); return; } $.iwbAjax4({ url: abp.appUrl + `Eval/${__roleHandleApi}`, data: { groupNo: __groupNo, behaviorRole: role, behaviorWord: word, logId: logId, scenePath: scenePath, sceneName: sceneName }, success: function () { $that.find('textarea').val('').focus(); if (logId && UpdateSuccessCallBack) { UpdateSuccessCallBack(logId); } } }); } var refreshTimer; function RefeshRunningScene(isNow) { clearTimeout(refreshTimer); if (isNow) { getRunningScene(); return; } refreshTimer = setTimeout(function () { //console.log('RefeshRunningScene'); getRunningScene(); }, 3000); }