Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xchenhao
blog
提交
823e0cee
B
blog
项目概览
xchenhao
/
blog
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
1
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
blog
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
823e0cee
编写于
10月 03, 2019
作者:
xchenhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change index and list style
上级
bfc4bee4
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
86 addition
and
178 deletion
+86
-178
backend/views/category/_form.php
backend/views/category/_form.php
+1
-1
common/models/Category.php
common/models/Category.php
+20
-3
frontend/controllers/ArticleController.php
frontend/controllers/ArticleController.php
+27
-7
frontend/views/article/cover.php
frontend/views/article/cover.php
+2
-49
frontend/views/article/index.php
frontend/views/article/index.php
+0
-28
frontend/views/article/list.php
frontend/views/article/list.php
+7
-90
frontend/views/layouts/header.php
frontend/views/layouts/header.php
+29
-0
未找到文件。
backend/views/category/_form.php
浏览文件 @
823e0cee
...
...
@@ -17,7 +17,7 @@ use common\models\Category;
<?php
$categorys
=
Category
::
getAllTreeList
();
$options
=
array_column
(
$categorys
,
'name'
,
'id'
);
$options
=
array_column
(
$categorys
,
'
_
name'
,
'id'
);
?>
<?=
$form
->
field
(
$model
,
'parent_id'
)
->
dropDownList
(
$options
,
[
'prompt'
=>
'请选择分类'
,
'required'
=>
true
]
);
?>
...
...
common/models/Category.php
浏览文件 @
823e0cee
...
...
@@ -15,6 +15,9 @@ use Yii;
* @property integer $attr
* @property integer $create_time
* @property integer $modified_time
*
* // magic field
* @property bool isCoverAttr
*/
class
Category
extends
\
yii\db\ActiveRecord
{
...
...
@@ -96,12 +99,15 @@ class Category extends \yii\db\ActiveRecord
/**
* 获取一维的树形结构(树形权体现在显示的名称上)
*
* @param int $parent_id
* @param int $max_level
*
* @return array
*/
public
static
function
getAllTreeList
(
)
public
static
function
getAllTreeList
(
int
$parent_id
=
0
,
$max_level
=
0
):
array
{
$list
=
self
::
getAllCategory
();
return
self
::
getTreeList
(
$list
,
0
,
0
);
return
self
::
getTreeList
(
$list
,
$parent_id
,
$max_level
);
}
/**
...
...
@@ -121,10 +127,11 @@ class Category extends \yii\db\ActiveRecord
}
$output
[]
=
[
'id'
=>
$item
[
'id'
],
'name'
=>
str_repeat
(
' '
,
$level
*
9
)
.
'┗'
.
str_repeat
(
'---'
,
$level
)
.
$item
[
'name'
],
'name'
=>
$item
[
'name'
],
'level'
=>
$level
,
//'margin' => str_repeat('---', $level),
'parent_id'
=>
$item
[
'parent_id'
],
'_name'
=>
str_repeat
(
' '
,
$level
*
9
)
.
'┗'
.
str_repeat
(
'---'
,
$level
)
.
$item
[
'name'
],
'attr'
=>
0
,
];
self
::
getTreeList
(
$list
,
$item
[
'id'
],
$level
+
1
);
...
...
@@ -211,4 +218,14 @@ class Category extends \yii\db\ActiveRecord
->
indexBy
(
'id'
)
->
column
();
}
public
static
function
isCoverAttr
(
int
$attr
):
bool
{
return
0
!==
(
self
::
ATTR_COVER
&
$attr
);
}
public
function
getIsCoverAttr
():
bool
{
return
self
::
isCoverAttr
(
$this
->
attr
);
}
}
frontend/controllers/ArticleController.php
浏览文件 @
823e0cee
...
...
@@ -74,17 +74,37 @@ class ArticleController extends Controller
]);
}
public
function
actionCover
()
/**
* 文章列表
*
* @param int $category_id
* @return string
*/
public
function
actionList
(
int
$category_id
)
{
return
$this
->
render
(
'cover'
,
[
$category
=
Category
::
findOne
([
'id'
=>
$category_id
]);
$view_tpl
=
$category
->
isCoverAttr
?
'cover'
:
'list'
;
]);
}
$cats
=
Category
::
getAllTreeList
(
$category_id
);
$cat_ids
=
array_column
(
$cats
,
'id'
);
$cat_ids
=
array_map
(
'intval'
,
$cat_ids
);
$cat_ids
[]
=
$category_id
;
public
function
actionList
(
int
$category_id
)
{
return
$this
->
render
(
'list'
,
[
$articles
=
Article
::
find
()
->
where
([
'category_id'
=>
$cat_ids
])
->
orderBy
(
'view_count DESC'
)
->
asArray
()
->
all
();
$category_names
=
array_column
(
$cats
,
'name'
,
'id'
);
$category_names
[
$category_id
]
=
$category
->
name
;
$articles
=
array_map
(
function
(
$item
)
use
(
$category_names
)
{
$item
[
'category_name'
]
=
$category_names
[
$item
[
'category_id'
]]
??
''
;
$item
[
'create_time'
]
=
date
(
'Y-m-d H:i:s'
,
$item
[
'create_time'
]);
return
$item
;
},
$articles
);
return
$this
->
render
(
$view_tpl
,
[
'articles'
=>
$articles
,
]);
}
...
...
frontend/views/article/cover.php
浏览文件 @
823e0cee
...
...
@@ -17,57 +17,10 @@
<div
class=
"askcontent"
style=
"min-height: inherit"
>
<ul
class=
"ask_user_area clearfix"
id=
"ask_ulist"
>
<?php
$articles
=
[
[
'id'
=>
1
,
'thumb'
=>
'http://hdcms.com/attachment/2017/07/27/51171501088571.jpg'
,
'title'
=>
'向荒野致敬:过去25年的25张户外探险奇照'
,
'created_at'
=>
'2017-07-27 01:04:29'
,
'author'
=>
'小迪 编译整理'
,
],
[
'id'
=>
1
,
'thumb'
=>
'http://hdcms.com/attachment/2017/07/27/77231501087130.jpg'
,
'title'
=>
'野路子 | 攀登我的大天堂,找到属于自己的那座山'
,
'created_at'
=>
'2017-07-27 00:39:52'
,
'author'
=>
'Kurt'
,
],
[
'id'
=>
1
,
'thumb'
=>
'http://hdcms.com/attachment/2017/07/27/11141501089665.jpg'
,
'title'
=>
'山居普罗旺斯'
,
'created_at'
=>
'2017-07-27 01:22:04'
,
'author'
=>
'Jing'
,
],
[
'id'
=>
1
,
'thumb'
=>
'http://hdcms.com/attachment/2017/07/27/79431501089775.jpg'
,
'title'
=>
'走近冈仁波齐,世界中心的雪山'
,
'created_at'
=>
'2017-07-27 01:23:33'
,
'author'
=>
'李初初'
,
],
[
'id'
=>
1
,
'thumb'
=>
'http://hdcms.com/attachment/2017/07/27/29621501089893.jpg'
,
'title'
=>
'趣看|十六年饰一梯,公寓楼也能变“凡尔赛宫”'
,
'created_at'
=>
'2017-07-27 01:25:44'
,
'author'
=>
'B2B'
,
],
[
'id'
=>
1
,
'thumb'
=>
'http://hdcms.com/attachment/2017/07/27/74671501090020.jpg'
,
'title'
=>
'马克龙要拿MPV当总统座驾?看看前任法国总统们选择的汽车'
,
'created_at'
=>
'2017-07-27 01:27:51'
,
'author'
=>
'澎湃新闻记者 栾锴韬'
,
],
];
?>
<?php
foreach
(
$articles
as
$arc
)
:
?>
<li
class=
"topic"
>
<div
class=
"ask_user_body"
>
<img
src=
"
<?=
$arc
[
'
thumb
'
]
?>
"
class=
"cover_pic"
/>
<img
src=
"
<?=
$arc
[
'
cover
'
]
?>
"
class=
"cover_pic"
/>
<div
class=
"ask_user_bgimg"
><a
href=
"/article/
<?=
$arc
[
'id'
]
?>
"
class=
"userhome"
target=
"_blank"
></a>
<div
class=
"ask_user_abstxt"
>
<a
href=
"/article/
<?=
$arc
[
'id'
]
?>
"
target=
"_blank"
>
...
...
@@ -89,7 +42,7 @@
</div>
<div
class=
"ask_user_trbs2"
>
<a
href=
"/author/1"
target=
"_blank"
class=
"u_sname"
>
作者:
<?=
$arc
[
'author'
]
?>
</a>
<span>
<?=
$arc
[
'create
d_at
'
]
?>
</span>
<span>
<?=
$arc
[
'create
_time
'
]
?>
</span>
</div>
</li>
<?php
endforeach
?>
...
...
frontend/views/article/index.php
浏览文件 @
823e0cee
...
...
@@ -39,34 +39,6 @@
<div
id=
"mainContent"
>
<div
class=
"newsbox"
id=
"masonryContent"
>
<style>
#masonryContent
{
position
:
relative
;
width
:
939px
;
height
:
740px
;
}
#masonryContent
.news_li
{
position
:
absolute
;
height
:
325px
;
}
#masonryContent
.news_li
:nth-of-type
(
3
n
+
1
)
{
left
:
0
;
}
#masonryContent
.news_li
:nth-of-type
(
3
n
+
2
)
{
left
:
313px
;
}
#masonryContent
.news_li
:nth-of-type
(
3
n
+
3
)
{
left
:
626px
;
}
#masonryContent
.news_li
:nth-of-type
(
3
n
+
3
)
{
left
:
626px
;
}
</style>
<?php
foreach
(
$articles
as
$art
)
:
?>
<div
class=
"news_li"
>
<div
class=
"news_tu"
>
...
...
frontend/views/article/list.php
浏览文件 @
823e0cee
...
...
@@ -20,112 +20,29 @@
</div>
</div>
<style>
.news_li
{
position
:
absolute
;
height
:
300px
;
}
.news_li
:nth-of-type
(
3
n
+
1
)
{
left
:
0
;
}
.news_li
:nth-of-type
(
3
n
+
2
)
{
left
:
313px
;
}
.news_li
:nth-of-type
(
3
n
+
3
)
{
left
:
626px
;
}
.news_li
:nth-of-type
(
3
n
+
3
)
{
left
:
626px
;
}
</style>
<div
id=
"mainContent"
>
<div
class=
"newsbox"
id=
"masonryContent"
style=
"position: relative; width: 939px; height: 1150px;"
>
<?php
$articles
=
[
[
'id'
=>
10
,
'title'
=>
'每一朵花的绽放,都在演绎延续数亿年的生命传奇'
,
'intro'
=>
'每一朵花的绽放,都在演绎延续数亿年的生命传奇'
,
'thumb'
=>
'http://hdcms.com/attachment/2017/07/31/9241501503150.jpg'
,
'cat_name'
=>
'读书'
,
'created_at'
=>
'2017-07-31 20:13:17'
,
'cid'
=>
3
,
'comment_num'
=>
3
,
],
[
'id'
=>
10
,
'title'
=>
'翻译弥尔顿的《失乐园》,过去30年里比之前300年还频繁'
,
'intro'
=>
'翻译弥尔顿的《失乐园》,过去30年里比之前300年还频繁'
,
'thumb'
=>
'http://hdcms.com/attachment/2017/07/26/39711501069470.jpg'
,
'cat_name'
=>
'读书'
,
'created_at'
=>
'2017-07-26 19:45:45'
,
'cid'
=>
3
,
'comment_num'
=>
7
,
],
[
'id'
=>
10
,
'title'
=>
'谢其章︱字小如蚁的《新民声半月刊》'
,
'intro'
=>
'谢其章︱字小如蚁的《新民声半月刊》'
,
'thumb'
=>
'http://hdcms.com/attachment/2017/07/25/86411500917256.jpg'
,
'cat_name'
=>
'读书'
,
'created_at'
=>
'2017-07-24 23:09:38'
,
'cid'
=>
3
,
'comment_num'
=>
4
,
],
[
'id'
=>
10
,
'title'
=>
'最新上线的京沪二手书平台:哪些作家的书有人卖没人买'
,
'intro'
=>
'最新上线的京沪二手书平台:哪些作家的书有人卖没人买'
,
'thumb'
=>
'http://hdcms.com/attachment/2017/07/26/51891501069629.jpg'
,
'cat_name'
=>
'读书'
,
'created_at'
=>
'2017-07-26 19:48:00'
,
'cid'
=>
3
,
'comment_num'
=>
1
,
],
[
'id'
=>
10
,
'title'
=>
'台湾学生如何学习马克思理论?'
,
'intro'
=>
'台湾学生如何学习马克思理论?'
,
'thumb'
=>
'http://hdcms.com/attachment/2017/07/26/80601501070654.jpg'
,
'cat_name'
=>
'读书'
,
'created_at'
=>
'2017-07-26 20:05:05'
,
'cid'
=>
3
,
'comment_num'
=>
2
,
],
];
?>
<div
class=
"newsbox"
id=
"masonryContent"
>
<?php
foreach
(
$articles
as
$arc
)
:
?>
<div
class=
"news_li"
id=
"cont271"
>
<div
class=
"news_tu"
>
<a
href=
"/article/
<?=
$arc
[
'id'
]
?>
"
class=
"tiptitleImg"
target=
"_blank"
>
<img
src=
"
<?=
$arc
[
'
thumb
'
]
?>
"
>
<img
src=
"
<?=
$arc
[
'
cover
'
]
?>
"
>
</a>
</div>
<h2><a
href=
"/article/
<?=
$arc
[
'id'
]
?>
"
target=
"_blank"
>
<?=
$arc
[
'title'
]
?>
</a></h2>
<p>
<?=
$arc
[
'title'
]
?>
</p>
<div
class=
"pdtt_trbs"
>
<a
href=
"/category/
<?=
$arc
[
'c
id'
]
?>
"
target=
"_blank"
>
<?=
$arc
[
'cat_name'
]
?>
</a><span>
<?=
$arc
[
'created_at
'
]
?>
</span>
<span
class=
"trbszan"
><span
id =
"sourceId::
<?=
$arc
[
'id'
]
?>
"
class =
"cy_cmt_count"
>
<?=
$arc
[
'comment_num'
]
?>
</span></span>
<a
href=
"/category/
<?=
$arc
[
'c
ategory_id'
]
?>
"
target=
"_blank"
>
<?=
$arc
[
'category_name'
]
?>
</a><span>
<?=
$arc
[
'create_time
'
]
?>
</span>
<span
class=
"trbszan"
><span
id =
"sourceId::
<?=
$arc
[
'id'
]
?>
"
class =
"cy_cmt_count"
>
<?=
$arc
[
'comment_num'
]
?
?
0
?
>
</span></span>
</div>
</div>
<?php
endforeach
?>
{{$arcModel->links()}}
<!--
<div class="news_li hidden" id="last1" lasttime="1500531475" pageindex="1" style="display: none !important; position: absolute; left: 0px; top: 1996px;"></div>-->
<!--
<div class="news_li hidden" id="last1" lasttime="1500531475" pageindex="1" style="display: none !important; position: absolute; left: 0px; top: 1996px;"></div>-->
</div>
{{$arcModel->links()}}
</div>
<script>
for
(
var
i
=
0
;
i
<
$
(
'
.news_li
'
).
length
;
i
++
){
var
t
=
parseInt
(
i
/
3
);
$
(
'
.news_li
'
).
eq
(
i
).
css
(
'
top
'
,
t
*
384
+
'
px
'
);
}
</script>
<script
id=
"cy_cmt_num"
src=
"https://changyan.sohu.com/upload/plugins/plugins.list.count.js?clientId=cyt8rNSI2"
></script>
...
...
frontend/views/layouts/header.php
浏览文件 @
823e0cee
...
...
@@ -41,5 +41,34 @@ use yii\helpers\Html;
})
})
</script>
<style>
#masonryContent
{
position
:
relative
;
width
:
939px
;
height
:
1600px
;
/*height: 740px;*/
/*overflow: hidden;*/
}
#masonryContent
.news_li
{
position
:
absolute
;
height
:
325px
;
}
#masonryContent
.news_li
:nth-of-type
(
3
n
+
1
)
{
left
:
0
;
}
#masonryContent
.news_li
:nth-of-type
(
3
n
+
2
)
{
left
:
313px
;
}
#masonryContent
.news_li
:nth-of-type
(
3
n
+
3
)
{
left
:
626px
;
}
#masonryContent
.news_li
:nth-of-type
(
3
n
+
3
)
{
left
:
626px
;
}
</style>
<?php
$this
->
head
()
?>
</head>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录