_CmdSend.cshtml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. @using WeOnlineApp.Configuration
  2. @using WeOnlineApp.Helpers
  3. @model WeOnlineApp.Models.Play.CampPlayModel
  4. @{
  5. string id = "cmd-send";
  6. string roles = "";
  7. var roleArr = Model.Play.PlayRoleNames.Split(',');
  8. foreach (var role in roleArr)
  9. {
  10. roles += "<span class=\" role label label-info\" onclick=\"ChangeRole('" + role + "')\">" + role + "</span>";
  11. }
  12. Model.Play.PlayModel = CampPlayModelDefinition.Team;
  13. }
  14. <style>
  15. .cmd-box {
  16. height: 100%;
  17. }
  18. .cmd-box .tool-box {
  19. margin: 10px 0 15px;
  20. position: relative;
  21. }
  22. .cmd-box .tool-box .role {
  23. cursor: pointer;
  24. min-width: 100px;
  25. border-radius: 20px;
  26. }
  27. .cmd-box .tool-box .role-change-box {
  28. display: none;
  29. min-height: 100px;
  30. border: 1px solid var(--mc);
  31. background: #f2f6fe;
  32. position: absolute;
  33. padding: 5px 10px;
  34. bottom: calc(100% + 10px);
  35. left: -45%;
  36. right: 45%;
  37. z-index: 2;
  38. border-radius: 5px;
  39. }
  40. .cmd-box .tool-box .role-change-box .role {
  41. margin: 3px;
  42. padding: 5px 10px;
  43. font-size: 13px;
  44. color: #fff;
  45. background: var(--mc);
  46. cursor: pointer;
  47. }
  48. .cmd-box .msg-box {
  49. position: relative;
  50. height: calc(100% - 60px);
  51. }
  52. .cmd-box .msg-box span {
  53. position: absolute;
  54. bottom: 10px;
  55. right: 15px;
  56. }
  57. .cmd-box .msg-box textarea {
  58. border: 1px solid var(--mc);
  59. background: #f2f6fe;
  60. color: #3c3c3c;
  61. height: 100%;
  62. }
  63. .cmd-box .msg-box textarea:focus, .cmd-box .msg-box textarea:active {
  64. background: #f2f6fe;
  65. color: #000;
  66. }
  67. .cmd-box .tool-footer {
  68. display: flex;
  69. }
  70. .cmd-box .tool-footer span {
  71. width: 50%;
  72. margin: 5px 10px;
  73. }
  74. #chat-modal-btn.flash {
  75. animation: fade 1s infinite;
  76. }
  77. @@keyframes fade {
  78. from {
  79. opacity: 1.0;
  80. transform: scale(1);
  81. }
  82. 50% {
  83. opacity: 0.9;
  84. transform: scale(0.9);
  85. }
  86. to {
  87. opacity: 1.0;
  88. transform: scale(1);
  89. }
  90. }
  91. </style>
  92. @Html.Partial("_Run/_AreaBox", $"指令下达区#{id}")
  93. <div style="display: none" id="@id-pre">
  94. <div class="cmd-box">
  95. <div class="tool-box">
  96. @if (Model.PlayUser != null)
  97. {
  98. <div class="role-change-box">
  99. @Html.Raw(roles)
  100. </div>
  101. <span id="self-role" class="btn btn-iwb btn-sm role" style="margin-left: 15px; cursor: pointer;" title="点击切换角色" onclick="ChangeRole('@(Model.PlayUser.Role)', 1)">@(Model.PlayUser.Role)</span>
  102. }
  103. @if (Model.Play.PlayModel == CampPlayModelDefinition.Team)
  104. {
  105. <span id="chat-modal-btn" class="btn btn-success btn-sm" style="float: right; width: 100px; margin-right: 15px; cursor: pointer;" onclick="ChatModal()"><i class="fas fa-comments"></i>&nbsp;&nbsp;讨论区</span>
  106. <div class="card direct-chat direct-chat-primary" style="position: absolute; width: calc(100% - 25px); top: -400px; z-index: 1000; color: #111; background: #f2f6fe; display: none">
  107. <div class="card-header">
  108. <h3 class="card-title" style="font-weight: 600"><i class="fas fa-comments"></i>&nbsp;&nbsp;讨论区</h3>
  109. <div class="card-tools">
  110. <button type="button" class="btn btn-tool" data-card-widget="remove" onclick="chatFlag = true">
  111. <i class="fas fa-times"></i>
  112. </button>
  113. </div>
  114. </div>
  115. <div class="card-body " style="height: 250px;">
  116. <div class="scroll-box" style="width: 100%; height: 100%;">
  117. <div class="direct-chat-messages" id="chat-box" style="height: 100%; overflow: unset;">
  118. </div>
  119. </div>
  120. </div>
  121. <div class="card-footer">
  122. <div class="input-group">
  123. <input type="text" id="message" name="message" placeholder="请输入..." class="form-control">
  124. <span class="input-group-append">
  125. <button type="button" onclick="SendChat()" class="btn btn-primary">发送</button>
  126. </span>
  127. </div>
  128. </div>
  129. </div>
  130. }
  131. @if (Model.PlayUser != null && (Model.PlayUser.PlayerType == CampPlayerTypeDefinition.Creator || Model.Play.PlayModel != CampPlayModelDefinition.Team))
  132. {
  133. <span class="btn btn-danger btn-sm" style="float: right; margin-right: 25px; transform: scale(0.9); cursor: pointer;" onclick="NextNode()"><i class="fas fa-paper-plane"></i>&nbsp;&nbsp;下一阶段情景</span>
  134. }
  135. </div>
  136. @if (Model.PlayUser != null)
  137. {
  138. <div class="msg-box">
  139. <textarea id="cmd-text" class="form-control" rows="3" placeholder="请输入指令"></textarea>
  140. <span class="btn btn-iwb btn-sm" onclick="Submit(@(Model.PlayUser.PlayerType))"><i class="fas fa-display-arrow-right"></i>&nbsp;&nbsp;提交指令</span>
  141. </div>
  142. }
  143. </div>
  144. </div>
  145. @using (Html.BeginScripts())
  146. {
  147. if (Model.PlayUser != null)
  148. {
  149. <text>
  150. <script id="cmd-send-script">
  151. var $cmdSendBody = $('#@id .box-body');
  152. $cmdSendBody.html($('#@id-pre').html());
  153. $('#@id-pre').remove();
  154. $(function() {
  155. $('#message').on('keypress',
  156. function(event) {
  157. if (event.keyCode == "13") {
  158. SendChat();
  159. return false;
  160. }
  161. return true;
  162. });
  163. $('#cmd-text').on('keypress',
  164. function(event) {
  165. if (event.keyCode == "13") {
  166. Submit(@(Model.PlayUser.PlayerType));
  167. return false;
  168. }
  169. return true;
  170. });
  171. });
  172. function Submit(type) {
  173. var text = $('#cmd-text').val().trim(),
  174. role = $('#self-role').text(),
  175. path = $('#current-scene-path').val();
  176. if (!text) {
  177. abp.message.warn("指令不能为空!");
  178. return;
  179. }
  180. var url = abp.appUrl + "/CampPlay/WriteCmdLog";
  181. if (type == @(CampPlayerTypeDefinition.Creator)) {
  182. if (!path) {
  183. abp.message.warn("请选择一个情景!");
  184. return;
  185. }
  186. if (@(roleArr.Length) > 0 && role == "@(Model.PlayUser.Role)") {
  187. abp.message.warn("请选择一个角色!");
  188. return;
  189. }
  190. url = abp.appUrl + "/CampPlay/WriteSubmitCmdLog";
  191. }
  192. $.iwbAjax4({
  193. url: url,
  194. data: { GroupNo: '@(Model.Play.Id)', BehaviorWord: text, BehaviorRole: role, scenePath: path },
  195. success: function() {
  196. $('#cmd-text').val('').focus();
  197. }
  198. });
  199. }
  200. function NextNode() {
  201. MsgConfirm("确认本阶段情景已处理完,进入下一阶段的情景吗?",
  202. "下一阶段情景",
  203. function() {
  204. $.iwbAjax4({
  205. url: abp.appUrl + "/CampPlay/NextFlowNode",
  206. data: { Id: '@(Model.Play.Id)' },
  207. success: function() {
  208. abp.ui.setBusy($('body'));
  209. setTimeout(function() {
  210. abp.ui.clearBusy($('body'));
  211. },
  212. 10000);
  213. }
  214. });
  215. });
  216. }
  217. function NextRound() {
  218. MsgConfirm("确认本阶段情景已处理完,进入下一阶段的情景吗?",
  219. "下一阶段情景",
  220. function() {
  221. $.iwbAjax1({
  222. url: abp.appUrl + "/CampPlay/NextRound",
  223. data: { Id: '@(Model.Play.Id)' },
  224. success: function() {
  225. }
  226. });
  227. });
  228. }
  229. function ChangeRole(role, type) {
  230. if (type) {
  231. if ($('.role-change-box').css("display")=="none") {
  232. $('.role-change-box').fadeIn(600);
  233. } else {
  234. $('.role-change-box').fadeOut(300);
  235. }
  236. //$('#self-role').html(role).removeClass('btn-danger').addClass('btn-iwb');
  237. } else {
  238. $('#self-role').html(role).removeClass('btn-iwb').addClass('btn-danger');
  239. $('.role-change-box').fadeOut(300);
  240. }
  241. }
  242. </script>
  243. </text>
  244. }
  245. if (Model.Play.PlayModel == CampPlayModelDefinition.Team)
  246. {
  247. <script id="chat-script">
  248. function ChatModal() {
  249. if ($('#chat-box').closest('.card').css("display") == "none") {
  250. $('#chat-box').closest('.card').fadeIn(600);
  251. $('#chat-modal-btn').removeClass('flash');
  252. window.Scroll2Bottom($('#chat-box').closest('.scroll-box'));
  253. $('#message').focus();
  254. } else {
  255. $('#chat-box').closest('.card').slideUp();
  256. }
  257. }
  258. function SendChat() {
  259. var text = $('#message').val();
  260. if (!text) {
  261. return;
  262. }
  263. $.iwbAjax4({
  264. url: abp.appUrl + "/CampPlay/Chat",
  265. data: { Id: '@(Model.Play.Id)', Msg: text },
  266. success: function() {
  267. $('#message').val('').focus();
  268. }
  269. });
  270. }
  271. function GetChat() {
  272. $.iwbAjax5({
  273. url: abp.appUrl + 'Query/GetPlayChats?no=@(Model.Play.Id)',
  274. success: function(res) {
  275. if (res && res.length) {
  276. res.forEach((v)=> {
  277. FormatChat(v);
  278. });
  279. }
  280. }
  281. });
  282. }
  283. function FormatChat(data) {
  284. if (data) {
  285. var str = '';
  286. var imagePath = data.imagePath ? data.imagePath : '/Content/Image/user.png';
  287. var isSelf = '', left = 'left', right = 'right';
  288. if (data.userName === '@(AbpSession.UserName)') {
  289. isSelf = "right";
  290. left = 'right';
  291. right = 'left';
  292. }
  293. str += '<div class="direct-chat-msg {0}">'.format(isSelf);
  294. str += '<div class="direct-chat-infos clearfix">';
  295. str += '<span class="direct-chat-name float-{0}">{1}</span>'
  296. .format(left, data.name); //+"("+data.userName+")");
  297. str += '<span class="direct-chat-timestamp float-{0}">{1}</span>'.format(right,
  298. new Date(data.logDate).format('hh:mm:ss'));
  299. str += '</div>';
  300. str += '<img class="direct-chat-img" src="{0}" alt="{1}">'.format(imagePath, data.name);;
  301. str += '<div class="direct-chat-text">{0}</div>'.format(data.word);
  302. str += '</div>';
  303. $('#chat-box').append(str);
  304. window.Scroll2Bottom($('#chat-box').closest('.scroll-box'));
  305. }
  306. }
  307. iwbHub.client.getChat = function(msg) {
  308. console.log('getChat: ', msg);
  309. if (msg) {
  310. try {
  311. var data = JSON.parse(msg);
  312. if (data.no == '@(Model.Play.Id)') {
  313. var str = FormatChat(data);
  314. if (str) {
  315. $('#chat-box').append(str);
  316. window.Scroll2Bottom($('#chat-box').closest('.scroll-box'));
  317. if ($('#chat-box').closest('.card').css("display") == "none"){
  318. $('#chat-modal-btn').addClass('flash');
  319. }
  320. }
  321. }
  322. } catch (e) {
  323. console.log('getChat: ', e);
  324. }
  325. }
  326. };
  327. </script>
  328. }
  329. }