role.php 13 KB

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