diff --git a/app/admin/controller/Login.php b/app/admin/controller/Login.php
index 1d7bed2..6ba078f 100644
--- a/app/admin/controller/Login.php
+++ b/app/admin/controller/Login.php
@@ -36,22 +36,16 @@ class Login extends Common
});
if(!$validate->check($post_data)){
- Session::set('admin_id',1);
- return json_message();
return json_message($validate->getError());
}
$model_admin = Admin::where('account',$post_data['account'])->find();
if(empty($model_admin)){
- Session::set('admin_id',1);
- return json_message();
return json_message('帐号不存在');
}
if($model_admin->getData('password') !== md5($post_data['password'].$model_admin->getData('salt'))){
- Session::set('admin_id',1);
- return json_message();
return json_message('密码错误');
}
diff --git a/app/index/controller/Index.php b/app/index/controller/Index.php
index 3d0f232..3519b84 100644
--- a/app/index/controller/Index.php
+++ b/app/index/controller/Index.php
@@ -16,10 +16,23 @@ class Index extends Common
*
* @return \think\Response
*/
- public function index()
+ public function index($post_id = 0)
{
//
+ $list_post = Post::where('status', 1)->order('sort desc')->select();
+
+ if (empty($post_id)) {
+ $model_post = $list_post->first();
+ } else {
+ $model_post = $list_post->where('id', $post_id)->first();
+ }
+
+
+ View::assign('model_post', $model_post);
+
+ View::assign('list_post', $list_post);
+
return View::fetch();
}
diff --git a/app/model/Post.php b/app/model/Post.php
index 831562b..7c3d18e 100644
--- a/app/model/Post.php
+++ b/app/model/Post.php
@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace app\model;
+use think\facade\App;
use think\Model;
use think\model\concern\SoftDelete;
@@ -15,8 +16,8 @@ class Post extends Model
//
public static $stausNameList = [
- 0=>'不发布',
- 1=>'发布'
+ 0 => '不发布',
+ 1 => '发布'
];
use SoftDelete;
@@ -25,12 +26,12 @@ class Post extends Model
public function categorys()
{
- return $this->hasMany(PostCategory::class,'post_id');
+ return $this->hasMany(PostCategory::class, 'post_id');
}
public function tags()
{
- return $this->hasMany(PostTag::class,'post_id');
+ return $this->hasMany(PostTag::class, 'post_id');
}
public function setPublishTimeAttr($value)
@@ -41,22 +42,22 @@ class Post extends Model
{
$value = $this->getData('publish_time');
- return date('Y-m-d',$value);
+ return date('Y-m-d', $value);
}
public function getPublishTimeDatetimeAttr()
{
$value = $this->getData('publish_time');
- return date('Y-m-d H:i:s',$value);
+ return date('Y-m-d H:i:s', $value);
}
public function getCategorysListAttr()
{
$list_post_categorys = $this->getAttr('categorys');
- $list = array_column($list_post_categorys->append(['category'])->toArray(),'category');
+ $list = array_column($list_post_categorys->append(['category'])->toArray(), 'category');
- $list = array2level($list,0,0);
+ $list = array2level($list, 0, 0);
return $list;
}
@@ -65,7 +66,7 @@ class Post extends Model
{
$list_post_tags = $this->getAttr('tags');
- $list = array_column($list_post_tags->append(['tag'])->toArray(),'tag');
+ $list = array_column($list_post_tags->append(['tag'])->toArray(), 'tag');
return $list;
}
@@ -74,8 +75,8 @@ class Post extends Model
{
$desc = $this->getData('desc');
- if(strlen($desc) > 100){
- $desc = mb_substr($desc,0,100).'...';
+ if (strlen($desc) > 100) {
+ $desc = mb_substr($desc, 0, 100) . '...';
}
return $desc;
@@ -85,7 +86,7 @@ class Post extends Model
{
$desc = $this->getData('desc');
- if(empty($desc)){
+ if (empty($desc)) {
return '';
}
$list = explode("\n", $desc);
@@ -97,11 +98,11 @@ class Post extends Model
{
$desc = $this->getData('desc');
- if(empty($desc)){
+ if (empty($desc)) {
return '';
}
- return str_replace("\n",'
',$desc);
+ return str_replace("\n", '
', $desc);
}
public function getStatusNameAttr()
@@ -125,15 +126,31 @@ class Post extends Model
public function getContentAttr($value)
{
- return json_decode($value,true);
+ return json_decode($value, true);
}
public function getPosterAttr($value)
{
- if(empty($value)){
+ if (empty($value)) {
$value = '/static/images/avatar.png';
}
return get_source_link($value);
}
+
+ public function getDemoPageAttr()
+ {
+ if (empty($this->getData('tpl_name'))) {
+ return '';
+ }
+
+ $base_dir = App::getRootPath() . '/demo/';
+
+ $file_path = $base_dir . $this->getData('tpl_name') . '.html';
+ if (!file_exists($file_path)) {
+ return '';
+ }
+
+ return file_get_contents($file_path);
+ }
}
diff --git a/demo/list.html b/demo/list.html
new file mode 100644
index 0000000..bb9c6a9
--- /dev/null
+++ b/demo/list.html
@@ -0,0 +1,6 @@
+