admin.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. <?php
  2. /*
  3. |--------------------------------------------------------------------------
  4. | admin.php 管理员表
  5. |--------------------------------------------------------------------------
  6. */
  7. # 定义几个常用的选项
  8. $status = array
  9. (
  10. 1 => '普通',
  11. 2 => '封禁',
  12. );
  13. $cur = Dever::load('manage/auth.data', false);
  14. $desc = '';
  15. if($cur['role'] > 1)
  16. {
  17. $desc = $cur['username'] . ',你好,你可以在此管理你的下属账号';
  18. $child = array_keys(Dever::db('manage/role')->all());
  19. $admin = Dever::db('manage/admin_role')->list(array
  20. (
  21. 'col' => 'admin_id|admin_id',
  22. 'option' => array
  23. (
  24. 'role_id' => array('yes', 'in'),
  25. ),
  26. 'option_role_id' => implode(',', $child),
  27. ));
  28. # 配置当前列表页的参数 只能查看自己下属的管理员
  29. Dever::$global['model']['manage/admin-list'] = array
  30. (
  31. 'option' => array
  32. (
  33. 'id' => array('yes', 'in'),
  34. ),
  35. 'option_id' => $admin ? array_keys($admin) : -1,
  36. );
  37. }
  38. $role = function()
  39. {
  40. return Dever::load('manage/role-all');
  41. };
  42. $group = function()
  43. {
  44. return Dever::load('manage/group-all');
  45. };
  46. $config = function()
  47. {
  48. return Dever::load('manage/config-all');
  49. };
  50. # 获取头部菜单list 建议这里使用匿名函数
  51. $top = function()
  52. {
  53. $data = Dever::load('manage/top.all');
  54. $data['state'] = 1;
  55. return $data;
  56. };
  57. return array
  58. (
  59. # 表名
  60. 'name' => 'admin',
  61. # 显示给用户看的名称
  62. 'lang' => '管理账户设置',
  63. 'desc' => $desc,
  64. # 这个表不使用cache功能
  65. //'cache' => false,
  66. /*
  67. # 用到哪个后台菜单上,对应项目的key
  68. 'menu' => 'project_niuyou_main',
  69. # 后台菜单排序
  70. 'order' => 10,
  71. # 显示到后台快捷发布中,值为排序
  72. 'fast' => 1,
  73. */
  74. 'order' => 9,
  75. # 检测email必须唯一
  76. 'check' => 'email',
  77. # 同步更新另外一个或多个表的多条关联数据,以逗号隔开
  78. 'sync' => array
  79. (
  80. 'manage/admin_role' => array
  81. (
  82. # 更新时的条件,另外一个表的字段 => 本表的字段
  83. 'where' => array('admin_id' => 'id'),
  84. # 要更新的数据
  85. 'update' => array('role_id' => 'role'),
  86. # 同步更新的类型,delete为先删再插入,update为先查询是否存在,存在直接更新,不存在则插入, only为仅更新
  87. 'type' => 'delete',
  88. )
  89. ),
  90. # 同步更新另外一个或多个表的一条关联数据
  91. /*
  92. 'syncone' => array
  93. (
  94. 'manage/admin_role' => array
  95. (
  96. # 更新另外一个表的字段 => 本表的字段
  97. 'where' => array('admin_id' => 'id'),
  98. # 要更新的数据
  99. 'update' => array('role_id' => 'role'),
  100. )
  101. ),
  102. */
  103. /*该方法用check替代
  104. 'start' => array
  105. (
  106. 'update' => 'manage/auth.check',
  107. 'insert' => 'manage/auth.check',
  108. ),
  109. */
  110. 'end' => array
  111. (
  112. 'update' => 'manage/auth.update',
  113. ),
  114. # 数据结构
  115. 'struct' => array
  116. (
  117. 'id' => array
  118. (
  119. 'type' => 'int-11',
  120. 'name' => '管理员ID',
  121. 'default' => '',
  122. 'desc' => '',
  123. 'match' => 'is_numeric',
  124. 'search' => 'order',
  125. 'list' => true,
  126. ),
  127. 'username' => array
  128. (
  129. 'type' => 'varchar-24',
  130. 'name' => '管理员名',
  131. 'default' => '',
  132. 'desc' => '请输入管理员名',
  133. 'match' => 'is_string',
  134. 'update' => 'text',
  135. # 自动完成功能,第一个参数是请求的地址,请自行实现,第二个参数是要使用的字段,共有id和value两个选择,id会特殊处理,value则直接把当前值写入,第三个参数是直接替换当前的值,第四个参数是当前表里的字段名,一般为分类的id
  136. //'autocomplete' => array('auth.role?json=1', 'value', 'manage/role-check#name', 'cate_id'),
  137. //'autocomplete' => array('auth.role?json=1'),
  138. 'search' => 'order,fulltext',
  139. 'list' => true,
  140. # 绑定js脚本,更新时使用,第一个参数是执行的方式,第二个参数执行的方法,第三个参数是传值。
  141. //'bind' => array('onblur', 'loading', array('url' => Dever::url("auth.blur"))),
  142. ),
  143. #多级联动
  144. //'update' => 'linkage',//多级联动 option参数:请求地址(返回参数为level_num当前联动级数,level_id当前选择的id),参考area组件:dever package area
  145. //'option' => Dever::url('api.get', 'area'),
  146. 'email' => array
  147. (
  148. 'type' => 'varchar-150',
  149. 'name' => '邮箱-可用于登录,请准确填写,不允许重复',
  150. 'default' => '',
  151. 'desc' => '请输入邮箱',
  152. 'match' => Dever::rule('email'),
  153. 'update' => 'text',
  154. /*
  155. * 列表页搜索选项,这里的search或者update的值为
  156. * fulltext:全文检索,模糊匹配
  157. * text:精确匹配
  158. * exp:大小判断,仅能选择一项
  159. * select:选择器,需要option项
  160. * group:组选择器,需要option项
  161. * linkage:多级联动选择器,需要option项,值为联动数据接口地址,参考area组件 'option' => Dever::url('api.get', 'area'), 'list' => 'Dever::load("area/api.string", "{area}")',
  162. * exist:是否存在,需要exist项,基本配置为
  163. $source_id = array
  164. (
  165. 'yes' => '有值',
  166. 'no' => '没有值',
  167. 'no|2832' => '没有值或者有值为2832',
  168. 'yes|2832' => '有值并且过滤值为2829',
  169. '2832' => '查找',
  170. );
  171. * 如果search的值为数组,则认为是接口,需要从接口获取数据后再进行查找
  172. * 如'search' => array
  173. (
  174. 'api' => 'passport/user-all',//接口地址,最好是获取多条数据的地址
  175. 'col' => 'name',//要查询的字段
  176. 'result' => 'id',//返回的字段
  177. 'search' => 'uid',//本表的字段,默认为当前的字段
  178. ),
  179. * 就是将本字段email当做passport/user-one的name字段来查找id
  180. */
  181. 'search' => 'fulltext',
  182. 'list' => true,
  183. # 在手机版或者小屏幕下,列表页的表格是否展示,1为展示,2、3、4、5、6均为在一定宽度下展示,详细参考:https://github.com/nadangergeo/RWD-Table-Patterns
  184. 'level' => 1,
  185. ),
  186. # 比较特殊的一些设置,不断添加中:
  187. /*
  188. 'cate' => array
  189. (
  190. 'type' => 'varchar-300',
  191. 'name' => '标签分类',
  192. 'default' => '1',
  193. 'desc' => '标签分类',
  194. 'match' => 'is_string',
  195. 'update' => 'select',
  196. 'option' => $cate,
  197. 'search' => 'fulltext',
  198. //'list' => true,
  199. 'control' => 'cate',
  200. ),
  201. # 标签,根据分类变化的标签
  202. 'tag' => array
  203. (
  204. 'type' => 'varchar-300',
  205. 'name' => '标签',
  206. 'default' => '',
  207. 'desc' => '标签',
  208. 'match' => 'is_string',
  209. 'update' => 'checkbox',
  210. # 新增接口 暂未实现
  211. 'adding' => 'tag/manage.getByCate?cate=',
  212. # 开启这个,需要将update更换为text类型,输入文字即可选择标签
  213. //'autocomplete' => array('tag/manage.getByName', 'id', 'tag/info-one#name'),
  214. 'search' => 'fulltext',
  215. //'list' => true,
  216. # 与上边的cate联动(ajax)
  217. 'show' => 'cate=tag/manage.getByCate?cate=',
  218. ),
  219. # 加载地图
  220. 'map' => array
  221. (
  222. 'type' => 'varchar-300',
  223. 'name' => '地理位置',
  224. 'default' => '',
  225. 'desc' => '地理位置',
  226. 'match' => 'is_string',
  227. # 如果是map,必须在config的base.php中设置map信息
  228. //'update' => 'map',
  229. 'search' => 'fulltext',
  230. //'list' => true,
  231. //自定义编辑器右侧按钮
  232. 'editor' => array
  233. (
  234. 'name' => '选择插入模块',
  235. 'button' => array
  236. (
  237. array
  238. (
  239. # 名称
  240. 'name' => '图片',
  241. # 资源库id
  242. 'key' => 1,
  243. # 类型
  244. 'type' => 'image',
  245. ),
  246. array
  247. (
  248. 'name' => '音频',
  249. 'key' => 2,
  250. 'type' => 'media',
  251. ),
  252. array
  253. (
  254. 'name' => '视频',
  255. 'key' => 'video/lib/core.vod',
  256. ),
  257. array
  258. (
  259. 'name' => '直播',
  260. 'key' => 'video/lib/core.live',
  261. ),
  262. ),
  263. ),
  264. ),
  265. # 三级地区联动
  266. 'area' => array
  267. (
  268. 'type' => 'varchar-100',
  269. 'name' => '地区',
  270. 'default' => '',
  271. 'desc' => '地区',
  272. 'match' => 'is_string',
  273. 'search' => 'linkage',
  274. 'update' => 'linkage',//多级联动 option参数:请求地址(参数为level_num当前联动级数,level_id当前选择的id)
  275. 'option' => Dever::url('api.get', 'area'),
  276. 'list' => 'Dever::load("area/api.string", "{area}")',
  277. ),
  278. # 无限级联动
  279. 'category' => array
  280. (
  281. 'type' => 'varchar-500',
  282. 'name' => '分类',
  283. 'default' => '',
  284. 'desc' => '分类',
  285. 'match' => 'is_string',
  286. 'search' => 'linkage',
  287. //'update' => 'linkage',
  288. 'option' => Dever::url('api.get', 'category'),
  289. 'list' => 'Dever::load("category/api.string", "{category}")',
  290. ),
  291. # 属性管理
  292. 'attr' => array
  293. (
  294. 'type' => 'varchar-800',
  295. 'name' => '属性设置',
  296. 'default' => '',
  297. 'desc' => '属性设置',
  298. 'match' => 'option',
  299. 'update' => 'checkbox',
  300. 'option' => $attr,
  301. 'update_input' => '',
  302. 'update_input_default' => '',
  303. 'update_parent' => 'checkbox',
  304. ),
  305. # 属性管理 需要用这个来设置值
  306. 'attr_input' => array
  307. (
  308. 'type' => 'text-255',
  309. 'name' => '属性值设置',
  310. 'default' => '',
  311. 'desc' => '属性值设置',
  312. 'match' => 'option',
  313. ),
  314. */
  315. 'mobile' => array
  316. (
  317. 'type' => 'varchar-32',
  318. 'name' => '手机号',
  319. 'default' => '',
  320. 'desc' => '请输入手机号',
  321. 'match' => Dever::rule('mobile'),
  322. 'update' => 'text',
  323. 'search' => 'fulltext',
  324. 'list' => true,
  325. 'level' => 1,
  326. # 显示在table中
  327. //'list_table'=> '111',
  328. ),
  329. 'password' => array
  330. (
  331. 'type' => 'varchar-64',
  332. 'name' => '管理员密码',
  333. 'default' => '',
  334. 'desc' => '请输入管理员密码',
  335. 'match' => 'option',
  336. 'update' => 'password',
  337. 'callback' => 'hash.sha256',
  338. ),
  339. 'config' => array
  340. (
  341. 'type' => 'int-11',
  342. 'name' => '后台配置',
  343. 'default' => '1',
  344. 'desc' => '请选择后台配置',
  345. 'match' => 'is_numeric',
  346. 'option' => $config,
  347. 'update' => 'select',
  348. 'list' => true,
  349. ),
  350. 'role' => array
  351. (
  352. 'type' => 'varchar-100',
  353. 'name' => '角色',
  354. 'default' => '1',
  355. 'desc' => '请选择角色',
  356. 'match' => 'is_string',
  357. 'option' => $role,
  358. 'update' => 'checkbox',
  359. //'list' => true,
  360. ),
  361. 'group' => array
  362. (
  363. 'type' => 'int-11',
  364. 'name' => '分组',
  365. 'default' => '1',
  366. 'desc' => '请选择分组',
  367. 'match' => 'is_numeric',
  368. 'option' => $group,
  369. 'update' => 'select',
  370. //'list' => true,
  371. ),
  372. 'top' => array
  373. (
  374. 'type' => 'text-255',
  375. 'name' => '头部菜单-这里的头部菜单如果设置,则会覆盖角色中的头部菜单',
  376. 'default' => '',
  377. 'desc' => '请选择头部菜单',
  378. 'match' => 'option',
  379. 'update' => 'checkbox',
  380. 'option' => $top,
  381. ),
  382. 'state' => array
  383. (
  384. 'type' => 'tinyint-1',
  385. 'name' => '数据状态',
  386. 'default' => '1',
  387. 'desc' => '请选择状态',
  388. 'match' => 'is_numeric',
  389. //'option' => $option,
  390. //'update' => 'radio',
  391. //'list' => true,
  392. //'extend' => true,//扩展功能,该字段为虚拟字段,只在数据库中建立extend字段来保存 后续实现
  393. ),
  394. /*
  395. 提供冲突检测机制(乐观锁),保证高并发下的数据安全
  396. 这是模仿自 php 的 Memcached 扩展 后续实现
  397. 'token' => array
  398. (
  399. 'type' => 'int-11',
  400. 'name' => 'token',
  401. 'default' => '1',
  402. 'desc' => 'token',
  403. 'match' => 'is_numeric',
  404. ),
  405. */
  406. 'status' => array
  407. (
  408. 'type' => 'tinyint-1',
  409. 'name' => '状态',
  410. 'default' => '1',
  411. 'desc' => '请选择状态',
  412. 'match' => 'is_numeric',
  413. 'option' => $status,
  414. 'update' => 'radio',
  415. 'list' => true,
  416. 'edit' => true,
  417. ),
  418. 'cdate' => array
  419. (
  420. 'type' => 'int-11',
  421. 'name' => '录入时间',
  422. 'match' => array('is_numeric', DEVER_TIME),
  423. 'desc' => '',
  424. # 只有insert时才生效
  425. 'insert' => true,
  426. 'list' => 'date("Y-m-d H:i:s", {cdate})',
  427. ),
  428. ),
  429. 'manage' => array
  430. (
  431. 'delete' => false,
  432. // 载入自定义资源
  433. 'res' => array
  434. (
  435. 'js' => 'demo',
  436. 'css' => 'demo',
  437. ),
  438. # 快捷更新
  439. /*
  440. 'list_button' => array
  441. (
  442. 'edit' => array('审核', 'name'),
  443. ),
  444. */
  445. /*
  446. 'insert' => false,
  447. 'edit' => false,
  448. //'delete' => false,
  449. # 自定义快捷新增和编辑
  450. 'button' => array
  451. (
  452. '新增' => array('fast', 'name,reorder'),
  453. ),
  454. # 快捷更新
  455. 'list_button' => array
  456. (
  457. 'edit' => array('编辑', 'name,reorder'),
  458. ),
  459. */
  460. ),
  461. # 更新表结构
  462. 'alter' => array
  463. (
  464. 2 => array
  465. (
  466. //array('update', 'role', 'role', 'varchar-100 1 角色'),
  467. //array('add', 'config', 'config', 'int-11 1 配置'),
  468. ),
  469. 'version' => 2,
  470. ),
  471. # 默认值
  472. /*
  473. 'default' => array
  474. (
  475. 'col' => 'username,email,password,role,state,cdate',
  476. 'value' => array
  477. (
  478. //'"DMC","DMC@dever.cc","'. md5('admin_' . date('Y_m_d_H')) . '",1, 1,' . time(),
  479. '"admin","DMC@dever.cc","'. hash('sha256', 'admin_123') . '",1, 1,' . DEVER_TIME,
  480. ),
  481. ),
  482. */
  483. # 索引
  484. 'index' => array
  485. (
  486. # 索引名 => 索引id
  487. //'id' => 'id,state',
  488. ),
  489. # request 请求接口定义
  490. 'request' => array
  491. (
  492. # one 根据用户名和密码取一条数据
  493. 'user' => array
  494. (
  495. # 匹配的正则或函数 必填项
  496. 'where' => array
  497. (
  498. //'username' => '/^([A-Za-z0-9])/',
  499. //'username' => 'yes',
  500. 'email' => 'yes',
  501. 'status' => 1,
  502. 'state' => 1,
  503. //'password' => 'is_string',
  504. ),
  505. 'type' => 'one',
  506. # 为这个接口独立设置缓存
  507. 'cache' => true,
  508. ),
  509. # one 根据用户名和密码取一条数据
  510. 'email' => array
  511. (
  512. # 匹配的正则或函数 必填项
  513. 'where' => array
  514. (
  515. //'username' => '/^([A-Za-z0-9])/',
  516. //'username' => 'yes',
  517. 'email' => 'yes',
  518. 'status' => 1,
  519. 'state' => 1,
  520. //'password' => 'is_string',
  521. ),
  522. 'type' => 'one',
  523. # 为这个接口独立设置缓存
  524. 'cache' => true,
  525. ),
  526. # one 根据用户名和密码取一条数据
  527. 'mobile' => array
  528. (
  529. # 匹配的正则或函数 必填项
  530. 'where' => array
  531. (
  532. //'username' => '/^([A-Za-z0-9])/',
  533. //'username' => 'yes',
  534. 'mobile' => 'yes',
  535. 'status' => 1,
  536. 'state' => 1,
  537. //'password' => 'is_string',
  538. ),
  539. 'type' => 'one',
  540. # 为这个接口独立设置缓存
  541. 'cache' => true,
  542. ),
  543. # 更新密码
  544. 'password' => array
  545. (
  546. 'type' => 'update',
  547. 'where' => array
  548. (
  549. 'id' => 'yes',
  550. ),
  551. 'set' => array
  552. (
  553. 'password' => 'yes',
  554. ),
  555. ),
  556. ),
  557. );