role.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. <?php
  2. /*
  3. |--------------------------------------------------------------------------
  4. | role.php 角色表
  5. |--------------------------------------------------------------------------
  6. */
  7. # 定义几个常用的选项
  8. $option = array
  9. (
  10. 1 => '可用',
  11. 2 => '不可用',
  12. );
  13. # 获取头部菜单list 建议这里使用匿名函数
  14. $top = function()
  15. {
  16. $data = Dever::load('manage/top.all');
  17. $data['state'] = 1;
  18. return $data;
  19. };
  20. # 操作权限控制
  21. $oper = array
  22. (
  23. 1 => '列表',
  24. 2 => '搜索',
  25. 3 => '编辑',
  26. 4 => '新增',
  27. 5 => '删除',
  28. 6 => '其他',
  29. );
  30. # 是否只能管理自己发布的内容
  31. $self = array
  32. (
  33. 1 => '是',
  34. 2 => '否',
  35. );
  36. # 获取当前登录管理员的所属角色,除id为1外,其余的角色只能管理本角色级别之下的子角色
  37. $cur = Dever::load('manage/auth.data');
  38. //print_r($cur);die;
  39. $desc = '';
  40. if($cur['role'] > 1)
  41. {
  42. $desc = $cur['username'] . ',你好,你可以在此管理你的下属角色';
  43. # 配置当前列表页的参数
  44. Dever::$global['model']['manage/role-all'] = Dever::$global['model']['manage/role-list'] = array
  45. (
  46. 'option_role_id' => $cur['role'],
  47. );
  48. $temp = explode(',', $cur['oper']);
  49. foreach($oper as $k => $v)
  50. {
  51. if(!in_array($k, $temp))
  52. {
  53. unset($oper[$k]);
  54. }
  55. }
  56. }
  57. # 获取权限list 建议这里使用匿名函数
  58. $auth = function() use($cur)
  59. {
  60. if($cur['role'] > 1)
  61. {
  62. $auth = Dever::load('manage/auth.get', false);
  63. }
  64. else
  65. {
  66. $auth = Dever::load('manage/auth.get', true);
  67. }
  68. return $auth;
  69. };
  70. $role = function() use($cur)
  71. {
  72. $param = $array = array();
  73. if($cur['role'] > 1)
  74. {
  75. $param['option_id'] = $cur['role'];
  76. }
  77. else
  78. {
  79. $array = array(-1 => array('name' => '无'));
  80. }
  81. $data = Dever::load('manage/role-main', $param);
  82. if($data)
  83. {
  84. $array += $data;
  85. }
  86. return $array;
  87. };
  88. # 获取权限list 建议这里使用匿名函数
  89. $auth_data = function()
  90. {
  91. $auth_data = Dever::load('manage/auth.getByData');
  92. return $auth_data;
  93. };
  94. //print_r($auth);die;
  95. $config = array
  96. (
  97. # 表名
  98. 'name' => 'role',
  99. # 显示给用户看的名称
  100. 'lang' => '管理角色设置',
  101. 'desc' => $desc,
  102. 'order' => 8,
  103. # 表类型 值为\innodb\myisam\,默认为innodb,仅在mysql类型有效
  104. 'type' => 'innodb',
  105. # 数据结构
  106. 'struct' => array
  107. (
  108. 'id' => array
  109. (
  110. 'type' => 'int-11',
  111. 'name' => '角色ID',
  112. 'default' => '',
  113. 'desc' => '',
  114. 'match' => 'is_numeric',
  115. 'search' => 'order',
  116. 'list' => true,
  117. ),
  118. 'hr0' => array
  119. (
  120. 'name' => '基本设置',
  121. 'class' => '',//本项必须填写
  122. 'attr' => '',
  123. ),
  124. 'name' => array
  125. (
  126. 'type' => 'varchar-24',
  127. 'name' => '角色名',
  128. 'default' => '',
  129. 'desc' => '请输入角色名',
  130. 'match' => 'is_string',
  131. 'update' => 'text',
  132. 'search' => 'fulltext',
  133. 'list_name' => '角色名',//定义列表页的名称
  134. 'list' => true,
  135. 'edit' => true,
  136. ),
  137. 'role_id' => array
  138. (
  139. 'type' => 'int-11',
  140. 'name' => '上级角色',
  141. 'default' => '-1',
  142. 'desc' => '请选择上级角色',
  143. 'match' => 'is_numeric',
  144. 'update' => 'select',
  145. 'search' => 'order,select',
  146. 'list' => '{role_id}',
  147. 'option' => $role,
  148. 'edit' => true,
  149. ),
  150. 'self' => array
  151. (
  152. 'type' => 'tinyint-1',
  153. 'name' => '是否只能管理自己发布的内容-请在需要此项权限的表中增加[数据查询时影响的字段]',
  154. 'default' => '2',
  155. 'desc' => '请选择是否只能管理自己发布的内容',
  156. 'match' => 'option',
  157. 'update' => 'radio',
  158. 'option' => $self,
  159. 'auth' => '"{my_role_id}"==1',
  160. ),
  161. 'col_select' => array
  162. (
  163. 'type' => 'varchar-30',
  164. 'name' => '数据查询时影响的字段-该项影响数据查询,如果在表中增加该字段,则后台在查询数据时自动查询当前管理员的id下的数据,多个用逗号隔开,与[是否只能管理自己发布的内容]相关',
  165. 'default' => 'admin_founder',
  166. 'desc' => '数据更新时影响的字段',
  167. 'match' => 'option',
  168. 'update' => 'text',
  169. 'auth' => '"{my_role_id}"==1',
  170. ),
  171. 'col_insert' => array
  172. (
  173. 'type' => 'varchar-30',
  174. 'name' => '数据插入时影响的字段-该项影响数据插入,如果在表中增加该字段,则后台操作时自动为该字段赋值为当前管理员的id,多个用逗号隔开',
  175. 'default' => 'admin_founder',
  176. 'desc' => '数据插入时影响的字段',
  177. 'match' => 'option',
  178. 'update' => 'text',
  179. 'auth' => '"{my_role_id}"==1',
  180. ),
  181. 'col_update' => array
  182. (
  183. 'type' => 'varchar-30',
  184. 'name' => '数据更新时影响的字段-该项影响数据更新,如果在表中增加该字段,则后台操作时自动为该字段赋值为当前管理员的id,多个用逗号隔开',
  185. 'default' => 'admin_editor',
  186. 'desc' => '数据更新时影响的字段',
  187. 'match' => 'option',
  188. 'update' => 'text',
  189. 'auth' => '"{my_role_id}"==1',
  190. ),
  191. /*
  192. //启用复制其他字段的值
  193. 'testname' => array
  194. (
  195. 'type' => 'varchar-24',
  196. 'name' => '角色名',
  197. 'default' => '',
  198. 'desc' => '请输入角色名',
  199. 'match' => 'is_string',
  200. 'update' => 'copy.name',//直接复制name的值
  201. 'search' => 'order,fulltext',
  202. 'list' => true,
  203. ),
  204. //当前的字段属于另外一个表,主要不要有type
  205. 'manage-role_test-name'=> array
  206. (
  207. 'name' => '测试名',
  208. 'default' => '',
  209. 'desc' => '请输入角色名',
  210. 'match' => 'option',
  211. 'update' => 'text',//直接复制name的值
  212. # 同步更新另外一个表的内容,两个表相关联的id,更新另一个表的字段
  213. 'sync' => array('id', 'role_id'),
  214. 'list' => true,
  215. ),
  216. */
  217. #设置分割条
  218. /*
  219. 'hr1' => array
  220. (
  221. 'name' => '基本信息',
  222. 'class' => '',//本项必须填写
  223. 'attr' => '',
  224. ),
  225. */
  226. 'oper' => array
  227. (
  228. 'type' => 'varchar-24',
  229. 'name' => '操作权限',
  230. 'default' => array(1,2,3),
  231. 'desc' => '请选择操作权限',
  232. 'match' => 'is_string',
  233. 'update' => 'checkbox',
  234. 'option' => $oper,
  235. ),
  236. 'hr1' => array
  237. (
  238. 'name' => '菜单权限设置',
  239. 'class' => '',//本项必须填写
  240. 'attr' => '',
  241. ),
  242. 'auth' => array
  243. (
  244. 'type' => 'text-255',
  245. 'name' => '左侧菜单',
  246. 'default' => '',
  247. 'desc' => '请选择左侧菜单',
  248. 'match' => 'option',
  249. 'update' => 'checkbox',
  250. //每个项对应的一个input以及父级更新的类型
  251. //'update_input' => '数量',
  252. //'update_parent' => 'radio',
  253. 'option' => $auth,
  254. ),
  255. 'top' => array
  256. (
  257. 'type' => 'text-255',
  258. 'name' => '头部菜单',
  259. 'default' => '',
  260. 'desc' => '请选择头部菜单',
  261. 'match' => 'option',
  262. 'update' => 'checkbox',
  263. 'option' => $top,
  264. ),
  265. 'auth_data' => array
  266. (
  267. 'type' => 'text-255',
  268. 'name' => '数据权限',
  269. 'default' => '',
  270. 'desc' => '数据权限',
  271. 'match' => 'option',
  272. 'update' => 'checkbox',
  273. //每个项对应的一个input以及父级更新的类型
  274. //'update_input' => '数量',
  275. //'update_parent' => 'radio',
  276. 'option' => $auth_data,
  277. ),
  278. ),
  279. # 更新表结构 请注意,新增字段已经无需在此增加add了,直接在struct中新增即可。如果是更新字段和删除字段,还需在此加相应配置,并且修改最新的版本号。
  280. /*
  281. 'alter' => array
  282. (
  283. 1 => array
  284. (
  285. array('add', 'top', 'top', 'text-255 头部菜单'),//新增字段
  286. array('update', 't1', 't2', 'text-255 头部菜单'),//更新字段
  287. array('delete', 't1'), //删除字段
  288. ),
  289. 'version' => 1,
  290. ),
  291. */
  292. # 默认值
  293. 'default' => array
  294. (
  295. 'col' => 'name,oper,auth,role_id,col_update,col_insert,col_select,state,cdate',
  296. 'value' => array
  297. (
  298. '"系统管理员","1,2,3,4,5","all",-1,"admin","admin","admin",1,' . time(),
  299. '"普通管理员","1,2,3,4,5","",-1,"admin","admin","admin",1,' . time(),
  300. ),
  301. ),
  302. # 索引
  303. /*
  304. 'index' => array
  305. (
  306. 1 => array
  307. (
  308. # 索引名 => 索引id 如果有后缀.unique,则为建立索引的类型,如id,state.unique
  309. 'id' => 'id,state',
  310. ),
  311. # 版本号 更改版本号会更新当前表的索引
  312. 'version' => 1,
  313. ),
  314. */
  315. # 头部菜单权限管理
  316. //'auth' => 'customer-project',
  317. # 后台管理 此处的功能全部开放
  318. 'manage' => array
  319. (
  320. # 自定义列表页面
  321. //'page_list' => 'test',
  322. # 自定义页面
  323. /*
  324. 'page' => 'test',
  325. # 后台banner
  326. 'banner' => array
  327. (
  328. 'img' => 'Dever::load("project/data.customer#img")',
  329. 'name' => 'Dever::load("project/data.customer#name")',
  330. ),
  331. */
  332. # 更新数据时,要显示的按钮,这里填写js脚本事件即可。保存当前数据可为固定参数:"save-data",复制数据为:copy-data
  333. /*
  334. 'update_button' => array
  335. (
  336. '提交保存' => 'save-data',
  337. '放弃保存' => "msg({status:1,msg:'yes'})",
  338. '复制数据' => 'copy-datas',
  339. ),
  340. */
  341. # 列表页的类型
  342. //'list_type' => 'parent',
  343. # 启动自动保存功能
  344. //'save' => true,
  345. # 启动预览功能
  346. 'preview' => true,
  347. # 开启报表下载
  348. # 涉及到报表下载,如果想使用phpexcel,请用composer安装phpexcel:require中添加 ,"phpoffice/phpexcel": "1.8.1",
  349. # 否则请使用框架自带的csv
  350. 'excel' => true,
  351. # 开启批量管理
  352. 'mul' => true,
  353. # 开启主动统计,需要人工选择选项来确定统计的项,有别于被动统计,实现中
  354. //'stat' => 'top,auth,state,oper,role_id,reorder',//值为不显示的字段,无需输入id和cdate
  355. # 列表页每个元素管理下的button,其中'update'为编辑、'delete'为删除,其他可以自定义。
  356. 'list_button' => array('update' => '编辑'),
  357. # 列表头部的button,多个直接添加字段即可
  358. 'button' => array
  359. (
  360. //'更新接口' => 'manage/api.update',
  361. )
  362. ),
  363. # request 请求接口定义
  364. 'request' => array
  365. (
  366. # all 取所有数据
  367. 'alls' => array
  368. (
  369. # 匹配的正则或函数 选填项
  370. 'option' => array
  371. (
  372. 'name' => array('is_string', 'like'),
  373. 'state' => 1,
  374. ),
  375. 'type' => 'all',
  376. 'order' => array('id', 'desc'),
  377. 'col' => '*,name as value,name as label|id',//这里为了做autocomplete进行测试,必须输出value和label
  378. ),
  379. # main 取所有主栏目
  380. 'main' => array
  381. (
  382. 'where' => array
  383. (
  384. //'role_id' => -1,
  385. 'state' => 1,
  386. ),
  387. 'option' => array
  388. (
  389. 'id' => array('yes', 'in'),
  390. ),
  391. 'type' => 'all',
  392. 'order' => array('reorder` desc,`id', 'desc'),
  393. 'col' => '*|id',
  394. ),
  395. # 取所有下级栏目
  396. 'child' => array
  397. (
  398. 'where' => array
  399. (
  400. 'role_id' => array('1', '>='),
  401. 'state' => 1,
  402. ),
  403. 'type' => 'all',
  404. 'order' => array('reorder` desc,`id', 'desc'),
  405. 'col' => '*|role_id|id|',
  406. ),
  407. # 带有*号前缀的,可以直接接口访问
  408. '*get' => array
  409. (
  410. # 匹配的正则或函数 选填项
  411. 'where' => array
  412. (
  413. 'id' => array('is_string', 'in'),
  414. ),
  415. 'type' => 'all',
  416. 'order' => array('id', 'desc'),
  417. 'col' => '*',
  418. ),
  419. # get 根据role的id取多条数据
  420. 'get' => array
  421. (
  422. # 匹配的正则或函数 选填项
  423. 'where' => array
  424. (
  425. 'id' => array('is_string', 'in'),
  426. ),
  427. 'type' => 'all',
  428. 'order' => array('id', 'desc'),
  429. 'col' => '*|id',
  430. ),
  431. ),
  432. );
  433. $project = Dever::load('manage/auth-project');
  434. #Dever::debug('test');
  435. if($project)
  436. {
  437. $config['struct']['hr2'] = array
  438. (
  439. 'name' => '项目精细权限设置',
  440. 'class' => '',//本项必须填写
  441. 'attr' => '',
  442. );
  443. $project_auth = Dever::load('manage/auth.all');
  444. foreach($project as $k => $v)
  445. {
  446. $config['struct']['auth_' . $v['project']] = array
  447. (
  448. 'type' => 'text-255',
  449. 'name' => $v['project_name'] . '下的权限设置',
  450. 'default' => '',
  451. 'desc' => '请选择' . $v['project_name'] . '下的权限设置',
  452. 'match' => 'option',
  453. 'update' => 'checkbox',
  454. 'option' => $project_auth[$v['project']],
  455. );
  456. }
  457. }
  458. $config['struct']['reorder'] = array
  459. (
  460. 'type' => 'int-11',
  461. 'name' => '排序-数值越大越靠前',
  462. 'default' => '1',
  463. 'desc' => '请输入排序',
  464. 'match' => 'option',
  465. 'update' => 'text',
  466. 'search' => 'order',
  467. 'list' => true,
  468. 'order' => 'desc',
  469. 'edit' => true,
  470. );
  471. $config['struct']['state'] = array
  472. (
  473. 'type' => 'tinyint-1',
  474. 'name' => '状态',
  475. 'default' => '1',
  476. 'desc' => '请选择状态',
  477. 'match' => 'is_numeric',
  478. //'option' => $option,
  479. //'update' => 'radio',
  480. //'list' => true,
  481. /*
  482. //启用位运算,仅支持与操作,数据保存时,将从0开始加起,一般用于站点之类的保存,慎用,测试需将radio改成checkbox
  483. 'bit' => array
  484. (
  485. 1 => 1,//1为对应的值,100为保存到数据库中的值
  486. 2 => 10,
  487. //4 => 100,
  488. ),
  489. */
  490. );
  491. $config['struct']['status'] = array
  492. (
  493. 'type' => 'tinyint-1',
  494. 'name' => '状态',
  495. 'default' => '1',
  496. 'desc' => '请选择状态',
  497. 'match' => 'is_numeric',
  498. 'option' => $option,
  499. //'update' => 'radio',
  500. //'list' => true,
  501. //'edit' => true,
  502. /*
  503. //启用位运算,仅支持与操作,数据保存时,将从0开始加起,一般用于站点之类的保存,慎用,测试需将radio改成checkbox
  504. 'bit' => array
  505. (
  506. 1 => 1,//1为对应的值,100为保存到数据库中的值
  507. 2 => 10,
  508. //4 => 100,
  509. ),
  510. */
  511. );
  512. $config['struct']['cdate'] = array
  513. (
  514. 'type' => 'int-11',
  515. 'name' => '录入时间',
  516. 'match' => array('is_numeric', time()),
  517. 'desc' => '',
  518. # 只有insert时才生效
  519. 'insert' => true,
  520. # 加入搜索时间区间段
  521. 'search' => 'date',
  522. 'list' => 'date("Y-m-d H:i:s", {cdate})',
  523. );
  524. return $config;