addrole.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <?php $shoname_name = D('Home/Front')->get_config_by_name('shoname'); ?>
  6. <title><?php echo $shoname; ?></title>
  7. <link rel="shortcut icon" href="" />
  8. <meta name="renderer" content="webkit">
  9. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  10. <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  11. <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
  12. <!-- 让IE8/9支持媒体查询,从而兼容栅格 -->
  13. <!--[if lt IE 9]>
  14. <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
  15. <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
  16. <![endif]-->
  17. <link href="./resource/css/bootstrap.min.css?v=201903260001" rel="stylesheet">
  18. <link href="./resource/css/common.css?v=201903260001" rel="stylesheet">
  19. <script type="text/javascript">
  20. window.sysinfo = {
  21. <?php if (!empty($_W['uniacid']) ){ ?>'uniacid': '{$_W['uniacid']}',<?php } ?>
  22. <?php if( !empty($_W['acid']) ){ ?>'acid': '{$_W['acid']}',<?php } ?>
  23. <?php if (!empty($_W['openid']) ) { ?>'openid': '{$_W['openid']}',<?php } ?>
  24. <?php if( !empty($_W['uid']) ) { ?>'uid': '{$_W['uid']}',<?php } ?>
  25. 'isfounder': <?php if (!empty($_W['isfounder']) ) { ?>1<?php }else{ ?>0<?php } ?>,
  26. 'siteroot': '{$_W['siteroot']}',
  27. 'siteurl': '{$_W['siteurl']}',
  28. 'attachurl': '{$_W['attachurl']}',
  29. 'attachurl_local': '{$_W['attachurl_local']}',
  30. 'attachurl_remote': '{$_W['attachurl_remote']}',
  31. 'module' : {'url' : '<?php if( defined('MODULE_URL') ) { ?>{MODULE_URL}<?php } ?>', 'name' : '<?php if (defined('IN_MODULE') ) { ?>{IN_MODULE}<?php } ?>'},
  32. 'cookie' : {'pre': ''},
  33. 'account' : {:json_encode($_W['account'])},
  34. };
  35. </script>
  36. <script type="text/javascript" src="./resource/js/lib/jquery-1.11.1.min.js"></script>
  37. <script type="text/javascript" src="./resource/js/lib/bootstrap.min.js"></script>
  38. <script type="text/javascript" src="./resource/js/app/util.js?v=201903260001"></script>
  39. <script type="text/javascript" src="./resource/js/app/common.min.js?v=201903260001"></script>
  40. <script type="text/javascript" src="./resource/js/require.js?v=201903260001"></script>
  41. <script type="text/javascript" src="./resource/js/lib/jquery.nice-select.js?v=201903260001"></script>
  42. <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
  43. <link href="/static/css/snailfish.css" rel="stylesheet">
  44. </head>
  45. <body layadmin-themealias="default">
  46. <div class="layui-fluid">
  47. <div class="layui-card">
  48. <div class="layui-card-header layui-elem-quote">当前位置:<span class="line-text">
  49. <?php if( !empty($item['id']) ){ ?>编辑<?php }else{ ?>添加<?php } ?>角色 <small><?php if(!empty($item['id'])){ ?>修改【{$item['rolename']}】<?php } ?></small>
  50. </span></div>
  51. <div class="layui-card-body" style="padding:15px;">
  52. <form action="" method="post" class="layui-form" lay-filter="component-layui-form-item" enctype="multipart/form-data" >
  53. <input type="hidden" name="id" value="{$item['id']}" />
  54. <div class="layui-form-item">
  55. <label class="layui-form-label must">角色</label>
  56. <div class="layui-input-block">
  57. <input type="text" name="rolename" class="form-control" value="{$item['rolename']}" data-rule-required="true" />
  58. </div>
  59. </div>
  60. <div class="layui-form-item">
  61. <label class="layui-form-label">状态</label>
  62. <div class="layui-input-block">
  63. <label class='radio-inline'>
  64. <input type='radio' name='status' value=1' <?php if($item['status']==1){ ?>checked<?php } ?> title="启用" />
  65. </label>
  66. <label class='radio-inline'>
  67. <input type='radio' name='status' value=0' <?php if($item['status']==0){ ?>checked<?php } ?> title="禁用" />
  68. </label>
  69. <span class="help-block">如果禁用,则当前角色的操作员全部会禁止使用</span>
  70. </div>
  71. </div>
  72. <!-- perm begin -->
  73. <div class="layui-form-item">
  74. <label class="layui-form-label">可用权限</label>
  75. <div class="layui-input-block">
  76. <div id="accordion" class="panel-group">
  77. <div class='panel panel-default' >
  78. <?php $i = 0; ?>
  79. <?php foreach($perms['parent'] as $key => $value){ ?>
  80. <div class='panel-heading' style='background:#f8f8f8' >
  81. <a class="btn btn-link btn-sm pull-right" data-toggle="collapse" data-parent="#accordion" href="#collapse{$key}"><i class='fa fa-angle-down'></i> 展开</a>
  82. <label class='checkbox-inline'>
  83. <input type='checkbox' lay-ignore id="perm_{$key}" name='perms[]' value='{$key}' class='perm-all' data-group='{$key}'
  84. <?php if(in_array($key,$role_perms) || in_array($key,$user_perms)){ ?> checked<?php } ?>
  85. <?php if(in_array($key,$role_perms) && $action=='perm.user'){ ?> disabled<?php } ?>
  86. / title=""> {$value['text']}
  87. </label>
  88. </div>
  89. <div id="collapse{$key}" class="panel-collapse <?php if($i == 0){ ?>in<?php }else{ ?>collapse<?php } ?>">
  90. <div class='panel-body perm-group'>
  91. <?php if( count($perms['parent'][$key]) >=1 ){ ?>
  92. <span>
  93. <?php foreach($perms['parent'][$key] as $ke => $val){ ?>
  94. <?php if($ke != 'text'){ ?>
  95. <label class='checkbox-inline'>
  96. <input type='checkbox' lay-ignore name='perms[]' value='{$key}.{$ke}' class='perm-item'
  97. data-group='{$key}' data-parent='text'
  98. <?php if(in_array($key.".".$ke,$role_perms) || in_array($key.".".$ke,$user_perms)){ ?> checked<?php } ?>
  99. <?php if(in_array($key.".".$ke,$role_perms) && $action=='perm.user'){ ?> disabled<?php } ?> title=""/> <?php echo str_replace("-log", "", $val); ?>
  100. </label>
  101. <?php }else{ ?>
  102. <label class='checkbox-inline'>
  103. <input type='checkbox' lay-ignore name='perms[]' value='{$key}' class='perm-all-item'
  104. data-group='{$key}' data-parent='text'
  105. <?php if(in_array($key,$role_perms) || in_array($key,$user_perms)){ ?> checked<?php } ?>
  106. <?php if(in_array($key,$role_perms) && $action=='perm.user'){ ?> disabled<?php } ?> title=""/><?php echo str_replace("-log", "", $val); ?>
  107. </label>
  108. <?php } ?>
  109. </span>
  110. <br>
  111. <?php } ?>
  112. <?php } ?>
  113. <?php foreach($perms['son'][$key] as $ke => $val){ ?>
  114. <?php if( count($val) >=1 ){ ?>
  115. <span>
  116. <?php foreach($val as $k => $v){ ?>
  117. <?php if($k != 'text'){ ?>
  118. <label class='checkbox-inline'>
  119. <input type='checkbox' lay-ignore name='perms[]' value='{$key}.{$ke}.{$k}' class='perm-item'
  120. data-group='{$key}' data-parent='{$ke}' data-son="{$k}"
  121. <?php if( in_array($key.".".$ke.".".$k,$role_perms) || in_array($key.".".$ke.".".$k,$user_perms) ){ ?> checked<?php } ?>
  122. <?php if(in_array($key.".".$ke.".".$k,$role_perms) && $action=='perm.user'){ ?> disabled<?php } ?> title=""/><?php echo str_replace("-log", "", $v); ?>
  123. </label>
  124. <?php }else{ ?>
  125. <label class='checkbox-inline'>
  126. <input type='checkbox' lay-ignore name='perms[]' value='{$key}.{$ke}' class='perm-all-item'
  127. data-group='{$key}' data-parent='{$ke}' data-son="{$k}"
  128. <?php if( in_array($key.".".$ke,$role_perms) || in_array($key.".".$ke,$user_perms) ){ ?> checked<?php } ?>
  129. <?php if(in_array($key.".".$ke,$role_perms) && $action=='perm.user'){ ?> disabled<?php } ?> title=""/> <?php echo str_replace("-log", "", $v); ?>
  130. </label>
  131. <?php } ?>
  132. <?php } ?>
  133. </span>
  134. <br>
  135. <?php } ?>
  136. <?php } ?>
  137. <?php foreach($perms['grandson'][$key] as $ke => $val){ ?>
  138. <?php foreach($val as $k => $v){ ?>
  139. <?php if( count($v) >1 ){ ?>
  140. <span>
  141. <?php foreach($v as $kk => $vv){ ?>
  142. <?php if($kk != 'text'){ ?>
  143. <label class='checkbox-inline'>
  144. <input type='checkbox' lay-ignore name='perms[]' value='{$key}.{$ke}.{$k}.{$kk}' class='perm-item'
  145. data-group='{$key}' data-parent='{$ke}' data-son="{$k}" data-grandson="{$kk}"
  146. <?php if(in_array($key.".".$ke.".".$k.".".$kk,$role_perms) || in_array($key.".".$ke.".".$k.".".$kk,$user_perms)){ ?> checked<?php } ?>
  147. <?php if(in_array($key.".".$ke.".".$k.".".$kk,$role_perms) && $action =='perm.user'){ ?> disabled<?php } ?> title=""/><?php echo str_replace("-log", "", $vv); ?>
  148. </label>
  149. <?php }else{ ?>
  150. <label class='checkbox-inline'>
  151. <input type='checkbox' lay-ignore name='perms[]' value='{$key}.{$ke}.{$k}' class='perm-all-item'
  152. data-group='{$key}' data-parent='{$ke}' data-son="{$k}" data-grandson="{$kk}"
  153. <?php if( in_array($key.".".$ke.".".$k,$role_perms) || in_array($key.".".$ke.".".$k,$user_perms) ){ ?> checked<?php } ?>
  154. <?php if(in_array($key.".".$ke.".".$k,$role_perms) && $action=='perm.user'){ ?> disabled<?php } ?> title=""/><?php echo str_replace("-log", "", $vv); ?>
  155. </label>
  156. <?php } ?>
  157. <?php } ?>
  158. </span>
  159. <br>
  160. <?php } ?>
  161. <?php } ?>
  162. <?php } ?>
  163. </div>
  164. </div>
  165. <?php $i++; ?>
  166. <?php } ?>
  167. </div>
  168. </div>
  169. </div>
  170. </div>
  171. <div class="layui-form-item">
  172. <label class="layui-form-label"> </label>
  173. <div class="layui-input-block">
  174. <input type="submit" value="提交" lay-submit lay-filter="formDemo" class="btn btn-primary" />
  175. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  176. </div>
  177. </div>
  178. </form>
  179. </div>
  180. </div>
  181. </div>
  182. <script src="/layuiadmin/layui/layui.js"></script>
  183. <script>
  184. layui.config({
  185. base: '/layuiadmin/' //静态资源所在路径
  186. }).extend({
  187. index: 'lib/index' //主入口模块
  188. }).use('index');
  189. </script>
  190. <script>
  191. var layer = layui.layer;
  192. var $;
  193. var cur_open_div;
  194. layui.use(['jquery', 'layer','form'], function(){
  195. $ = layui.$;
  196. var form = layui.form;
  197. form.on('radio(linktype)', function(data){
  198. if (data.value == 2) {
  199. $('#typeGroup').show();
  200. } else {
  201. $('#typeGroup').hide();
  202. }
  203. });
  204. $('#chose_link').click(function(){
  205. cur_open_div = $(this).attr('data-input');
  206. $.post("{:U('util.selecturl', array('ok' => 1))}", {}, function(shtml){
  207. layer.open({
  208. type: 1,
  209. area: '930px',
  210. content: shtml //注意,如果str是object,那么需要字符拼接。
  211. });
  212. });
  213. })
  214. form.verify({
  215. title: [
  216. /^[\S]{1,}$/,'标题不能为空'
  217. ]
  218. });
  219. //监听提交
  220. form.on('submit(formDemo)', function(data){
  221. $.ajax({
  222. url: data.form.action,
  223. type: data.form.method,
  224. data: data.field,
  225. dataType:'json',
  226. success: function (info) {
  227. if(info.status == 0)
  228. {
  229. layer.msg(info.result.message,{icon: 1,time: 2000});
  230. }else if(info.status == 1){
  231. var go_url = location.href;
  232. if( info.result.hasOwnProperty("url") )
  233. {
  234. go_url = info.result.url;
  235. }
  236. layer.msg('操作成功',{time: 1000,
  237. end:function(){
  238. location.href = info.result.url;
  239. }
  240. });
  241. }
  242. }
  243. });
  244. return false;
  245. });
  246. })
  247. </script>
  248. <script language="javascript">
  249. $(function () {
  250. $('.perm-all').click(function () {
  251. var checked = $(this).get(0).checked;
  252. var group = $(this).data('group');
  253. $(".perm-item[data-group='" + group + "'],.perm-all-item[data-group='" + group + "']").each(function () {
  254. $(this).get(0).checked = checked;
  255. })
  256. })
  257. $('.perm-all-item').click(function () {
  258. var checked = $(this).get(0).checked;
  259. var group = $(this).data('group');
  260. var parent = $(this).data('parent');
  261. var son = $(this).data('son');
  262. var grandson = $(this).data('grandson');
  263. $(this).parents("span").find(".perm-item").each(function () {
  264. $(this).get(0).checked = checked;
  265. });
  266. group_check(this);
  267. });
  268. $('.perm-item').click(function () {
  269. var group = $(this).data('group');
  270. var parent = $(this).data('parent');
  271. var son = $(this).data('son');
  272. var grandson = $(this).data('grandson');
  273. var check = false;
  274. $(this).closest('span').find(".perm-item").each(function () {
  275. if ($(this).get(0).checked) {
  276. check = true;
  277. return false;
  278. }
  279. });
  280. var allitem = $(this).parents("span").find(".perm-all-item");
  281. if (allitem.length == 1) {
  282. allitem.get(0).checked = check;
  283. }
  284. group_check(this);
  285. });
  286. $(".panel-body").find("span").each(function (index, item) {
  287. if ($(this).find("label").length != 1) {
  288. $($(this).find("label").get(0)).wrap("<div class='col-sm-2' style='white-space:nowrap;'></div>");
  289. $($(this).find("label").not($(this).find("label").get(0))).wrapAll("<div class='col-sm-10'></div>");
  290. }
  291. else {
  292. $($(this).find("label").get(0)).wrap("<div class='col-sm-12'></div>");
  293. }
  294. });
  295. });
  296. function group_check(obj) {
  297. var check = false;
  298. $(obj).parents('.perm-group').find(":checkbox").each(function (index, item) {
  299. if (item.checked) {
  300. check = true;
  301. }
  302. });
  303. var group = $(obj).eq(0).data('group');
  304. $(".perm-all[data-group=" + group + "]").get(0).checked = check;
  305. }
  306. </script>
  307. </body>
  308. </html>