优化扩展功能

This commit is contained in:
2020-04-04 21:53:38 +08:00
parent 98419ca360
commit a8619c61fb
11 changed files with 214 additions and 28 deletions

View File

@@ -8,6 +8,7 @@
// +----------------------------------------------------------------------
// 应用公共文件
use think\facade\Session;
use app\model\Member;
define("SENTCMS_VERSION", '4.x');
@@ -82,6 +83,21 @@ function get_client_ip($type = 0, $adv = false) {
return $ip[$type];
}
/**
* 根据用户ID获取用户名
* @param integer $uid 用户ID
* @return string 用户名
*/
function get_username($uid = 0) {
static $list;
if (!($uid && is_numeric($uid))) {
//获取当前登录用户名
return session('userInfo.username');
}
$name = Member::where('uid', $uid)->value('username');
return $name;
}
function avatar($uid, $size = 'middle') {
return request()->root(true) . '/static/common/images/default_avatar_' . $size . '.jpg';
}

View File

@@ -17,6 +17,11 @@ use app\model\Hooks;
*/
class Addons extends Base {
public function initialize() {
parent::initialize();
$this->getAddonsMenu();
}
/**
* @title 插件列表
*/

View File

@@ -11,6 +11,7 @@ namespace app\controller\admin;
use app\model\Menu;
use app\model\Model;
use app\model\AuthGroup;
use app\model\Addons;
use think\facade\View;
use \app\model\Form;
use \app\controller\Base as BaseC;
@@ -217,25 +218,22 @@ class Base extends BaseC {
}
protected function getAddonsMenu() {
$model = db('Addons');
$list = array();
$map = array(
'isinstall' => array('gt', 0),
'status' => array('gt', 0),
);
$list = $model->field("name,id,title,'' as 'style'")->where($map)->select();
$map[] = ['isinstall', '>', 0];
$map[] = ['status', '>', 0];
$list = Addons::where($map)->field("name,id,title,'' as 'style'")->select();
$menu = array();
foreach ($list as $key => $value) {
$class = "\\addons\\" . strtolower($value['name']) . "\\controller\\Admin";
if (is_file(ROOT_PATH . '/addons/' . strtolower($value['name']) . "/controller/Admin.php")) {
if (is_file($this->app->getRootPath() . '/addons/' . strtolower($value['name']) . "/controller/Admin.php")) {
$action = get_class_methods($class);
$value['url'] = "admin/addons/execute?mc=" . strtolower($value['name']) . "&ac=" . $action[0];
$value['url'] = "/addons/".$value['name']."/admin/" . $action[0];
$menu[$key] = $value;
}
}
if (!empty($menu)) {
$this->assign('extend_menu', array('管理插件' => $menu));
View::assign('extend_menu', array('管理插件' => $menu));
}
}

View File

@@ -101,4 +101,63 @@ class Client extends Base {
return $this->error('删除失败!');
}
}
public function api(){
$list = [];
$path = app()->getAppPath() . 'controller/api';
$classname = $this->scanFile($path);
foreach ($classname as $value) {
if($value == 'Base'){
continue;
}
$class = "app\\controller\\api\\" . $value;
if (class_exists($class)) {
$reflection = new \ReflectionClass($class);
$group_doc = $this->Parser($reflection->getDocComment());
$method = $reflection->getMethods(\ReflectionMethod::IS_FINAL | \ReflectionMethod::IS_PUBLIC);
$group_doc['name'] = $value;
foreach ($method as $key => $v) {
if (!in_array($v->name, ['__construct'])) {
$title_doc = $this->Parser($v->getDocComment());
if (isset($title_doc['title']) && $title_doc['title']) {
$list[] = array(
'url' => 'api/' . strtolower($value) . '/' . strtolower($v->name),
'name' => 'api/' . strtolower($value) . '/' . strtolower($v->name),
'method' => isset($title_doc['method']) ? strtoupper($title_doc['method']) : 'GET',
'title' => trim($title_doc['title']),
'group' => $group_doc['title'],
'status' => 1,
);
}
}
}
}
}
$this->data = [
'list' => $list
];
return $this->fetch();
}
protected function scanFile($path) {
$result = array();
$files = scandir($path);
foreach ($files as $file) {
if ($file != '.' && $file != '..') {
if (is_dir($path . '/' . $file)) {
$this->scanFile($path . '/' . $file);
} else {
$result[] = substr(basename($file), 0, -4);
}
}
}
return $result;
}
protected function Parser($text) {
$doc = new \doc\Doc();
return $doc->parse($text);
}
}

View File

@@ -0,0 +1,63 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller\api;
use app\model\Category;
/**
* @title 内容管理
*/
class Content extends Base {
/**
* @title 内容列表
* @method GET
* @param Category $category [description]
* @return [json]
*/
public function lists(Category $category){
}
/**
* @title 内容详情
* @method GET
* @return [json]
*/
public function detail(){
}
/**
* @title 添加内容
* @method POST
* @return [json]
*/
public function add(){
}
/**
* @title 修改内容
* @method POST
* @return [json]
*/
public function edit(){
}
/**
* @title 删除内容
* @method POST
* @return [json]
*/
public function delete(){
}
}

View File

View File

View File

