Headquarter.cshtml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. @using WeApp.TrainingCampGroup.Dto
  2. @{
  3. Layout = "~/Views/Shared/Layout/_Layout.Stu.cshtml";
  4. CampGroupDto group = ViewBag.Group;
  5. bool isLeader = ViewBag.IsLeader, hasBuilded = ViewBag.HasBuilded;
  6. string id = group.Id,
  7. groupName = group.Name,
  8. campNo = group.CampNo;
  9. ViewBag.Title = (isLeader ? "指挥长组建指挥部" : "学员屏指挥部") + "(" + groupName + ")";
  10. var name = hasBuilded ? groupName + "指挥部——" + (isLeader ? "指挥长" : "组员") : isLeader ? "指挥长组建指挥部" : "指挥部组建中...";
  11. var title = hasBuilded ? "指挥部" : "创建指挥部";
  12. var stu = isLeader ? "" : "stu";
  13. }
  14. @section css{
  15. <link href="~/Content/Css/ExerciseV2/stu-zhb.min.css?v=1.1" rel="stylesheet" />
  16. }
  17. @Html.Partial("Layout/V2/_Bg",false)
  18. <div class="box no-select">
  19. <div id="bg_title">
  20. <span class="title">@(title)</span>
  21. </div>
  22. <div class="box-body">
  23. <div class="box-header">
  24. <span class="title">@name</span>
  25. </div>
  26. <div class="body" style="margin-top: 5px">
  27. @if (!hasBuilded)
  28. {
  29. <div class="body-card select">
  30. <div class="select-box">
  31. </div>
  32. @if (isLeader)
  33. {
  34. <div class="add-role" data-id="self" onclick="GroupToggle(this)">
  35. <div class="icon">
  36. <img src="/Content/Image/ExerciseV2/zhb/zh_icon-add-role.svg" alt="" />
  37. </div>
  38. <div class="text">自定义角色</div>
  39. </div>
  40. }
  41. </div>
  42. }
  43. <div class="body-card role">
  44. <div class="content-box">
  45. @if (!hasBuilded && isLeader)
  46. {
  47. <div class="role-content self" id="c_self">
  48. <div class="role-box">
  49. <div class="role-item add" id="add-role" onclick="$('#add-role').hide();$('#add-box').fadeIn(800).css('display', 'flex');$('#self-role-text').focus();">
  50. <div class="icon">
  51. <img src="~/Content/Image/ExerciseV2/zhb/zh_icon-add-role-2.svg" />
  52. </div>
  53. <div class="text">点击添加角色</div>
  54. </div>
  55. </div>
  56. <div class="add-box" id="add-box">
  57. <input type="text" id="self-role-text" value="" pattern="请输入新增角色名称" />
  58. <div class="btn-box">
  59. <button type="button" class="btn btn-small cancel" onclick="$('#add-box').fadeOut(500);$('#add-role').fadeIn(800).css('display', 'flex');">取消</button>
  60. <button type="button" class="btn btn-small submit" onclick="CreateSelfRole()">添加</button>
  61. </div>
  62. </div>
  63. </div>
  64. }
  65. else
  66. {
  67. <div class="role-content" style="display: none"></div>
  68. }
  69. </div>
  70. </div>
  71. @if (!hasBuilded && isLeader)
  72. {
  73. <div class="body-card">
  74. <div class="btn" onclick="CreateGroupRole()">创建指挥部</div>
  75. </div>
  76. <div style="display: none">
  77. <img src="/Content/Image/ExerciseV2/zhb/zh_icon-checkbox.svg" style="opacity: 0" />
  78. <img src="/Content/Image/ExerciseV2/zhb/zh_icon-checkbox-selected.svg" style="opacity: 0" />
  79. </div>
  80. }
  81. </div>
  82. </div>
  83. </div>
  84. @section scripts
  85. {
  86. <script>
  87. $(function () {
  88. resizeHeight_head();
  89. window.addEventListener('resize', resizeHeight_head);
  90. @if (hasBuilded)
  91. {
  92. <text>
  93. GetGroupRoles();
  94. </text>
  95. }
  96. else
  97. {
  98. <text>
  99. GetCampRoleGroups();
  100. </text>
  101. }
  102. $('#self-role-text').keydown(function(e) {
  103. var theEvent = window.event || e;
  104. var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
  105. if (code == 13) {
  106. CreateSelfRole();
  107. }
  108. });
  109. });
  110. function resizeHeight_head() {
  111. resizeHeight((h, wh) => {
  112. var height = 355;
  113. @if (hasBuilded)
  114. {
  115. <text>
  116. height = 175;
  117. </text>
  118. }
  119. else if (!isLeader)
  120. {
  121. <text>
  122. height = 305;
  123. </text>
  124. }
  125. $(".content-box").height(wh - h - height)
  126. })
  127. }
  128. var selectStr = '<div class="check-box-icon"></div>已选择<span>(点击取消)</span>';
  129. var noSelectStr = '<div class="check-box-icon"></div>未选择<span>(点击选择)</span>';
  130. var roleInfo = '<div class="role-item {1}" data-name="{0}"><div class="icon"><img src="/Content/Image/ExerciseV2/zhb/zh_icon-user.svg" alt="" /></div><div class="text">{0}</div>{2}</div> ';
  131. function GetGroupRoles() {
  132. $.iwbAjax4({
  133. url: abp.appUrl + "Query/GetGroupRoleInfos?no=@(id)",
  134. success: function(res) {
  135. FormatterBuildGroupRole(res);
  136. OverlayScrollbar($('.content-box'));
  137. }
  138. });
  139. }
  140. function GetCampRoleGroups() {
  141. $.iwbAjax4({
  142. url: abp.appUrl + "Query/GetCampRoleGroupInfos?no=@(campNo)",
  143. success: function(res) {
  144. FormatterGroupRole(res);
  145. OverlayScrollbar($('.content-box'));
  146. }
  147. });
  148. }
  149. function FormatterBuildGroupRole(data) {
  150. if (data && data.length > 0) {
  151. var str = '<div class="role-content active"><div class="role-box">';
  152. data.forEach(function(r) {
  153. str += roleInfo.format(r, "", "");
  154. });
  155. str += '</div></div>';
  156. $('.content-box').html(str);
  157. }
  158. }
  159. function FormatterGroupRole(data) {
  160. var str1 = "", str2 = "";
  161. if (data && data.length > 0) {
  162. data.forEach(function(v) {
  163. str1 += FormatterGroup(v);
  164. str2 += FormatterRole(v);
  165. });
  166. }
  167. if (str1) {
  168. $('.role .content-box .role-content').before(str2);
  169. $('.select-box').html(str1);
  170. $('.select-box .select-item:first-child').trigger("click");
  171. }
  172. }
  173. function FormatterGroup(data) {
  174. var str = '';
  175. if (data) {
  176. str += '<div class="select-item" id="t_{0}" data-id="{0}" onclick="GroupToggle(this)">'.format(data.id);
  177. str += '<div class="check-box-icon @(stu)"></div>';
  178. str += '<div class="icon"><img data-id="{0}" src="/Content/Image/ExerciseV2/zhb/zh_icon-{0}.svg"/></div >'
  179. .format(data.id);
  180. str += '<span class="text">{0}</span>'.format(data.roleGroupName);
  181. str += '</div>';
  182. }
  183. return str;
  184. }
  185. function FormatterRole(data) {
  186. var str = '';
  187. if (data) {
  188. str += '<div class="role-content" id="c_{0}">'.format(data.id);
  189. str += '<div class="role-select @(stu)" data-id="{1}" onclick="GroupCheckToggle(this)">{0}</div>'.format(noSelectStr,
  190. data.id);
  191. str += '<div class="role-box">';
  192. if (data.roleNames) {
  193. var arr = data.roleNames.split(',');
  194. arr.forEach(function(v) {
  195. str += roleInfo.format(v, "", "");
  196. });
  197. }
  198. str += '</div>';
  199. str += '</div>';
  200. }
  201. return str;
  202. }
  203. function GroupToggle(that) {
  204. var $that = $(that);
  205. var id = $that.data('id');
  206. $('.role-content').removeClass('active');
  207. $('#c_' + id).addClass('active');
  208. $('.select-box .select-item').removeClass('active');
  209. $that.addClass('active');
  210. }
  211. function GroupCheckToggle(that) {
  212. var $that = $(that);
  213. var id = $that.data('id');
  214. if ($('#t_' + id).hasClass('check')) {
  215. $('#t_' + id).removeClass('check');
  216. $('#c_' + id).find('.role-select').removeClass('check').html(noSelectStr);
  217. $('#c_' + id).find('.role-item').removeClass('check');
  218. } else {
  219. $('#t_' + id).addClass('check');
  220. $('#c_' + id).find('.role-select').addClass('check').html(selectStr);
  221. $('#c_' + id).find('.role-item').addClass('check');
  222. }
  223. }
  224. function CreateSelfRole() {
  225. var name = $('#self-role-text').val();
  226. if (name) {
  227. var str = roleInfo.format(name,
  228. " check",
  229. '<span class="close" onclick="$(this).parent().remove()">&times;</span>');
  230. $('#add-role').before(str);
  231. $('#self-role-text').val('');
  232. }
  233. $('#add-box').hide();
  234. $('#add-role').fadeIn(800).css('display', 'flex');
  235. }
  236. function CreateGroupRole() {
  237. var groupNo = "@(id)";
  238. abp.message.confirm("您确认提交吗?提交后不可再更改。",
  239. "创建指挥部",
  240. function (isConfirmed) {
  241. if (isConfirmed) {
  242. var roleGroupNos = [], selfRoleNames = [];
  243. $(".select-item.check").each(function (i, v) {
  244. var no = $(v).data("id");
  245. if (no != 'self') {
  246. roleGroupNos.push(no);
  247. }
  248. });
  249. $("#c_self .check").each(function (i, v) {
  250. selfRoleNames.push($(v).data("name"));
  251. });
  252. console.log(roleGroupNos, selfRoleNames);
  253. if (roleGroupNos.length <= 0 && selfRoleNames.length <= 0) {
  254. abp.message.warn("您还未选择角色。");
  255. return;
  256. }
  257. $.iwbAjax1({
  258. url: abp.appUrl + "/Eval/CreateGroupRole",
  259. isAlert: false,
  260. isValidate: false,
  261. data: { GroupNo: groupNo, RoleGroupNos: roleGroupNos, SelfRoleNames: selfRoleNames },
  262. success: function () {
  263. //window.iwbHub.server.sendPageState(JSON.stringify({ groupNo: groupNo, cmd: "reload" }));
  264. //window.iwbHub.server.sendPageState(JSON.stringify({ groupNo: groupNo, cmd: "reload-public" }));
  265. //window.iwbHub.server.sendRefreshRole(groupNo);
  266. window.location.reload();
  267. abp.message.success("角色预案创建成功");
  268. }
  269. });
  270. }
  271. });
  272. }
  273. </script>
  274. <script id="hub">
  275. abp.signalr.connect(['@(id)', '@(campNo)']);
  276. iwbHub.client.getReloadAll = function(msg) {
  277. console.log('getReloadAll: ', msg);
  278. if (msg) {
  279. try {
  280. var data = JSON.parse(msg);
  281. if (data) {
  282. if (data.no == '@(id)' || data.no == '@(campNo)') {
  283. window.location.reload();
  284. }
  285. }
  286. } catch (e) {
  287. console.log('getReloadAll: ', e);
  288. }
  289. }
  290. };
  291. @if (isLeader)
  292. {
  293. <text>
  294. iwbHub.client.getReloadLeader = function(msg) {
  295. console.log('getReloadLeader: ', msg);
  296. if (msg) {
  297. try {
  298. var data = JSON.parse(msg);
  299. if (data) {
  300. if (data.no == '@(id)' || data.no == '@(campNo)') {
  301. window.location.reload();
  302. }
  303. }
  304. } catch (e) {
  305. console.log('getReloadLeader: ', e);
  306. }
  307. }
  308. };
  309. </text>
  310. }
  311. else
  312. {
  313. <text>
  314. iwbHub.client.getReloadStu = function(msg) {
  315. console.log('getReloadStu: ', msg);
  316. if (msg) {
  317. try {
  318. var data = JSON.parse(msg);
  319. if (data) {
  320. if (data.no == '@(id)' || data.no == '@(campNo)') {
  321. window.location.reload();
  322. }
  323. }
  324. } catch (e) {
  325. console.log('getReloadStu: ', e);
  326. }
  327. }
  328. };
  329. </text>
  330. }
  331. </script>
  332. }