Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
yirius committed Mar 26, 2019
1 parent ba7f602 commit 3022d7f
Show file tree
Hide file tree
Showing 9 changed files with 868 additions and 372 deletions.
552 changes: 215 additions & 337 deletions .idea/workspace.xml

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions src/controller/Cms.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ public function templates()
*/
public function templatesEdit($id = 0)
{
return Admin::form("thinker_cms_templatesedit", function(Form $form) use($id){
return Admin::form("thinker_cms_templatesedit", function (Form $form) use ($id) {

$form->setValue($id == 0 ? [] : CmsTemplates::get(['id' => $id]));

Expand All @@ -479,7 +479,7 @@ public function templatesEdit($id = 0)
*/
public function templateVars($id)
{
return Admin::table("thinker_cms_templatevars", function(Table $table) use($id){
return Admin::table("thinker_cms_templatevars", function (Table $table) use ($id) {
$table
->setRestfulUrl("/restful/cmstemplatesvars?templateid=" . $id)
->setEditPath("/thinkercms/templateVarsEdit?templateid=" . $id);
Expand All @@ -506,14 +506,15 @@ public function templateVars($id)
/**
* @title templateVarsEdit
* @description
* @createtime 2019/3/22 下午3:19
* @createtime 2019/3/26 下午2:00
* @param $templateid
* @param int $id
* @return mixed
* @throws \Exception
*/
public function templateVarsEdit($templateid, $id = 0)
{
return Admin::form("thinker_cms_templatevarsedit", function(Form $form) use($templateid, $id){
return Admin::form("thinker_cms_templatevarsedit", function (Form $form) use ($templateid, $id) {

$form->setValue($id == 0 ? [] : CmsTemplatesVars::get(['id' => $id]));

Expand Down
118 changes: 107 additions & 11 deletions src/controller/CmsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

use think\facade\View;
use Yirius\Admin\Admin;
use Yirius\Admin\model\table\AdminConfigs;
use Yirius\AdminCms\model\CmsColumns;
use Yirius\AdminCms\model\CmsGuestbookAttr;
use Yirius\AdminCms\model\CmsTemplates;
use Yirius\AdminCms\model\CmsTemplatesVars;

Expand All @@ -28,6 +30,12 @@ class CmsController

protected $cmsTemplatePath = '';

/**
* CmsController constructor.
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function __construct()
{
$this->view = View::init();
Expand All @@ -41,6 +49,8 @@ public function __construct()
$this->cmsTemplate['path']
);

$this->view->config("view_path", $this->cmsTemplatePath);

//找到所有自定义变量, 取值渲染
$templateVars = CmsTemplatesVars::where('templateid', '=', $this->cmsTemplate['id'])->select();
$assignValues = [
Expand All @@ -50,38 +60,124 @@ public function __construct()
$assignValues[$v['name']] = $v['value'];
}
$this->assign("_config", $assignValues);

//找到网站设置
$this->assign("_siteconfig", AdminConfigs::getValues());

//find top columns
$topMenus = CmsColumns::where([
['is_hidden', '=', 0],
['status', '=', 1]
])->field("id,name,pid,modelid")->order("list_order", "desc")->select()
->each(function($item){
$item->cms_models;
})->toArray();

$this->assign('topMenus', Admin::tools()->tree($topMenus, null));
}

/**
* @title index
* @description
* @description CmsIndexPage
* @createtime 2019/3/22 下午2:14
* @return string
* @throws \Exception
*/
public function index()
{
//find top columns
$topMenus = CmsColumns::where([
['is_hidden', '=', 0],
['status', '=', 1]
])->field("id,name,pid")->order("list_order", "desc")->select()->toArray();

//find latest five news
$latestFiveCms = \Yirius\AdminCms\model\Cms::order("list_order", "desc")
$latestFiveCms = \Yirius\AdminCms\model\Cms::with("CmsModels")
->order("list_order", "desc")
->limit(5)->select()->toArray();


//render home page
return $this->assign([
'topMenus' => Admin::tools()->tree($topMenus, null),
'latestcms' => $latestFiveCms
])->fetch("index");
}

public function cms()
/**
* @title article
* @description
* @createtime 2019/3/26 下午3:20
* @param $id
* @return string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function article($id)
{
//render home page
return $this->assign(
"article_content",
\Yirius\AdminCms\model\Cms::with("CmsColumns,CmsModels")
->where("columnid", '=', $id)
->select()
)->fetch("article");
}

/**
* @title single
* @description
* @createtime 2019/3/26 下午4:38
* @param $id
* @return string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function single($id)
{
//render home page
return $this->assign(
"article_content",
\Yirius\AdminCms\model\Cms::with("CmsColumns,CmsModels")
->where("columnid", '=', $id)
->find()
)->fetch("single");
}

/**
* @title guestbook
* @description
* @createtime 2019/3/26 下午4:47
* @param $id
* @return string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function guestbook($id)
{
$guestbookAttr = CmsGuestbookAttr::where('columnid', '=', $id)->select();

//render home page
return $this->assign("guestbook_content", $guestbookAttr)->fetch("guestbook");
}

/**
* @title product
* @description
* @createtime 2019/3/26 下午4:50
* @param $id
* @return string
*/
public function product($id)
{
return '';
}

/**
* @title download
* @description
* @createtime 2019/3/26 下午7:57
* @param $id
* @return string
*/
public function download($id)
{
return '';
}

/**
Expand Down
7 changes: 6 additions & 1 deletion src/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@
\think\facade\Route::resource("restful/cmstemplatesvars", "\\Yirius\\AdminCms\\restful\\CmsTemplatesVars");

//便捷访问
\think\facade\Route::get("cms_:id", "Index/cms");
\think\facade\Route::get("article_:id", "Index/Article");
\think\facade\Route::get("download_:id", "Index/Download");
\think\facade\Route::get("product_:id", "Index/Product");
\think\facade\Route::get("guestbook_:id", "Index/Guestbook");
\think\facade\Route::get("single_:id", "Index/Single");
\think\facade\Route::get("images_:id", "Index/Images");
138 changes: 138 additions & 0 deletions src/templates/default/article.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
{extend name="base" /}

{block name="content"}

<style>
.blog-area {
background: rgba(31, 88, 177, .7);
border-radius: 14px;
}

.blog-area .blog figure {
height: 40%;
}

.container, .row, .blog-slider, .owl-wrapper-outer, .owl-wrapper, .owl-item, .blog-area .blog figure img {
height: 100%;
}

.animation-visibility {
height: 80%;
margin: 10% 0;
}

@media screen and (max-height: 667px) {
.animation-visibility {
height: 100%;
margin: 0;
overflow-y: scroll !important;
}
}

#showArticleDetail {
position: fixed;
right: 0;
height: 100%;
width: 100%;
top: 0;
z-index: 10000;
display: none;
background: rgba(0, 0, 0, 0.4);
}

#showArticleDetail .content {
width: 60%;
position: absolute;
top: 0;
right: 0;
height: 100%;
background: #fff;
padding: 20px;
overflow-y: scroll;
}

#showArticleDetail .content p {
color: #000;
}

@media screen and (max-width: 750px) {
#showArticleDetail .content {
width: 80%;
}
}
</style>

<section class="blog-area" style="width: 90%;left: 5%;padding: 20px 0;height: 90%;">
<div class="container">
<div class="row">
<div class="blog-slider">
{foreach name="article_content" item="article_content_val"}
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" style="height: 100%;">
<div class="blog wow fadeIn animated animation-visibility"
data-wow-duration="1.3s" style="animation-duration: 1.3s;background: #0d469f;"
data-id="{$article_content_val['id']}">
<figure>
<img src="{$article_content_val['coverpic']|default='/templates/default/images/blog/1.jpg'}"
alt=""/>
</figure>
<div class="content" style="bottom: 0;">
<span>
<i class="fa fa-calendar-o"></i>
{:date("m月d日,Y年", strtotime($article_content_val['create_time']))}
</span>
<h4>
<a href="#">
{:mb_substr(strip_tags($article_content_val['title']), 0, 30)}...
</a>
</h4>
<p>
{:mb_substr(strip_tags($article_content_val['content']), 0, 100)}...
</p>
<a href="#" class="blog-btn">
阅读全文 <i class="fa fa-arrow-circle-o-right"></i>
</a>
</div>
</div>
</div>
{/foreach}
</div>
</div>
</div>
</section>
{/block}

{block name="other"}
<div id="showArticleDetail">
<div class="content">
<h2></h2>
<div class="">

</div>
</div>
</div>
{/block}

{block name="scripts"}
<script>
var articlesList = {:json_encode($article_content)};
var showArticleDetail = $("#showArticleDetail");
$(".animation-visibility").on("click", function () {
if ($(this).data("id")) {
var id = $(this).data("id");
for (var i in articlesList) {
if (id == articlesList[i].id) {
showArticleDetail.find("h2").html(articlesList[i].title);
showArticleDetail.find(".content>div").html(articlesList[i].content);
showArticleDetail.fadeIn();
break;
}
}
}
});
showArticleDetail.on("click", function (e) {
if (e.target.id == "showArticleDetail") {
showArticleDetail.fadeOut();
}
});
</script>
{/block}
Loading

0 comments on commit 3022d7f

Please sign in to comment.