作者 景龙
1 个管道 的构建 通过 耗费 1 秒

修改首页轮播和增加收藏文章功能

... ... @@ -9,7 +9,9 @@ namespace app\portal\controller;
use app\portal\model\UserModel;
use app\portal\validate\UsersValidate;
use cmf\controller\HomeBaseController;
use app\portal\model\CollectionModel;
use cmf\lib\Storage;
use think\Db;
use anerg\OAuth2\OAuth;
use think\Config;
... ... @@ -170,6 +172,40 @@ class LoginController extends HomeBaseController
}
}
//我的收藏列表
public function myCollection(){
$limit = 8;
$uid = cmf_get_current_user_id();
$collectionModel = new CollectionModel();
$res = $collectionModel
->where(['uid'=>$uid])
->field('id,post_id,category_name,city_name,post_url')
->order('id desc')
->paginate($limit);
$data = $res->toArray();
$page = $res->render();
$post_ids = array_unique(array_column($data['data'],'post_id'));
$data1 = Db::name('portal_post')
->whereIn('id',$post_ids)
->where('delete_time', 0)
->field('id,post_title,post_excerpt,post_favorites')
->order('weigh desc')
->select()
->toArray();
foreach($data['data'] as &$value){
foreach ($data1 as $item) {
if($value['post_id'] == $item['id']){
$value['post_title'] = $item['post_title'];
$value['post_excerpt'] = $item['post_excerpt'];
$value['post_favorites'] = $item['post_favorites'];
}
}
}
$this->assign('res',$data['data']);
$this->assign('page',$page);
return $this->fetch();
}
//第三方微信登录
public function wx_login(){
$config = Config::get('wx_login');
... ...
... ... @@ -368,10 +368,34 @@ class StarController extends HomeBaseController
//判断是否登录
$login = cmf_is_user_login();
$article_id = $this->request->param('article_id');//文章id
$post_url = $this->request->param('post_url');//文章链接
if($login){
$data['uid'] = cmf_get_current_user_id();
$data['post_id'] = $article_id;
$data['create_time'] = time();
$data['post_id'] = $article_id;//文章id
$data['post_url'] = $post_url;
//查找分类名称
$category = Db::name('portal_category_post')
->where('post_id',$article_id)
->field('category_id')
->find();
$category_name = Db::name('portal_category')
->where('id',$category['category_id'])
->field('name')
->find();
//查找城市名称
$city = Db::name('portal_post')
->where('id',$article_id)
->where('delete_time',0)
->field('city_id')
->find();
$city_name = Db::name('city_category')
->where('id',$city['city_id'])
->field('name')
->find();
$data['category_name'] = $category_name['name'];//分类名称
$data['city_name'] = isset($city_name['name']) && !empty($city_name['name'])?$city_name['name']:'';//城市名称
$data['create_time'] = time();//
$data['update_time'] = time();
$collectionModel = new CollectionModel();
$res = $collectionModel->allowField(true)->save($data);
... ...
... ... @@ -19,6 +19,9 @@
.swiper-container6{
overflow: hidden;
}
.swiper-container6 .swiper-wrapper{
transition-duration:1.5s !important;
}
</style>
</head>
... ... @@ -788,16 +791,13 @@
var swiper = new Swiper('.swiper-container6', {
slidesPerView: 1,
spaceBetween: 0,
centeredSlides: true,
autoplay: {
delay: 4000,
disableOnInteraction: false,
},
// pagination: {
// el: '.swiper-pagination',
// clickable: true,
// },
navigation: {
nextEl: '.swiper-button-nextban',
prevEl: '.swiper-button-prevban'
... ...
... ... @@ -43,7 +43,7 @@
<span>修改资料</span>
</div>
<!--我的收藏-->
<div class="Collection clearfix">
<div class="Collection clearfix" id="myCollection">
<div class="Collection_icon">
<img src="__TMPL__/public/assets/starImg/aicon_86.png" alt="">
</div>
... ...
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>我的收藏</title>
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="__TMPL__/public/assets/css/bootstrap4.0.css">
<link rel="stylesheet" href="__TMPL__/public/assets/css/header1.css">
<link rel="stylesheet" href="__TMPL__/public/assets/css/collection.css">
<style>
.post_url{
cursor: pointer;
}
.post_url:hover{
text-decoration: none;
}
.collection_item_title:hover{
color:#09FF8E;
}
</style>
</head>
<body>
<include file="public@header"/>
<!--内容-->
<main>
<div class="container">
<!--收藏-->
<div class="collection">
<div class="collection_list">
<volist name="res" id="vo">
<div class="collection_item">
<a href="{$vo.post_url}" class="post_url">
<div class="collection_item_title">
{$vo.post_title}
</div>
</a>
<div class="collection_item_main">
{$vo.post_excerpt}
</div>
<div class="collection_item_bottom clearfix">
<div class="collection_item_bottom_left clearfix">
<div class="collection_bottom_left_item">{$vo.category_name}</div>
<notempty name="vo.city_name">
<div class="collection_bottom_left_item">{$vo.city_name}</div>
</notempty>
</div>
<div class="collection_item_bottom_right clearfix">
<div class="collection_bottom_right_img">
<img src="__TMPL__/public/assets/starImg/bicon_13.png" alt="">
</div>
<div class="collection_bottom_right_num">{$vo.post_favorites}</div>
</div>
</div>
</div>
</volist>
</div>
<!--分页-->
<div class="pagination">
{$page|default=''}
</div>
</div>
</div>
</main>
<!-- 底部 -->
<include file="public@footer"/>
<script src="__TMPL__/public/assets/js/jquery-3.2.1.min.js"></script>
<script src="__TMPL__/public/assets/js/public.js"></script>
</body>
</html>
... ...
.container{
width: 1200px;
margin: 0 auto;
}
body{
background: #3C3C94;
}
main{
padding-top: 74px;
box-sizing: border-box;
padding-bottom: 100px;
}
main .container{
width: 900px;
margin: 0 auto;
background: #fff;
margin-bottom:50px;
}
.collection_list{
background: #fff;
padding: 0 30px;
}
.collection_item{
width: 100%;
border-bottom: 1px solid #EBEBEB;
padding-bottom: 30px;
}
.collection_item_title{
font-size: 18px;
color: #1A1A1A;
font-weight: bold;
padding-top: 30px;
}
.collection_item_main{
padding: 20px 0;
font-size: 14px;
color: #999999;
}
.collection_bottom_left_item{
padding-right: 10px;
padding-left: 10px;
border-right: 1px solid #EBEBEB;
float: left;
}
.collection_bottom_left_item:first-child{
padding-left: 0;
}
.collection_item_bottom_left,.collection_item_bottom_right,.collection_bottom_right_num{
float: left;
}
.collection_bottom_right_img{
float: left;
}
.collection_bottom_right_img img{
width: 14px;
height: 12px;
vertical-align: middle;
margin-left: 10px;
margin-right: 7px;
cursor: pointer;
}
\ No newline at end of file
... ...
body,
ol,
ul,
h1,
h2,
h3,
h4,
h5,
h6,
p,
th,
td,
dl,
dd,
form,
fieldset,
legend,
input,
textarea,
select {
margin: 0;
padding: 0
}
body {
font: 12px "微软雅黑", "MicrosoftYaHei", HELVETICA;
background: #fff;
-webkit-text-size-adjust: 100%;
color: rgba(51, 51, 51, 1);
}
a {
color: #2d374b;
text-decoration: none
}
em,
i {
font-style: normal
}
li {
list-style: none
}
img {
border: 0;
vertical-align: middle
}
table {
border-collapse: collapse;
border-spacing: 0
}
p {
word-wrap: break-word
}
/* 头部 */
#header {
width: 100%;
background: #fff;
margin: 0 auto;
height: 80px;
line-height: 80px
}
#header section {
float: left;
}
/* logo */
#header .home_logo {
width: 110px;
height: 70px;
margin: 0 75px 0 0px;
}
#header .home_logo img {
width: 100%;
height: 100%
}
/* 导航栏 */
#header .home_nav ul li {
float: left;
font-size: 17px;
color: rgba(77, 77, 77, 1);
width: 70px;
height: 76px;
margin: 0 15px;
text-align: center;
border-top: 4px solid rgba(255, 255, 255, 1);
}
/* 搜索框 */
#header .home_search {
position: relative;
/* width: 308px;*/
}
/* 图标 */
#header .home_search .search_icon {
position: absolute;
left: 30px;
top: 30px;
background-image: url("../starImg/aicon_23.png");
background-repeat: no-repeat;
background-position: 0px 0px;
width: 18px;
height: 18px;
z-index: 3
}
/* 输入框 */
#header .home_search input {
margin: 0 16px 0 16px;
width: 160px;
height: 33px;
background: rgba(242, 242, 242, 1);
border-radius: 17px;
outline: none;
border: none;
padding-left: 40px;
}
/* 登录注册按钮 */
#header .home_login span p {
float: left;
margin-left: 16px
}
\ No newline at end of file
... ...
... ... @@ -97,11 +97,16 @@ $(function(){
window.location.href = '/portal/login/editInfo';
});
//我的收藏页面
$('#myCollection').click(function(){
window.location.href = '/portal/login/myCollection';
});
//评论
$('#comment').click(function(){
var content = $('#comment_content').val();
var article_id = getUrlParam('id');
var url = window.location.href;
var url = window.location.pathname+window.location.search;
$.ajax({
type: 'POST',
url: "/portal/star/comment",
... ... @@ -133,11 +138,13 @@ $(function(){
function operation(url){
var article_id = getUrlParam('id');
var is_login = 1;
var post_url = window.location.pathname+window.location.search;
$.ajax({
type: 'POST',
url: url,
data: {
'article_id':article_id,
'post_url':post_url
},
dataType: 'json',
async : false,
... ...