@@ -77,7 +77,7 @@ class Attribute extends \think\Model {
}
protected function getTypeTextAttr($value, $data) {
$config_type_list = Config::get('config.config_type_list');
$config_type_list = Config::get('config.config_type_list') ?? [];
$type = [];
foreach ($config_type_list as $key => $value) {
$type[$value['key']] = $value['label'];
@@ -111,6 +111,9 @@ class Attribute extends \think\Model {
$map[] = ['model_id', '=', $data['model_id']];
}
$row = Db::name($extra[0])->where($map)->select()->toArray();
if(empty($row)){
return [];
}
if ($extra[1] == 'tree') {
$row = (new Tree())->toFormatTree($row);
foreach ($row as $val) {
@@ -146,7 +149,7 @@ class Attribute extends \think\Model {
$map[] = ['is_show', 'IN', [1, 3]];
}
$row = self::where($map)
$row = self::where($map)->order('sort asc, id desc')
->select()
->append(['option'])
->toArray();

View File

@@ -14,19 +14,19 @@ use app\model\Model;
$model = Model::where('status', '>', 0)->field(['id', 'name'])->select()->toArray();
foreach ($model as $value) {
Route::rule('/admin/' . $value['name'] . '/:function', 'Admin.content/:function')->append(['name'=>$value['name'], 'model_id' => $value['id']]);
Route::rule('/front/' . $value['name'] . '/:function', 'Front.content/:function')->append(['name'=>$value['name'], 'model_id' => $value['id']]);
Route::rule('/user/' . $value['name'] . '/:function', 'User.content/:function')->append(['name'=>$value['name'], 'model_id' => $value['id']]);
Route::rule('/admin/' . $value['name'] . '/:function', 'admin.content/:function')->append(['name'=>$value['name'], 'model_id' => $value['id']]);
Route::rule('/front/' . $value['name'] . '/:function', 'front.content/:function')->append(['name'=>$value['name'], 'model_id' => $value['id']]);
Route::rule('/user/' . $value['name'] . '/:function', 'user.content/:function')->append(['name'=>$value['name'], 'model_id' => $value['id']]);
}
Route::rule('/', 'Front.Index/index');
Route::rule('search', 'Front.Content/search');
Route::rule('lists', 'Front.Content/lists');
Route::rule('detail-:id', 'Front.Content/detail');
Route::rule('category', 'Front.Content/category');
Route::rule('topic-:id', 'Front.Content/topic');
Route::rule('form/:id/:name', 'Front.Form/index');
Route::rule('front/:controller/:function', 'Front.:controller/:function');
Route::rule('/', 'front.Index/index');
Route::rule('search', 'front.Content/search');
Route::rule('lists', 'front.Content/lists');
Route::rule('detail-:id', 'front.Content/detail');
Route::rule('category', 'front.Content/category');
Route::rule('topic-:id', 'front.Content/topic');
Route::rule('form/:id/:name', 'front.Form/index');
Route::rule('front/:controller/:function', 'front.:controller/:function');
Route::group('admin', function () {
Route::rule('/', 'admin.Index/index');
@@ -37,12 +37,12 @@ Route::group('admin', function () {
});
Route::group('user', function () {
Route::rule('/', 'User.Index/index');
Route::rule('login', 'User.Index/login');
Route::rule('logout', 'User.Index/logout');
Route::rule('register', 'User.Index/register');
Route::rule('/', 'user.Index/index');
Route::rule('login', 'user.Index/login');
Route::rule('logout', 'user.Index/logout');
Route::rule('register', 'user.Index/register');
Route::rule('upload/:function', 'Upload/:function');
Route::rule(':controller/:function', 'User.:controller/:function');
Route::rule(':controller/:function', 'user.:controller/:function');
});
Route::group('api', function () {

View File

@@ -45,7 +45,7 @@
<td><input class="ids row-selected" type="checkbox" name="id[]" value="{$list.id}"></td>
<td>{$list['id']}</td>
<td>
{$list['level_show']}
{$list['level_show']|raw}
<a href="#" class="editable editable-click" data-id="{$list['id']}" data-name="title" data-type="text" data-pk="{$list['id']}" data-url="{:url('/admin/channel/editable')}">{$list['title']} </a>
<a class="add-sub-cate" title="添加子分类" href="{:url('/admin/channel/add', ['pid' =>$list['id']])}">
<i class="fa fa-plus-square"></i>

View File

@@ -0,0 +1,42 @@
{extend name="admin/public/base"/}
{block name="body"}
<div class="main-box clearfix">
<header class="main-box-header clearfix">
<div class="pull-left">
<h2>{$meta_title}</h2>
</div>
<div class="pull-right">
<a class="btn btn-primary" href="{:url('/admin/client/add')}">新 增</a>
<button class="btn btn-danger ajax-post confirm" url="{:url('/admin/client/del')}" target-form="ids">删 除</button>
</div>
</header>
<div class="main-box-body clearfix">
<div class="table-responsive clearfix">
<table class="table table-hover">
<thead>
<tr>
<th>ID</th>
<th>分组</th>
<th>名称</th>
<th>接口地址</th>
<th>方法类型</th>
<th>状态</th>
</tr>
</thead>
<tbody>
{volist name="list" id="item"}
<tr>
<td>{$key}</td>
<td>{$item['group']}</td>
<td>{$item['title']}</td>
<td>{$item['url']}</td>
<td>{$item['method']}</td>
<td>{$item['status']}</td>
</tr>
{/volist}
</tbody>
</table>
</div>
</div>
</div>
{/block}