diff --git a/app/common.php b/app/common.php index 3bfbb7e8..5af1fe01 100755 --- a/app/common.php +++ b/app/common.php @@ -63,4 +63,19 @@ function get_client_ip($type = 0, $adv = false) { function avatar($uid, $size = 'middle') { return request()->root(true) . '/static/common/images/default_avatar_' . $size . '.jpg'; +} + +// 分析枚举类型配置值 格式 a:名称1,b:名称2 +function parse_config_attr($string) { + $array = preg_split('/[,;\r\n]+/', trim($string, ",;\r\n")); + if (strpos($string, ':')) { + $value = array(); + foreach ($array as $val) { + list($k, $v) = explode(':', $val); + $value[$k] = $v; + } + } else { + $value = $array; + } + return $value; } \ No newline at end of file diff --git a/app/controller/Admin.php b/app/controller/Admin.php index 9a575035..a929567c 100755 --- a/app/controller/Admin.php +++ b/app/controller/Admin.php @@ -9,6 +9,7 @@ namespace app\controller; use app\model\Menu; +use think\facade\View; /** * @title 后端公共模块 @@ -73,9 +74,8 @@ class Admin extends Base { } //菜单设置 $this->getMenu(); - // $this->setMeta(); - // $this->data['__menu__'] = ['main' => [], 'child' => []]; - $this->data['meta_title'] = $this->getCurrentTitle(); + + View::assign('meta_title', $this->getCurrentTitle()); } } @@ -186,7 +186,7 @@ class Admin extends Base { } } } - $this->data['__menu__'] = $menu; + View::assign('__menu__', $menu); } protected function getContentMenu() { diff --git a/app/controller/Base.php b/app/controller/Base.php index aa294f81..c70cc8db 100644 --- a/app/controller/Base.php +++ b/app/controller/Base.php @@ -11,7 +11,9 @@ namespace app\controller; use think\App; use think\exception\ValidateException; use think\facade\View; +use think\facade\Cache; use think\Validate; +use app\model\Config; class Base { @@ -62,6 +64,12 @@ class Base { $this->app = $app; $this->request = $this->app->request; + $config = Cache::get('system_config_data'); + if (!$config) { + $config = Config::getConfigList($this->request); + Cache::set('system_config_data', $config); + } + View::assign('config', $config); // 控制器初始化 $this->initialize(); } diff --git a/app/controller/admin/Category.php b/app/controller/admin/Category.php index 573e079f..40ed09d9 100644 --- a/app/controller/admin/Category.php +++ b/app/controller/admin/Category.php @@ -7,11 +7,15 @@ // | Author: molong // +---------------------------------------------------------------------- -namespace app\admin\controller; -use app\common\controller\Admin; +namespace app\controller\admin; + +use app\model\Category as CategoryM; +use app\model\Attribute; +use app\model\Module; +use app\controller\Admin; /** - * @title 分类管理 + * @title 栏目管理 * @description 分类管理 */ class Category extends Admin { @@ -22,26 +26,34 @@ class Category extends Admin { } /** - * @title 分类列表 + * @title 栏目列表 */ - public function index($model_id = '') { - $map = array('status' => array('gt', -1)); - if ($model_id) { - $map['model_id'] = $model_id; + public function index(CategoryM $category, Attribute $attr, Module $medule) { + $param = $this->request->param(); + $map = []; + + $map[] = ['status', '>', -1]; + if (isset($param['model_id']) && $param['model_id']) { + $map[] = ['model_id', '=', $model_id]; } - $list = db('Category')->where($map)->order('sort asc,id asc')->column('*', 'id'); + $list = $category->where($map)->order('sort asc,id asc')->select(); if (!empty($list)) { - $tree = new \com\Tree(); - $list = $tree->toFormatTree($list); + $tree = new \sent\tree\Tree(); + $list = $tree->toFormatTree($list->toArray()); } - $subsql = db('Attribute')->where('name', 'category_id')->fetchSql(true)->column('model_id'); - $model_list = model('Model')->where('id IN ('. $subsql.')')->select(); + // $subsql = $attr->where('name', 'category_id')->fetchSql(true)->column('model_id'); + // $model_list = $medule->where('id IN ('. $subsql.')')->select(); - $this->assign('tree', $list); - $this->assign('model_list', $model_list); - $this->assign('model_id', $model_id); - $this->setMeta('栏目列表'); + $this->data = [ + 'tree' => $list, + 'module_id' => isset($param['module_id']) ? $param['module_id'] : 0, + 'model_list' => [] + ]; + // $this->assign('tree', $list); + // $this->assign('model_list', $model_list); + // $this->assign('model_id', $model_id); + // $this->setMeta('栏目列表'); return $this->fetch(); } diff --git a/app/controller/admin/Config.php b/app/controller/admin/Config.php index fcfba6c4..a818d90e 100644 --- a/app/controller/admin/Config.php +++ b/app/controller/admin/Config.php @@ -25,7 +25,10 @@ class Config extends Admin { * @title 配置管理 * @author 麦当苗儿 */ - public function index() { + public function index(ConfigM $config) { + $param = $this->request->param(); + + $group = input('group', 0, 'trim'); $name = input('name', '', 'trim'); /* 查询条件初始化 */ @@ -38,13 +41,13 @@ class Config extends Admin { $map['name'] = array('like', '%' . $name . '%'); } - $list = $this->model->where($map)->order('id desc')->paginate(25, false, array( + $list = $config->where($map)->order('id desc')->paginate(25, false, array( 'query' => $this->request->param(), )); // 记录当前列表页的cookie Cookie('__forward__', $_SERVER['REQUEST_URI']); - $data = array( + $this->data = array( 'group' => config('config_group_list'), 'config_type' => config('config_config_list'), 'page' => $list->render(), @@ -52,32 +55,28 @@ class Config extends Admin { 'list' => $list, ); - $this->assign($data); - $this->setMeta('配置管理'); return $this->fetch(); } /** * @title 信息配置 */ - public function group($id = 1) { + public function group(ConfigM $config, $id = 1) { if ($this->request->isPost()) { - $config = $this->request->post('config/a'); - $model = model('Config'); - foreach ($config as $key => $value) { - $model->where(array('name' => $key))->setField('value', $value); + $data = $this->request->post(); + + foreach ($data['config'] as $key => $value) { + ConfigM::update(['value' => $value], ['name' => $key]); } //清除db_config_data缓存 - cache('db_config_data', null); + cache('system_config_data', null); return $this->success("更新成功!"); } else { - $type = config('config_group_list'); - $list = (new ConfigM())->where(array('status' => 1, 'group' => $id))->field('id,name,title,extra,value,remark,type')->order('sort')->select(); + $list = $config->where(array('status' => 1, 'group' => $id))->field('id,name,title,extra,value,remark,type')->order('sort')->select(); if ($list) { $this->data['list'] = $list; } - // $this->assign('id', $id); - // $this->setMeta($type[$id] . '设置'); + $this->data['id'] = $id; return $this->fetch(); } } @@ -86,17 +85,14 @@ class Config extends Admin { * @title 新增配置 * @author 麦当苗儿 */ - public function add() { + public function add(ConfigM $config) { if ($this->request->isPost()) { - $config = model('Config'); $data = $this->request->post(); if ($data) { - $id = $config->validate(true)->save($data); + $id = $config->save($data); if ($id) { - cache('db_config_data', null); - //记录行为 - action_log('update_config', 'config', $id, session('user_auth.uid')); - return $this->success('新增成功', url('index')); + cache('system_config_data', null); + return $this->success('新增成功', url('/admin/config/index')); } else { return $this->error('新增失败'); } @@ -104,8 +100,7 @@ class Config extends Admin { return $this->error($config->getError()); } } else { - $this->setMeta('新增配置'); - $this->assign('info', null); + $this->data['info'] = []; return $this->fetch('edit'); } } diff --git a/app/controller/admin/Menu.php b/app/controller/admin/Menu.php index 42f5948e..3129c616 100644 --- a/app/controller/admin/Menu.php +++ b/app/controller/admin/Menu.php @@ -6,9 +6,11 @@ // +---------------------------------------------------------------------- // | Author: molong // +---------------------------------------------------------------------- - namespace app\controller\admin; + +use sent\tree\Tree; use app\controller\Admin; +use app\model\Menu as MenuM; /** * @title 菜单管理 @@ -22,21 +24,19 @@ class Menu extends Admin { /** * @title 菜单列表 */ - public function index() { + public function index(MenuM $menu) { $map = array(); $title = trim(input('get.title')); - $list = db("Menu")->where($map)->field(true)->order('sort asc,id asc')->column('*', 'id'); - int_to_string($list, array('hide' => array(1 => '是', 0 => '否'), 'is_dev' => array(1 => '是', 0 => '否'))); + $list = $menu->where($map)->field(true)->order('sort asc,id asc')->select(); + // int_to_string($list, array('hide' => array(1 => '是', 0 => '否'), 'is_dev' => array(1 => '是', 0 => '否'))); if (!empty($list)) { - $tree = new \com\Tree(); - $list = $tree->toFormatTree($list); + $list = (new Tree())->toFormatTree($list->append(['is_dev_text', 'hide_text'])->toArray()); } // 记录当前列表页的cookie - Cookie('__forward__', $_SERVER['REQUEST_URI']); + // Cookie('__forward__', $_SERVER['REQUEST_URI']); - $this->setMeta('菜单列表'); - $this->assign('list', $list); + $this->data['list'] = $list; return $this->fetch(); } diff --git a/app/controller/admin/User.php b/app/controller/admin/User.php index d85688d3..1cc87e00 100644 --- a/app/controller/admin/User.php +++ b/app/controller/admin/User.php @@ -21,20 +21,7 @@ class User extends Admin { * @author 麦当苗儿 */ public function index(Member $member) { - $param = $this->request->param(); - $map[] = ['status', '>=', 0]; - if (isset($param['nickname']) && $param['nickname']) { - $map['nickname'] = array('like', '%' . $param['nickname'] . '%'); - } - if (isset($param['username']) && $param['username']) { - $map['username'] = array('like', '%' . (string) $param['nickname'] . '%'); - } - - $order = "uid desc"; - $list = $member->where($map)->order($order) - ->paginate(15, false, array( - 'param' => $param, - )); + $list = $member->getUserList($this->request); $this->data['list'] = $list; $this->data['page'] = $list->render(); @@ -46,24 +33,18 @@ class User extends Admin { * @title 添加用户 * @author colin */ - public function add() { - $model = \think\Loader::model('Member'); + public function add(Member $member) { if ($this->request->isPost()) { $data = $this->request->param(); //创建注册用户 - $result = $model->register($data['username'], $data['password'], $data['repassword'], $data['email'], false); + $result = $member->register($data['username'], $data['password'], $data['repassword'], $data['email'], false); if ($result) { return $this->success('用户添加成功!', url('admin/user/index')); } else { return $this->error($model->getError()); } } else { - $data = array( - 'keyList' => $model->addfield, - ); - $this->assign($data); - $this->setMeta("添加用户"); - return $this->fetch('public/edit'); + return $this->fetch('admin/public/edit'); } } diff --git a/app/model/Category.php b/app/model/Category.php index f9227e32..8b7c5d50 100644 --- a/app/model/Category.php +++ b/app/model/Category.php @@ -12,7 +12,7 @@ namespace app\model; /** * 设置模型 */ -class Category { +class Category extends \think\Model{ protected $name = "Category"; protected $auto = array('update_time', 'status' => 1); diff --git a/app/model/Member.php b/app/model/Member.php index 5a18ccbc..4af43947 100644 --- a/app/model/Member.php +++ b/app/model/Member.php @@ -149,8 +149,8 @@ class Member extends Model { }]; } - $list = self::with(['depart', 'role'])->field('uid,username,nickname,status,email,mobile,department,reg_time')->where($map)->order($order)->paginate($request->pageConfig); - return $list->append(['avatar', 'status_text'])->toArray(); + $list = self::with(['role'])->field('uid,username,nickname,status,email,mobile,department,reg_time')->where($map)->order($order)->paginate($request->pageConfig); + return $list->append(['avatar', 'status_text']); } /** diff --git a/app/model/Menu.php b/app/model/Menu.php index 53b1cb7c..b6e70380 100644 --- a/app/model/Menu.php +++ b/app/model/Menu.php @@ -19,9 +19,19 @@ class Menu extends \think\Model { 'id' => 'integer', ); + protected function getIsDevTextAttr($value, $data){ + $is_dev = [0 => '否', 1 => '是']; + return isset($is_dev[$data['is_dev']]) ? $is_dev[$data['is_dev']] : '是'; + } + + protected function getHideTextAttr($value, $data){ + $is_dev = [0 => '否', 1 => '是']; + return isset($is_dev[$data['is_dev']]) ? $is_dev[$data['is_dev']] : '是'; + } + public function getAuthNodes($type = 'admin') { $map['type'] = $type; - $rows = $this->db()->field('id,pid,group,title,url')->where($map)->order('id asc')->select(); + $rows = $this->field('id,pid,group,title,url')->where($map)->order('id asc')->select(); foreach ($rows as $key => $value) { $data[$value['id']] = $value; } diff --git a/composer.json b/composer.json index 1ee5ef16..2cbf3682 100755 --- a/composer.json +++ b/composer.json @@ -29,7 +29,8 @@ "sent/think-auth": "^1.2", "topthink/think-captcha": "^3.0", "sent/think-jwt": "^1.0", - "xin/helper": "^1.0" + "xin/helper": "^1.0", + "sent/tree": "^1.0" }, "require-dev": { "symfony/var-dumper": "^4.2" diff --git a/composer.lock b/composer.lock index 2cdff89d..2c7bec00 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "0476987d328bafb722d7dd0d63579fa8", + "content-hash": "6b1346aad2724d940b44b2a507ab9be5", "packages": [ { "name": "lcobucci/jwt", @@ -636,6 +636,36 @@ "description": "thinkphp jwt auth composer", "time": "2019-11-19T07:11:50+00:00" }, + { + "name": "sent/tree", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://gitee.com/ycgpp/tree.git", + "reference": "61229ea4cc4485fb8a82343921d33559daed2992" + }, + "require": { + "php": ">=5.6" + }, + "type": "library", + "autoload": { + "psr-4": { + "sent\\tree\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "molong", + "email": "ycgpp@126.com" + } + ], + "description": "tree", + "time": "2019-11-26T13:24:07+00:00" + }, { "name": "topthink/framework", "version": "v6.0.2", diff --git a/view/admin/category/index.html b/view/admin/category/index.html index da86e1ec..01dd97ff 100644 --- a/view/admin/category/index.html +++ b/view/admin/category/index.html @@ -17,10 +17,10 @@
diff --git a/view/admin/config/edit.html b/view/admin/config/edit.html index b0305ee6..b5025206 100644 --- a/view/admin/config/edit.html +++ b/view/admin/config/edit.html @@ -12,21 +12,21 @@
- + (用于config函数调用,只能使用英文且不能重复)
- + (用于后台显示的配置标题)
- + (用于分组显示的顺序)
@@ -34,8 +34,8 @@
(系统会根据不同类型解析配置值) @@ -46,8 +46,8 @@
(配置分组 用于批量设置 不分组则不会显示在系统设置中) @@ -56,21 +56,21 @@
- + (配置值)
- + (如果是枚举型 需要配置该项)
- + (配置详细说明)
@@ -84,5 +84,4 @@
- {/block} \ No newline at end of file diff --git a/view/admin/config/group.html b/view/admin/config/group.html index 6eb2e912..ca686a9f 100644 --- a/view/admin/config/group.html +++ b/view/admin/config/group.html @@ -7,11 +7,11 @@

配置管理

- + 配置列表 - + 添加配置 @@ -20,9 +20,9 @@
diff --git a/view/admin/config/index.html b/view/admin/config/index.html index a5e269b4..35a8d8c3 100644 --- a/view/admin/config/index.html +++ b/view/admin/config/index.html @@ -6,11 +6,11 @@

网站设置

- + 配置管理 - + 添加配置 @@ -19,10 +19,10 @@
@@ -65,7 +65,7 @@
- {$page} + {$page|raw}
diff --git a/view/admin/menu/index.html b/view/admin/menu/index.html index 052ff89b..3a9b4b8e 100644 --- a/view/admin/menu/index.html +++ b/view/admin/menu/index.html @@ -1,6 +1,6 @@ {extend name="admin/public/base"/} {block name="style"} - + {/block} {block name="body"}
@@ -16,9 +16,9 @@
--> - 新 增 - - 导 入 + 新 增 + + 导 入
@@ -49,31 +49,31 @@ {$menu.id} - {$menu['level_show']} - {$menu['title']} - + {$menu['level_show']|raw} + {$menu['title']} + {$menu.up_title|default='无'} {$menu.group} {$menu.url} - {$menu['sort']} + {$menu['sort']} - {$menu.is_dev_text} - {$menu.hide_text} - 编辑 - 删除 + 编辑 + 删除 {/volist} @@ -88,7 +88,7 @@
{/block} {block name="script"} - +