人人商城

set-permission.html 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. {template 'common/header'}
  2. <ol class="breadcrumb we7-breadcrumb">
  3. <a href="javascript:history.go(-1);"><i class="wi wi-back-circle"></i> </a>
  4. <li>权限设置</li>
  5. </ol>
  6. <form class="form-horizontal form we7-form" action="" method="post">
  7. <table class="table we7-table table-hover we7-form account-and-wxapp">
  8. {loop $menus $name $sections}
  9. {if $sections['section'] && $name == 'account' && in_array($account['type'], array(ACCOUNT_TYPE_OFFCIAL_NORMAL, ACCOUNT_TYPE_OFFCIAL_AUTH))}
  10. <div class="we7-page-title">{$sections['title']}<span class="color-default font-sm">(<i class="fa fa-exclamation-circle"></i> 默认未勾选任何菜单时,用户拥有全部权限)</span>
  11. </div>
  12. {loop $sections['section'] $section_id $section}
  13. {if !in_array($section_id, array('platform_module'))}
  14. <thead>
  15. <tr class="text-left">
  16. <th colspan="4" class="text-left">
  17. <div class="">
  18. <input id="check-{$section_id}" type="checkbox" name="system_{$section_id}" onChange="selectall(this, 'system_{$section_id}')">
  19. <label for="check-{$section_id}" class=" we7-margin-horizontal-none">{$section['title']}</label>
  20. </div>
  21. </th>
  22. </tr>
  23. </thead>
  24. <tbody class="system_{$section_id}">
  25. {php $i=1;}
  26. {loop $section['menu'] $menu_id $menu}
  27. {if is_array($menu['permission_display']) && !in_array($account['type'], $menu['permission_display'])}{php continue;}{/if}
  28. {if $i%4 == 1 || $i == 1}<tr>{/if}
  29. <td class="text-left vertical-middle" style="overflow:inherit;">
  30. <div class="dropdown system-select-dropdown">
  31. <span>
  32. <input id="check-child-{$menu_id}" type="checkbox" we7-check-all="1" value="{$menu['permission_name']}" {if in_array($menu['permission_name'], $user_menu_permission_account)}checked{/if} name="system[]" autocomplete="off" />
  33. <label for="check-child-{$menu_id}" class="we7-margin-horizontal-none" data-toggle="tooltip">{$menu['title']}{if !empty($menu['sub_permission'])}<span class="caret"></span>{/if}</label>
  34. </span>
  35. {if $menu['sub_permission']}
  36. <ul class="dropdown-menu">
  37. {loop $menu['sub_permission'] $sub_permission}
  38. <li class="text-left">
  39. <input id="check-child-{$sub_permission['permission_name']}" we7-check-all="1" type="checkbox" value="{$sub_permission['permission_name']}" {if in_array($sub_permission['permission_name'], $user_menu_permission_account)}checked{/if} name="system[]">
  40. <label class="we7-margin-horizontal-none" for="check-child-{$sub_permission['permission_name']}">
  41. {$sub_permission['title']}
  42. </label>
  43. </li>
  44. {/loop}
  45. </ul>
  46. {/if}
  47. </div>
  48. </td>
  49. {if $i%4 == 0}</tr><tr>{/if}
  50. {php $i++;}
  51. {/loop}
  52. {if ($i-1)%4 != 0}
  53. <?php
  54. for ($x=0; $x<4-($i-1)%4; $x++) {
  55. echo "<td></td>";
  56. }
  57. ?>
  58. </tr>
  59. {/if}
  60. </tbody>
  61. {/if}
  62. {/loop}
  63. {/if}
  64. {if $sections['section'] && $name == 'wxapp' && $account['type'] == ACCOUNT_TYPE_APP_NORMAL}
  65. <div class="we7-page-title">{$sections['title']}</div>
  66. {loop $sections['section'] $section_id $section}
  67. {if !in_array($section_id, array('platform_module'))}
  68. <thead>
  69. <tr class="text-left">
  70. <th colspan="4" class="text-left">
  71. <div class="">
  72. <input id="check-{$section_id}" type="checkbox" name="system_{$section_id}" we7-check-all="1" onChange="selectall(this, 'system_{$section_id}')">
  73. <label for="check-{$section_id}" class=" we7-margin-horizontal-none">{$section['title']}<span class="caret"></span></label>
  74. </div>
  75. </th>
  76. </tr>
  77. </thead>
  78. <tbody class="system_{$section_id}">
  79. {php $i=1;}
  80. {loop $section['menu'] $menu_id $menu}
  81. {if $menu_id == 'front_download'}{php continue;}{/if}
  82. {if $i%4 == 1 || $i == 1}<tr>{/if}
  83. <td class="text-left vertical-middle" style="overflow:inherit;">
  84. <div class="dropdown system-select-dropdown">
  85. <span>
  86. <input id="check-child-{$menu_id}" type="checkbox" we7-check-all="1" value="{$menu['permission_name']}" {if in_array($menu['permission_name'], $user_menu_permission_wxapp)}checked{/if} name="wxapp[]" autocomplete="off" />
  87. <label for="check-child-{$menu_id}" class="we7-margin-horizontal-none" data-toggle="tooltip">{$menu['title']}{if !empty($menu['sub_permission'])}<span class="caret"></span>{/if}</label>
  88. </span>
  89. {if $menu['sub_permission']}
  90. <ul class="dropdown-menu">
  91. {loop $menu['sub_permission'] $sub_permission}
  92. <li class="text-left">
  93. <input id="check-child-{$sub_permission['permission_name']}" we7-check-all="1" type="checkbox" value="{$sub_permission['permission_name']}" {if in_array($sub_permission['permission_name'], $user_menu_permission_wxapp)}checked{/if} name="wxapp[]">
  94. <label class="we7-margin-horizontal-none" for="check-child-{$sub_permission['permission_name']}">
  95. {$sub_permission['title']}
  96. </label>
  97. </li>
  98. {/loop}
  99. </ul>
  100. {/if}
  101. </div>
  102. </td>
  103. {if $i%4 == 0}</tr><tr>{/if}
  104. {php $i++;}
  105. {/loop}
  106. {if ($i-1)%4 != 0}
  107. <?php
  108. for ($x=0; $x<4-($i-1)%4; $x++) {
  109. echo "<td></td>";
  110. }
  111. ?>
  112. </tr>
  113. {/if}
  114. </tbody>
  115. {/if}
  116. {/loop}
  117. {/if}
  118. {/loop}
  119. </table>
  120. {if !empty($module)}
  121. <table class="table we7-table table-hover vertical-middle we7-form">
  122. <div class="we7-page-title">应用<span class="color-default font-sm">(<i class="fa fa-exclamation-circle"></i> 默认未勾选任何菜单时,用户拥有全部权限)</span></div>
  123. <thead>
  124. <tr>
  125. <th colspan="4" class="text-left">
  126. <div class="">
  127. <input id="check-module" type="checkbox" name="module_select" we7-check-all="1" onChange="selectall(this, 'module_select')">
  128. <label for="check-module" class=" we7-margin-horizontal-none">应用权限</label>
  129. </div>
  130. </th>
  131. </tr>
  132. </thead>
  133. <tbody class="module_select system-select-box">
  134. {php $i=1;}
  135. {loop $module $k $m}
  136. {if empty($m['issystem'])}
  137. {if $i%4 == 1 || $i == 1}<tr>{/if}
  138. <td class="text-left vertical-middle" style="overflow:inherit;width:25%">
  139. <div class="dropdown system-select-dropdown">
  140. <span class="" data-id="{$k}">
  141. <input id="check-module-{$k}" type="checkbox" value="{$k}" name="module[]" we7-check-all="1" {if in_array($k, $module_permission_keys)}checked{/if}>
  142. <label for="check-module-{$k}" >{php echo mb_substr($m['title'], 0, 12, 'utf-8')}<span class="caret"></span></label>
  143. </span>
  144. <ul class="dropdown-menu" role="menu"></ul>
  145. <input type="hidden" name="{$k}_select" value="0"/>
  146. </div>
  147. </td>
  148. {if $i%4 == 0}</tr>{/if}
  149. {php $i++;}
  150. {/if}
  151. {/loop}
  152. {if ($i-1)%4 != 0}
  153. <?php
  154. for ($x=0; $x<4-($i-1)%4; $x++) {
  155. echo "<td></td>";
  156. }
  157. ?>
  158. </tr>
  159. {/if}
  160. </tbody>
  161. </table>
  162. {/if}
  163. <button type="submit" class="btn btn-primary span3" name="submit" value="提交" onclick="if ($('input:checkbox:checked').size() == 0) {return confirm('您未勾选任何菜单权限,意味着允许用户使用所有功能。确定吗?')}">提交</button>
  164. <input type="hidden" name="token" value="{$_W['token']}" />
  165. </form>
  166. <script>
  167. $(function(){
  168. var uniacid = "{$_GPC['uniacid']}";
  169. var acid = "{$_GPC['acid']}";
  170. //公众号OR小程序下拉框
  171. $('.account-and-wxapp .dropdown span').hover(function(){
  172. $(this).parent().addClass('open').find('.dropdown-menu').show();
  173. $(this).parent().find('.dropdown-menu').hover(
  174. function(){$(this).show();$(this).parent().addClass('open')},
  175. function(){$(this).hide();$(this).parent().removeClass('open');}
  176. );
  177. },function(){
  178. $(this).parent().removeClass('open').find('.dropdown-menu').hide();
  179. });
  180. //模块下拉框
  181. $('.module_select .dropdown span').hover(function(){
  182. var _this = $(this);
  183. var m = $(this).attr('data-id');
  184. var uid = "{$uid}";
  185. var length = $(this).next().find('li').size();
  186. if(!length) {
  187. _this.next().html('<div class="text-center"><i class="fa-spin wi wi-changing-over"></i> 获取子权限 </div>');
  188. $.post("{php echo url('account/post-user/module')}", {'m' : m, 'uid' : uid, 'uniacid' : uniacid, 'acid' : acid}, function(data) {
  189. if(!data.message.errno) {
  190. var li_nums = data.message.message.length;
  191. var li_checked = 0;
  192. var li_contents = '';
  193. var html = '';
  194. $.each(data.message.message, function(k, v){
  195. var check = '';
  196. if (v.checked) {
  197. check = 'checked';
  198. li_checked ++;
  199. }
  200. html += '<li><a href="javascript:;"><input id="check-moduledetail-'+m+'-'+k+'" we7-check-all="1" type="checkbox" name="module_'+m+'[]" value="'+ v.permission +'" '+check+'/><label for="check-moduledetail-'+m+'-'+k+'" class="we7-padding-left we7-margin-horizontal-none checkbox-inline">'+ v.title +'</label></a></li>';
  201. });
  202. if (li_nums == li_checked) {
  203. li_contents = '已全选';
  204. } else {
  205. li_contents = '已选' + li_checked + '项';
  206. }
  207. var _html = '<div><label class="checkbox-inline info">' + li_contents + '</label></div>';
  208. html = _html + '<ul>' + html + '</ul>';
  209. _this.next().html(html);
  210. } else {
  211. _this.next().html('<div class="text-center">无子权限</div>');
  212. }
  213. }, 'json');
  214. }
  215. $(this).parent().addClass('open').find('.dropdown-menu').show();
  216. $(this).parent().find('.dropdown-menu').hover(
  217. function(){$(this).show();$(this).parent().addClass('open')},
  218. function(){$(this).hide();$(this).parent().removeClass('open');}
  219. );
  220. },function(){
  221. $(this).parent().removeClass('open').find('.dropdown-menu').hide();
  222. });
  223. $('.dropdown span :checkbox').click(function(e){
  224. var _parent = $(this).parents('.dropdown');
  225. _parent.find('.dropdown-menu :checkbox').prop('checked', $(this).prop('checked'));
  226. if($(this).prop('checked')) {
  227. _parent.find('label.info').html('已全选');
  228. _parent.find('input[type="hidden"]').val(1);
  229. } else {
  230. _parent.find('input[type="hidden"]').val(0);
  231. _parent.find('label.info').html('已选0项');
  232. }
  233. });
  234. $('.dropdown-menu').on('click', ':checkbox', function(){
  235. if(!$(this).prop('checked')) {
  236. var i = 0;
  237. $.each($(this).parents('li').siblings(), function(){
  238. if($(this).find(':checkbox').prop('checked')) {
  239. i ++;
  240. }
  241. });
  242. $(this).parents('.dropdown').find('input[type="hidden"]').val(0);
  243. $(this).parents('.dropdown').find('label.info').html('已选' + i + '项');
  244. if(!i) {
  245. $(this).parents('.dropdown').find('span :checkbox').prop('checked', false);
  246. }
  247. } else {
  248. var flag = 0;
  249. var i = 1;
  250. $.each($(this).parents('li').siblings(), function(){
  251. if(!$(this).find(':checkbox').prop('checked')) {
  252. flag = 1;
  253. } else {
  254. i ++;
  255. }
  256. });
  257. if(!flag) {
  258. $(this).parents('.dropdown').find('label.info').html('已全选');
  259. $(this).parents('.dropdown').find('input[type="hidden"]').val(1);
  260. } else {
  261. $(this).parents('.dropdown').find('label.info').html('已选' + i + '项');
  262. $(this).parents('.dropdown').find('input[type="hidden"]').val(0);
  263. }
  264. $(this).parents('.dropdown').find('span :checkbox').prop('checked', true);
  265. }
  266. });
  267. });
  268. //处理全选函数
  269. function selectall(obj, a){
  270. $('.'+a+' input:checkbox').each(function() {
  271. $(this)[0].checked = obj.checked ? true : false;
  272. });
  273. }
  274. //当已经全选时,默认全选按钮选中
  275. $(function() {
  276. $('.table>tbody').each(function() {
  277. var a = true;
  278. $(this).find('input:checkbox').each(function() {
  279. if($(this)[0].checked != true) {
  280. a = false;
  281. return false;
  282. }
  283. });
  284. if(a) $('input[name='+$(this).attr('class')+']:checkbox')[0].checked = true;
  285. });
  286. });
  287. </script>
  288. {template 'common/footer'}