diff --git a/app/UploadFiles.php b/app/UploadFiles.php index d36fb7f..7e362db 100644 --- a/app/UploadFiles.php +++ b/app/UploadFiles.php @@ -1,47 +1,96 @@ update([ + 'used_time' => time(), + 'status' => 1 + ]); + } + + public static function delete($save_name) + { + return AppUploadFiles::where('save_name', $save_name)->update([ + 'delete_time' => time(), + 'status' => 2 + ]); + } + + public static function clear($id) + { + $model_file = AppUploadFiles::withTrashed()->find($id); + + $model_file->clear_time = time(); + $model_file->status = 3; + + $model_file->save(); + + return Filesystem::delete($model_file->getData('save_name')); + } + + public static function save(Request $request) + { + + $type = $request->param('type'); + if (empty($type)) { + return json_message('缺少类型参数'); } - public static function create($data,$allowFiled = [],$replace = false) - { - return AppUploadFiles::create($data,$allowFiled,$replace); + $file = request()->file('file'); + + $file_extension = $file->extension(); + + if ($file_extension == 'php') { + return json_message('上传文件异常'); } - public static function use($save_name) - { - return AppUploadFiles::where('save_name',$save_name)->update([ - 'used_time'=>time(), - 'status'=>1 - ]); + $file_path = $file->getRealPath(); + + $file_content = file_get_contents($file_path); + + if (strpos($file_content, 'update([ - 'delete_time'=>time(), - 'status'=>2 - ]); + if (empty($file)) { + return json_message('上传失败'); } - public static function clear($id) - { - $model_file = AppUploadFiles::withTrashed()->find($id); - - $model_file->clear_time = time(); - $model_file->status = 3; - - $model_file->save(); - - return Filesystem::delete($model_file->getData('save_name')); + $dir_name = $request->param('dir', 'data'); + $model_file = UploadFiles::add(); + $model_file->file_name = $file->getOriginalName(); + $model_file->mime_type = $file->getOriginalMime(); + $model_file->ext_name = $file->extension(); + $model_file->file_size = $file->getSize(); + $model_file->file_md5 = $file->md5(); + $model_file->file_sha1 = $file->sha1(); + $model_file->create_time = time(); + $model_file->type = $type; + try { + $model_file->save_name = Filesystem::putFile('upload/' . $dir_name, $file, 'uniqid'); + $model_file->save(); + return json_message($model_file->append(['src'])->toArray()); + } catch (\Throwable $th) { + return json_message($th->getMessage()); } + } } diff --git a/app/admin/controller/File.php b/app/admin/controller/File.php index 5b6c907..f43c534 100644 --- a/app/admin/controller/File.php +++ b/app/admin/controller/File.php @@ -9,100 +9,102 @@ use think\Request; class File extends Common { - /** - * 显示资源列表 - * - * @return \think\Response - */ - public function index() - { - // + /** + * 显示资源列表 + * + * @return \think\Response + */ + public function index() + { + // - $type = $this->request->param('type',1); - $status = $this->request->param('status',''); + $type = $this->request->param('type', 1); + $status = $this->request->param('status', ''); - $model_list = UploadFiles::withTrashed()->where('type',$type)->order('id desc'); + $model_list = UploadFiles::withTrashed()->where('type', $type)->order('id desc'); - if($status != ''){ - $model_list->where('status',$status); - } - - $list = $model_list->paginate(); - View::assign('list',$list); - - return View::fetch(); + if ($status != '') { + $model_list->where('status', $status); } - /** - * 显示创建资源表单页. - * - * @return \think\Response - */ - public function create() - { - // - } + $list = $model_list->paginate(); + View::assign('list', $list); - /** - * 保存新建的资源 - * - * @param \think\Request $request - * @return \think\Response - */ - public function save(Request $request) - { - // - } + return View::fetch(); + } - /** - * 显示指定的资源 - * - * @param int $id - * @return \think\Response - */ - public function read($id) - { - // - } + /** + * 显示创建资源表单页. + * + * @return \think\Response + */ + public function create() + { + // + } - /** - * 显示编辑资源表单页. - * - * @param int $id - * @return \think\Response - */ - public function edit($id) - { - // - } + /** + * 保存新建的资源 + * + * @param \think\Request $request + * @return \think\Response + */ + public function save(Request $request) + { + // - /** - * 保存更新的资源 - * - * @param \think\Request $request - * @param int $id - * @return \think\Response - */ - public function update(Request $request, $id) - { - // - } + return AppUploadFiles::save($request); + } - /** - * 删除指定资源 - * - * @param int $id - * @return \think\Response - */ - public function delete($id) - { - // - } + /** + * 显示指定的资源 + * + * @param int $id + * @return \think\Response + */ + public function read($id) + { + // + } - public function clear($id) - { - AppUploadFiles::clear($id); + /** + * 显示编辑资源表单页. + * + * @param int $id + * @return \think\Response + */ + public function edit($id) + { + // + } - return json_message(); - } + /** + * 保存更新的资源 + * + * @param \think\Request $request + * @param int $id + * @return \think\Response + */ + public function update(Request $request, $id) + { + // + } + + /** + * 删除指定资源 + * + * @param int $id + * @return \think\Response + */ + public function delete($id) + { + // + } + + public function clear($id) + { + AppUploadFiles::clear($id); + + return json_message(); + } } diff --git a/app/api/controller/Files.php b/app/api/controller/Files.php index 1c32c1f..e13d862 100644 --- a/app/api/controller/Files.php +++ b/app/api/controller/Files.php @@ -10,111 +10,69 @@ use app\UploadFiles as AppUploadFiles; class Files extends BaseController { - /** - * 显示资源列表 - * - * @return \think\Response - */ - public function index() - { - // - } + /** + * 显示资源列表 + * + * @return \think\Response + */ + public function index() + { + // + } - /** - * 保存新建的资源 - * - * @param \think\Request $request - * @return \think\Response - */ - public function save(Request $request) - { - $type = $request->param('type'); - if(empty($type)){ - return json_message('缺少类型参数'); - } - - $file = request()->file('file'); + /** + * 保存新建的资源 + * + * @param \think\Request $request + * @return \think\Response + */ + public function save(Request $request) + { + return AppUploadFiles::save($request); + } - $file_extension = $file->extension(); - - if($file_extension == 'php'){ - return json_message('上传文件异常'); - } + /** + * 显示指定的资源 + * + * @param int $id + * @return \think\Response + */ + public function read($id) + { + // + } - $file_path = $file->getRealPath(); + /** + * 显示编辑资源表单页. + * + * @param int $id + * @return \think\Response + */ + public function edit($id) + { + // + } - $file_content = file_get_contents($file_path); + /** + * 保存更新的资源 + * + * @param \think\Request $request + * @param int $id + * @return \think\Response + */ + public function update(Request $request, $id) + { + // + } - if(strpos($file_content,'param('dir','data'); - $model_file = AppUploadFiles::add(); - $model_file->file_name = $file->getOriginalName(); - $model_file->mime_type = $file->getOriginalMime(); - $model_file->ext_name = $file->extension(); - $model_file->file_size = $file->getSize(); - $model_file->file_md5 = $file->md5(); - $model_file->file_sha1 = $file->sha1(); - $model_file->create_time = time(); - $model_file->type = $type; - try { - $model_file->save_name = Filesystem::putFile('upload/'.$dir_name,$file,'uniqid'); - $model_file->save(); - return json_message($model_file->append(['src'])->toArray()); - } catch (\Throwable $th) { - return json_message($th->getMessage()); - } - - } - - /** - * 显示指定的资源 - * - * @param int $id - * @return \think\Response - */ - public function read($id) - { - // - } - - /** - * 显示编辑资源表单页. - * - * @param int $id - * @return \think\Response - */ - public function edit($id) - { - // - } - - /** - * 保存更新的资源 - * - * @param \think\Request $request - * @param int $id - * @return \think\Response - */ - public function update(Request $request, $id) - { - // - } - - /** - * 删除指定资源 - * - * @param int $id - * @return \think\Response - */ - public function delete($id) - { - // - } + /** + * 删除指定资源 + * + * @param int $id + * @return \think\Response + */ + public function delete($id) + { + // + } } diff --git a/app/index/controller/BaseController.php b/app/index/controller/BaseController.php index 7025b8c..de9feca 100644 --- a/app/index/controller/BaseController.php +++ b/app/index/controller/BaseController.php @@ -1,4 +1,5 @@ isUseTpls && strpos($template,'@') === false && stripos($template,'/') === false){ - if($template === ''){ - $config_auto_rule = Config::get('view.auto_rule'); - if (2 == $config_auto_rule) { - $template = $this->request->action(true); - } elseif (3 == $config_auto_rule) { - $template = $this->request->action(); - } else { - $template = Str::snake($this->request->action()); - } - } - return View::fetch(get_system_config('index_tpl_name').$template,$vars); - }else{ - return View::fetch($template,$vars); + + public function initialize() + { + parent::initialize(); + + $this->indexTplName = get_system_config('index_tpl_name'); + + $this->indexTplMethod = '__'.Str::camel($this->indexTplName); + + $this->indexTplMethodCurrentAction = $this->indexTplMethod.Str::studly($this->request->action()); + + + } + + public function assign($template, $value) + { + return View::assign($template, $value); + } + + public function fetch($template = '', $vars = []) + { + if ($this->isUseTpls && strpos($template, '@') === false && stripos($template, '/') === false) { + + if ($template === '') { + $config_auto_rule = Config::get('view.auto_rule'); + if (2 == $config_auto_rule) { + $template = $this->request->action(true); + } elseif (3 == $config_auto_rule) { + $template = $this->request->action(); + } else { + $template = Str::snake($this->request->action()); } + } + + return View::fetch($this->indexTplName . $template, $vars); + } else { + return View::fetch($template, $vars); } + } } diff --git a/app/index/controller/Common.php b/app/index/controller/Common.php index a25ff0a..c17f6e6 100644 --- a/app/index/controller/Common.php +++ b/app/index/controller/Common.php @@ -1,25 +1,54 @@ order('sort asc')->where('status',1)->select(); - View::assign('list_header_nav',$list_header_nav); - $list_nav_slide = Nav::where('type',3)->order('sort asc')->where('status',1)->select(); - View::assign('list_nav_slide',$list_nav_slide); - $list_nav_index_block_1 = Nav::where('type',6)->order('sort asc')->where('status',1)->select(); - View::assign('list_nav_index_block_1',$list_nav_index_block_1); - $list_nav_index_block_2 = Nav::where('type',7)->order('sort asc')->where('status',1)->select(); - View::assign('list_nav_index_block_2',$list_nav_index_block_2); - $list_nav_friend_url = Nav::where('type',2)->order('sort asc')->where('status',1)->select(); - View::assign('list_nav_friend_url',$list_nav_friend_url); + $list_header_nav = Nav::where('type', 1)->order('sort asc')->where('status', 1)->select(); + View::assign('list_header_nav', $list_header_nav); + $list_nav_slide = Nav::where('type', 3)->order('sort asc')->where('status', 1)->select(); + View::assign('list_nav_slide', $list_nav_slide); + $list_nav_friend_url = Nav::where('type', 2)->order('sort asc')->where('status', 1)->select(); + View::assign('list_nav_friend_url', $list_nav_friend_url); + + if (!empty($this->indexTplMethod)) { + + if (method_exists($this, $this->indexTplMethod)) { + $this->{$this->indexTplMethod}(); + } + + } + if (!empty($this->indexTplMethodCurrentAction)) { + + if (method_exists($this, $this->indexTplMethodCurrentAction)) { + $this->{$this->indexTplMethodCurrentAction}(); + } + + } + } + + public function __easyBlue() + { + $list_nav_index_block_1 = Nav::where('type', 6)->order('sort asc')->where('status', 1)->select(); + View::assign('list_nav_index_block_1', $list_nav_index_block_1); + $list_nav_index_block_2 = Nav::where('type', 7)->order('sort asc')->where('status', 1)->select(); + View::assign('list_nav_index_block_2', $list_nav_index_block_2); + } + + public function __articles() + { + $list_category_first_level = Category::where('level', 1)->where('status', 1)->select(); + $this->assign('list_category_first_level', $list_category_first_level); + $list_nav_more = Nav::where('type', 8)->order('sort asc')->where('status', 1)->select(); + View::assign('list_nav_more', $list_nav_more); } } diff --git a/app/index/controller/Index.php b/app/index/controller/Index.php index bbc9c1d..fea1b89 100644 --- a/app/index/controller/Index.php +++ b/app/index/controller/Index.php @@ -2,86 +2,126 @@ namespace app\index\controller; -use think\facade\View; +use app\model\Category; +use app\model\Post; +use app\model\PostCategory; use think\Request; class Index extends Common { - /** - * 显示资源列表 - * - * @return \think\Response - */ - public function index() - { - // + /** + * 显示资源列表 + * + * @return \think\Response + */ + public function index() + { + // - return $this->fetch(); + return $this->fetch(); + } + + public function __articlesIndex() + { + + $sub_category = []; + + if(!empty($this->request->param('category_id'))){ + $sub_category = Category::where('pid',$this->request->param('category_id'))->select(); + + if(empty($this->request->param('sub_category_id'))){ + $categorys = [$this->request->param('category_id')]; + + $categorys = array_merge($categorys,array_column((array)Category::getListLevel($this->request->param('category_id')),'id')); + + $categorys_where = PostCategory::whereIn('category_id',$categorys); + + $model_post = Post::hasWhere('categorys',$categorys_where)->where('status',1)->order('id desc'); + }else{ + $model_post = Post::hasWhere('categorys',['category_id'=>$this->request->param('sub_category_id')])->where('status',1)->order('id desc'); + + } + }else{ + + $model_post = Post::where('status',1)->order('id desc'); + } + + $keywords = $this->request->param('keywords'); + + if(!empty($keywords)){ + $model_post->whereLike('title|desc',"%$keywords%"); } - /** - * 显示创建资源表单页. - * - * @return \think\Response - */ - public function create() - { - // - } + $list_post = $model_post->paginate(); - /** - * 保存新建的资源 - * - * @param \think\Request $request - * @return \think\Response - */ - public function save(Request $request) - { - // - } + $this->assign('sub_category',$sub_category); - /** - * 显示指定的资源 - * - * @param int $id - * @return \think\Response - */ - public function read($id) - { - // - } + $this->assign('list_post',$list_post); + } - /** - * 显示编辑资源表单页. - * - * @param int $id - * @return \think\Response - */ - public function edit($id) - { - // - } + /** + * 显示创建资源表单页. + * + * @return \think\Response + */ + public function create() + { + // + } - /** - * 保存更新的资源 - * - * @param \think\Request $request - * @param int $id - * @return \think\Response - */ - public function update(Request $request, $id) - { - // - } + /** + * 保存新建的资源 + * + * @param \think\Request $request + * @return \think\Response + */ + public function save(Request $request) + { + // + } - /** - * 删除指定资源 - * - * @param int $id - * @return \think\Response - */ - public function delete($id) - { - // - } + /** + * 显示指定的资源 + * + * @param int $id + * @return \think\Response + */ + public function read($id) + { + // + } + + /** + * 显示编辑资源表单页. + * + * @param int $id + * @return \think\Response + */ + public function edit($id) + { + // + } + + /** + * 保存更新的资源 + * + * @param \think\Request $request + * @param int $id + * @return \think\Response + */ + public function update(Request $request, $id) + { + // + } + + /** + * 删除指定资源 + * + * @param int $id + * @return \think\Response + */ + public function delete($id) + { + // + } } diff --git a/app/model/Category.php b/app/model/Category.php index 4f01d6c..8ae886b 100644 --- a/app/model/Category.php +++ b/app/model/Category.php @@ -14,14 +14,41 @@ class Category extends Model { // - public static function getListLevel() - { - $model_list = Category::select(); + public static $allCategory = []; - // return $model_list; - return array2level($model_list,0,0); + + /** + * 获取指定id下的所有分类 + * + * @param string $id + * @return void + */ + public static function getListLevel($id = '') + { + + if(empty(self::$allCategory)){ + + $model_list = Category::select(); + self::$allCategory = array2level($model_list,0,0); + } + + if(!empty($id)){ + $list = []; + $in_category = [$id]; + foreach (self::$allCategory as $category) { + if(in_array($category->pid,$in_category)){ + $list[] = $category; + $in_category[] = $category->id; + } + } + + return $list; + } + + return self::$allCategory; } + public function getTitleImgAttr($value) { diff --git a/app/model/Post.php b/app/model/Post.php index c5cb9fb..e67ab3d 100644 --- a/app/model/Post.php +++ b/app/model/Post.php @@ -113,6 +113,10 @@ class Post extends Model { return json_encode($value); } + public function setContentHtmlAttr($value) + { + return trim($value); + } public function getContentAttr($value) { diff --git a/public/static/css/index.articles.css b/public/static/css/index.articles.css new file mode 100644 index 0000000..665c295 --- /dev/null +++ b/public/static/css/index.articles.css @@ -0,0 +1,130 @@ +.main-container{ + margin-top: 15px; +} + +.nav-left-container{ + margin-top: 15px; +} + +.nav-left-list{ + text-align: center; +} + +.nav-left-list a{ + display: block; + padding: 10px 15px; + border-radius: 5px; + margin: 5px 40px; +} + +.nav-left-list a:hover,.nav-left-list a.current{ + background-color: #6699CC; + color: #fff; +} + +.logo{ + text-align: center; +} + +.logo img{ + max-width: 60%; +} + +.session{ + margin-top: 15px; + background-color: #99CCFF; + padding: 15px; +} + +.session.border{ + border-top: 2px solid #6699CC; +} + +.session .header{ + font-size: 18px; + font-weight: 600; + color: #036; +} + +.search-container{ + display: flex; +} + + +.layui-btn{ + background-color: #6699CC; +} + +.nav-more-list a{ + display: inline-block; + white-space: nowrap; + color: #036; + margin-right: 15px; + margin-top: 15px; +} + +.session .info p{ + margin: 5px 0; +} + +#banner img{ + width: 100%; +} + +.tab-list{ + border-bottom: 1px solid #ddd; + margin-top: 15px; + font-size: 16px; + +} + +.tab-list a{ + margin-right: 15px; + border-bottom: 2px solid transparent; + padding-bottom: 10px; + display: inline-block; +} + +.tab-list a.current{ + border-color: #6699CC; +} + + +.post-item{ + display: flex; + justify-content: flex-start; + align-items: center; + margin-top: 15px; + padding-bottom: 15px; + border-bottom: 1px solid #ddd; +} + +.post-item .poster{ + width: 160px; + height: 100px; + background-size: cover; + background-position: center; + background-repeat: no-repeat; + margin-right: 15px; +} + +.post-item .info .title{ + font-size: 22px; + font-weight: 600; +} + +.post-item .info .plus-info{ + margin-top: 5px; +} + +.nodata{ + + margin: 60px auto; + display: block; + width: 40%; +} + +.content-container .title{ + font-size: 22px; + font-weight: 600; +} diff --git a/public/static/images/nodata.png b/public/static/images/nodata.png new file mode 100644 index 0000000..6733108 Binary files /dev/null and b/public/static/images/nodata.png differ diff --git a/view/admin/admin/create.html b/view/admin/admin/create.html index 7613430..04258fb 100644 --- a/view/admin/admin/create.html +++ b/view/admin/admin/create.html @@ -110,7 +110,7 @@ var uploadSiteLogo = croppers.render({ elem: '.upload-admin-avatar', - url: '{:url("api/Files/save")}', + url: '{:url("File/save")}', data: { type: 2, dir: 'admin_avatar' diff --git a/view/admin/admin/edit.html b/view/admin/admin/edit.html index 5c409e6..356497a 100644 --- a/view/admin/admin/edit.html +++ b/view/admin/admin/edit.html @@ -84,7 +84,7 @@ var uploadSiteLogo = croppers.render({ elem:'.upload-admin-avatar', - url:'{:url("api/Files/save")}', + url:'{:url("File/save")}', data:{ type:2, dir:'admin_avatar' diff --git a/view/admin/admin/edit_account.html b/view/admin/admin/edit_account.html index b77064d..31ffb9a 100644 --- a/view/admin/admin/edit_account.html +++ b/view/admin/admin/edit_account.html @@ -115,7 +115,7 @@ var uploadSiteLogo = croppers.render({ elem: '.upload-admin-avatar', - url: '{:url("api/Files/save")}', + url: '{:url("File/save")}', data: { type: 2, dir: 'admin_avatar' diff --git a/view/admin/category/create.html b/view/admin/category/create.html index 2b8fa67..de08355 100644 --- a/view/admin/category/create.html +++ b/view/admin/category/create.html @@ -112,7 +112,7 @@ upload.render({ elem: '.upload-title-img', - url: '{:url("api/Files/save")}', + url: '{:url("File/save")}', data: { type: 4, dir: 'article' diff --git a/view/admin/category/edit.html b/view/admin/category/edit.html index bee4000..317ffdf 100644 --- a/view/admin/category/edit.html +++ b/view/admin/category/edit.html @@ -121,7 +121,7 @@ upload.render({ elem: '.upload-title-img', - url: '{:url("api/Files/save")}', + url: '{:url("File/save")}', data: { type: 4, dir: 'article' diff --git a/view/admin/common/left_system.html b/view/admin/common/left_system.html index 7d21349..39a5d9a 100644 --- a/view/admin/common/left_system.html +++ b/view/admin/common/left_system.html @@ -37,6 +37,23 @@ {/if} + {if get_system_config('index_tpl_name') == 'articles_' } + + + {/if}