IndexController.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2013-present http://www.thinkcmf.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 小夏 < 449134904@qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\controller;
  12. use cmf\controller\AdminBaseController;
  13. use think\facade\Db;
  14. use app\admin\model\AdminMenuModel;
  15. use app\admin\service\AdminMenuService;
  16. class IndexController extends AdminBaseController
  17. {
  18. public function initialize()
  19. {
  20. $adminSettings = cmf_get_option('admin_settings');
  21. if (empty($adminSettings['admin_password']) || $this->request->pathinfo() == $adminSettings['admin_password'] || true) {
  22. $adminId = cmf_get_current_admin_id();
  23. if (empty($adminId)) {
  24. session("__LOGIN_BY_CMF_ADMIN_PW__", 1);//设置后台登录加密码
  25. }
  26. }
  27. parent::initialize();
  28. }
  29. /**
  30. * 后台首页
  31. */
  32. public function index(AdminMenuService $service)
  33. {
  34. $content = hook_one('admin_index_index_view');
  35. if (!empty($content)) {
  36. return $content;
  37. }
  38. $adminMenuModel = new AdminMenuModel();
  39. $menus = cache('admin_menus_' . cmf_get_current_admin_id(), '', null, 'admin_menus');
  40. if (empty($menus)) {
  41. $menus = $adminMenuModel->menuTree();
  42. cache('admin_menus_' . cmf_get_current_admin_id(), $menus, null, 'admin_menus');
  43. }
  44. $this->assign("menus", $menus);
  45. $result = $service->getAll();
  46. $menusTmp = array();
  47. foreach ($result as $item) {
  48. //去掉/ _ 全部小写。作为索引。
  49. $indexTmp = $item['app'] . $item['controller'] . $item['action'];
  50. $indexTmp = preg_replace("/[\\/|_]/", "", $indexTmp);
  51. $indexTmp = strtolower($indexTmp);
  52. $menusTmp[$indexTmp] = $item;
  53. }
  54. $this->assign("menus_js_var", json_encode($menusTmp));
  55. //$admin = Db::name("user")->where('id', cmf_get_current_admin_id())->find();
  56. //$this->assign('admin', $admin);
  57. return $this->fetch();
  58. }
  59. }