Ready.cshtml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. @using IwbZero.ToolCommon.StringModel
  2. @using WeOnlineApp.Configuration
  3. @using WeOnlineApp.Models.Play
  4. @using WeOnlineApp.TrainingCamp.Dto
  5. @using WeOnlineApp.TrainingCampPlay.Dto
  6. @{
  7. Layout = "~/Views/Shared/Layout/_Layout.None.cshtml";
  8. ViewBag.PageId = "start";
  9. ViewBag.Title = "等待演练";
  10. CampPlayModel campPlay = ViewBag.CampPlay;
  11. CampPlayDto play = campPlay.Play;
  12. CampDto camp = campPlay.Camp;
  13. CampPlayUserDto playUser = campPlay.PlayUser;
  14. var imagePath = string.IsNullOrEmpty(AbpSession.AvatarImagePath) ? "/Content/Image/user.png" : AbpSession.AvatarImagePath;
  15. }
  16. <style>
  17. body {
  18. width: 100vw;
  19. height: 100vh;
  20. color: #f5f5dc;
  21. background-image: linear-gradient(45deg,#005f61,#007f61);
  22. }
  23. .menu {
  24. --h: 35px;
  25. position: absolute;
  26. top: 30px;
  27. right: 10px;
  28. width: 80%;
  29. padding-right: 20px;
  30. line-height: var(--h);
  31. display: inline-block;
  32. list-style: none;
  33. display: flex;
  34. justify-content: flex-end;
  35. }
  36. .menu a {
  37. color: #f5f5dc;
  38. padding: 3px 5px;
  39. margin: 0 10px;
  40. line-height: var(--h);
  41. }
  42. .menu a:hover {
  43. border-bottom: 1px solid #f5f5dc;
  44. }
  45. .header {
  46. margin: 60px 20px 0;
  47. min-height: 80px;
  48. display: flex;
  49. justify-content: center;
  50. align-items: center;
  51. }
  52. .friend-box {
  53. margin: 50px 100px 10px;
  54. min-height: 100px;
  55. display: flex;
  56. flex-wrap: wrap;
  57. justify-content: flex-start;
  58. align-items: center;
  59. border: 1px solid #8fbc8f;
  60. }
  61. .self-box {
  62. margin: 20px 0;
  63. width: 100%;
  64. min-height: 100px;
  65. display: flex;
  66. flex-direction: column;
  67. justify-content: center;
  68. align-items: center;
  69. }
  70. .self-box > div {
  71. margin-top: 15px;
  72. }
  73. .code {
  74. color: #f5f5dc;
  75. font-weight: 600;
  76. font-size: 24px;
  77. }
  78. .img-box {
  79. width: auto;
  80. }
  81. img {
  82. width: 100px;
  83. height: 100px;
  84. border: 1px solid #f5f5dc;
  85. }
  86. .name {
  87. font-size: 18px;
  88. }
  89. .role {
  90. color: #f08080;
  91. margin-top: 0 !important;
  92. text-align: center;
  93. }
  94. .self-box .img-box img {
  95. width: 200px;
  96. height: 200px;
  97. border: 2px solid #f5f5dc;
  98. border-radius: 50%;
  99. }
  100. .self-box .name {
  101. font-weight: 600;
  102. font-size: 22px;
  103. }
  104. .friend {
  105. margin: 10px;
  106. display: flex;
  107. flex-direction: column;
  108. justify-content: center;
  109. align-items: center;
  110. }
  111. .friend > div {
  112. margin-top: 8px;
  113. }
  114. .friend .img-box {
  115. position: relative;
  116. }
  117. .role-box .select2-selection {
  118. height: 38px;
  119. }
  120. .select2-results__option {
  121. color: #5897fb !important;
  122. }
  123. .select2-selection__arrow b {
  124. margin-top: 4px !important;
  125. }
  126. .btn-box {
  127. width: 100px;
  128. margin: 15px auto 0;
  129. }
  130. .btn-box button {
  131. width: 100%;
  132. }
  133. </style>
  134. <div class="header">
  135. <h2>@(play.Name) (@(camp?.Name)) </h2>
  136. </div>
  137. <ul class="menu">
  138. <li>
  139. <a href="@Url.Action("Index","Play")"><i class="iconfont icon-home"></i>&nbsp;&nbsp;返回主页</a>
  140. </li>
  141. <li>
  142. <a href="javascript:void(0)" onclick="Exit()"><i class="iconfont icon-backspace"></i>&nbsp;&nbsp;退出演练</a>
  143. </li>
  144. <li>
  145. <a href="javascript:void(0)" onclick="LoginOut()"><i class="iconfont icon-poweroff"></i>&nbsp;&nbsp;注销账号</a>
  146. </li>
  147. </ul>
  148. <div class="self-box">
  149. <div class="img-box">
  150. <img src="@(imagePath)" alt="@(AbpSession.RealName)" />
  151. </div>
  152. <div class="name">@(AbpSession.RealName)</div>
  153. @if (playUser == null)
  154. {
  155. <div class="btn-box"><button type="button" class="btn btn-success" onclick="Join()">加入演练</button></div>
  156. }
  157. else if (playUser.PlayerType == CampPlayerTypeDefinition.Creator)
  158. {
  159. <div class="btn-box"> <button type="button" class="btn btn-success" onclick="Start()">开始演练</button></div>
  160. <div class="code">
  161. <span>邀请码:@(play.InvitationCode)</span>
  162. </div>
  163. }
  164. else
  165. {
  166. string style1 = "display:none", style2 = "display:none";
  167. if (playUser.PlayerState == CampPlayUserStateDefinition.Ready)
  168. {
  169. style1 = "display:block";
  170. }
  171. else if (playUser.PlayerState == CampPlayUserStateDefinition.New || playUser.PlayerState == CampPlayUserStateDefinition.CancelReady)
  172. {
  173. style2 = "display:block";
  174. }
  175. var roleNames = "<option value=\"\">请选择一个角色开始准备</option>"; ;
  176. if (play.PlayRoleNames.IsNotEmpty())
  177. {
  178. var arr = play.PlayRoleNames.Split(',');
  179. foreach (var role in arr)
  180. {
  181. roleNames += "<option value=\"" + role + "\">" + role + "</option>";
  182. }
  183. }
  184. <div id="noReady" style="@(style2)">
  185. <div class="role-box">
  186. <select id="role" class="form-control" style="width: 250px" autocomplete="off">
  187. @(Html.Raw(roleNames))
  188. </select>
  189. </div>
  190. <div class="btn-box"><button type="button" class="btn btn-success" onclick="Ready()">准备演练</button></div>
  191. </div>
  192. <div id="hasReady" style="@(style1)">
  193. <div class="role">@(playUser.Role)</div>
  194. <div class="btn-box"><button type="button" class="btn btn-danger" onclick="Cancel()">取消准备</button></div>
  195. </div>
  196. }
  197. </div>
  198. @if (play.PlayModel == CampPlayModelDefinition.Team)
  199. {
  200. <div class="friend-box"></div>
  201. }
  202. @section scripts
  203. {
  204. <script>
  205. $(function() {
  206. abp.signalr.connect('@(play.InvitationCode)');
  207. $('#role').select2();
  208. @if (play.PlayModel == CampPlayModelDefinition.Team)
  209. {
  210. <text>
  211. GetPlayUsers();
  212. </text>
  213. }
  214. });
  215. function Exit() {
  216. MsgConfirm("退出后无法再加入演练,您确定退出演练吗?",
  217. "退出演练",
  218. function () {
  219. @if (playUser?.PlayerType == CampPlayerTypeDefinition.Creator)
  220. {
  221. <text>
  222. MsgConfirm("演练还未开始!您是房主,退出后演练后会删除演练,确定退出吗?",
  223. "再次确认",
  224. function() {
  225. $.iwbAjax({
  226. url: abp.appUrl + '/CampPlay/ExitPlay?no=@(play.Id)',
  227. success: function() {
  228. window.location.href = "@Url.Action("Start", "Play")";
  229. }
  230. });
  231. });
  232. </text>
  233. }
  234. else
  235. {
  236. <text>
  237. $.iwbAjax({
  238. url: abp.appUrl + '/CampPlay/ExitPlay?no=@(play.Id)',
  239. success: function() {
  240. window.location.href = "@Url.Action("Start", "Play")";
  241. }
  242. });
  243. </text>
  244. }
  245. });
  246. }
  247. function LoginOut() {
  248. MsgConfirm("您确定注销账号吗?",
  249. "注销账号",
  250. function () {
  251. @if (playUser?.PlayerType == CampPlayerTypeDefinition.Creator)
  252. {
  253. <text>
  254. MsgConfirm("您是房主,注销后演练进程无法继续,注销退出吗?",
  255. "再次确认",
  256. function() {
  257. window.location.href = "/Account/LogOut";
  258. });
  259. </text>
  260. }
  261. else
  262. {
  263. <text>
  264. window.location.href = "/Account/LogOut";
  265. </text>
  266. }
  267. });
  268. }
  269. function GetPlayUsers() {
  270. $.iwbAjax4({
  271. url: abp.appUrl + "CampPlay/GetPlayUsers?no=@(play.Id)",
  272. success: function(res) {
  273. FormatterPlayUsers(res);
  274. }
  275. });
  276. }
  277. function FormatterPlayUsers(data) {
  278. var str = "";
  279. if (data && data.length) {
  280. data.forEach(function(v) {
  281. str += '<div class="friend" id="user-{0}">'.format(v.id);
  282. str += FormatterPlayUser(v);
  283. str += '</div>';
  284. });
  285. }
  286. if (str) {
  287. $('.friend-box').html(str);
  288. }
  289. }
  290. function FormatterPlayUser(data) {
  291. var str = "";
  292. if (data) {
  293. var ribbon = '<div class="ribbon-wrapper"><div class="ribbon bg-danger">未准备</div></div>';
  294. if (data.playerType == @(CampPlayerTypeDefinition.Creator)) {
  295. ribbon = '<div class="ribbon-wrapper"><div class="ribbon bg-warning">房主</div></div>';
  296. } else if (data.playerState == @(CampPlayUserStateDefinition.Ready)) {
  297. ribbon = '<div class="ribbon-wrapper"><div class="ribbon bg-success">已准备</div></div>';
  298. }
  299. var img = data.imagePath ? data.imagePath : "/Content/Image/user.png";
  300. str += '<div class="img-box"><img src="{0}" alt="{1}" />{2}</div>'.format(img, data.playerName, ribbon);
  301. str += '<div class="name">{0}</div>'.format(data.playerName);
  302. str += '<div class="role">{0}</div>'.format(data.role ? data.role : "未准备");
  303. }
  304. return str;
  305. }
  306. </script>
  307. <script>
  308. function Join() {
  309. MsgConfirm("确认加入演练吗?",
  310. "加入演练",
  311. function() {
  312. $.iwbAjax1({
  313. url: abp.appUrl + "/CampPlay/Join",
  314. data: { id: '@(play.Id)' },
  315. success: function() {
  316. window.location.reload();
  317. }
  318. });
  319. });
  320. }
  321. function Cancel() {
  322. MsgConfirm("确认取消准备吗?",
  323. "取消准备",
  324. function() {
  325. $.iwbAjax1({
  326. url: abp.appUrl + "/CampPlay/CancelReady",
  327. data: { id: '@(play.Id)' },
  328. success: function() {
  329. $('#hasReady').hide();
  330. $('#noReady').fadeIn(500);
  331. }
  332. });
  333. });
  334. }
  335. function Ready() {
  336. var role = $('#role').val();
  337. if (role) {
  338. $.iwbAjax4({
  339. url: abp.appUrl + "/CampPlay/Ready",
  340. data: { id: '@(play.Id)', role: role },
  341. success: function() {
  342. $('#noReady').hide();
  343. $('#hasReady').fadeIn(500);
  344. }
  345. });
  346. } else {
  347. abp.message.warn('请选择一个角色!');
  348. }
  349. }
  350. function Start() {
  351. var msg = "确认开始演练吗?";
  352. MsgConfirm(msg,
  353. "开始演练",
  354. function() {
  355. $.iwbAjax4({
  356. url: abp.appUrl + "/CampPlay/Start",
  357. data: { id: '@(play.Id)' },
  358. success: function() {
  359. abp.message.success("演练启动完成。");
  360. },
  361. error: function() {
  362. }
  363. });
  364. });
  365. }
  366. </script>
  367. <script id="hub-s">
  368. iwbHub.client.getReloadPage = function (msg) {
  369. console.log('getReloadPage: ', msg);
  370. if (msg) {
  371. try {
  372. var data = JSON.parse(msg);
  373. if (data.no=='@(play.Id)') {
  374. window.location.reload();
  375. }
  376. } catch (e) {
  377. console.log('getReloadPage: ', e);
  378. }
  379. }
  380. };
  381. iwbHub.client.getUserChange = function (msg) {
  382. console.log('getUserChange: ', msg);
  383. if (msg) {
  384. try {
  385. var data = JSON.parse(msg);
  386. if (data) {
  387. var str = FormatterPlayUser(data);
  388. var $user = $('#user-' + data.id);
  389. if ($user.length > 0) {
  390. $user.html(str);
  391. } else {
  392. str = '<div class="friend" id="user-{0}">{1}</div>'.format(data.id, str);
  393. $('.friend-box').append(str);
  394. }
  395. }
  396. } catch (e) {
  397. console.log('getUserChange: ', e);
  398. }
  399. }
  400. };
  401. iwbHub.client.getUserExit = function (msg) {
  402. console.log('getUserExit: ', msg);
  403. if (msg) {
  404. try {
  405. var data = JSON.parse(msg);
  406. if (data) {
  407. var $user = $('#user-' + data.id);
  408. if ($user.length > 0) {
  409. $user.remove();
  410. }
  411. }
  412. } catch (e) {
  413. console.log('getUserExit: ', e);
  414. }
  415. }
  416. };
  417. @if (play.PlayModel == CampPlayModelDefinition.Team&& playUser?.PlayerType != CampPlayerTypeDefinition.Creator)
  418. {
  419. <text>
  420. iwbHub.client.getCreatorExit = function (msg) {
  421. console.log('getCreatorExit: ', msg);
  422. if (msg) {
  423. try {
  424. var data = JSON.parse(msg);
  425. if (data) {
  426. abp.message.warn('房主已退出演练,演练已结束!',"演练结束").done(function() {
  427. window.location.href = "@Url.Action("Start", "Play")";
  428. });
  429. }
  430. } catch (e) {
  431. console.log('getCreatorExit: ', e);
  432. }
  433. }
  434. };
  435. </text>
  436. }
  437. </script>
  438. }