role.php 14 KB

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