| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- 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 = "<option value='self'>自定义角色</option>"
- if (res) {
- res += str
- $('#role-select').html(res).select2({ minimumResultsForSearch: -1 });
- } else {
- $('#role-select').html(str).select2({ minimumResultsForSearch: -1 });
- }
- }
- });
- }
- function getRunningScene() {
- $('.scene-box').html(`<div class="loading">加载中...</div>`)
- $.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 += `<div class="scene vb-btn ${active}" data-no="${item.id}" data-path="${item.path}" data-name="${item.name}" onclick="changeScene(this)">${item.name}</div>`
- }
- $('.scene-box').html(str);
- } else {
- $('.scene-box').html(`<div class="end">本轮演练已结束</div>`);
- $(".log-cmd-box #log-box").html("<div class='end'>本轮演练已结束</div>");
- }
- }
- 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(`<div class="loading">加载中...</div>`)
- $.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 += `<div class="tip" onclick="SelectTip(this)">${item.content}</div>`
- }
- $('.tip-box .tip-body').html(str);
- } else {
- $('.tip-box .tip-body').html(`<div class="empty">暂无提示</div>`);
- }
- }
- 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);
- }
|