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

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

@@ -9,7 +9,9 @@ namespace app\portal\controller; @@ -9,7 +9,9 @@ namespace app\portal\controller;
9 use app\portal\model\UserModel; 9 use app\portal\model\UserModel;
10 use app\portal\validate\UsersValidate; 10 use app\portal\validate\UsersValidate;
11 use cmf\controller\HomeBaseController; 11 use cmf\controller\HomeBaseController;
  12 +use app\portal\model\CollectionModel;
12 use cmf\lib\Storage; 13 use cmf\lib\Storage;
  14 +use think\Db;
13 use anerg\OAuth2\OAuth; 15 use anerg\OAuth2\OAuth;
14 use think\Config; 16 use think\Config;
15 17
@@ -170,6 +172,40 @@ class LoginController extends HomeBaseController @@ -170,6 +172,40 @@ class LoginController extends HomeBaseController
170 } 172 }
171 } 173 }
172 174
  175 + //我的收藏列表
  176 + public function myCollection(){
  177 + $limit = 8;
  178 + $uid = cmf_get_current_user_id();
  179 + $collectionModel = new CollectionModel();
  180 + $res = $collectionModel
  181 + ->where(['uid'=>$uid])
  182 + ->field('id,post_id,category_name,city_name,post_url')
  183 + ->order('id desc')
  184 + ->paginate($limit);
  185 + $data = $res->toArray();
  186 + $page = $res->render();
  187 + $post_ids = array_unique(array_column($data['data'],'post_id'));
  188 + $data1 = Db::name('portal_post')
  189 + ->whereIn('id',$post_ids)
  190 + ->where('delete_time', 0)
  191 + ->field('id,post_title,post_excerpt,post_favorites')
  192 + ->order('weigh desc')
  193 + ->select()
  194 + ->toArray();
  195 + foreach($data['data'] as &$value){
  196 + foreach ($data1 as $item) {
  197 + if($value['post_id'] == $item['id']){
  198 + $value['post_title'] = $item['post_title'];
  199 + $value['post_excerpt'] = $item['post_excerpt'];
  200 + $value['post_favorites'] = $item['post_favorites'];
  201 + }
  202 + }
  203 + }
  204 + $this->assign('res',$data['data']);
  205 + $this->assign('page',$page);
  206 + return $this->fetch();
  207 + }
  208 +
173 //第三方微信登录 209 //第三方微信登录
174 public function wx_login(){ 210 public function wx_login(){
175 $config = Config::get('wx_login'); 211 $config = Config::get('wx_login');
@@ -368,10 +368,34 @@ class StarController extends HomeBaseController @@ -368,10 +368,34 @@ class StarController extends HomeBaseController
368 //判断是否登录 368 //判断是否登录
369 $login = cmf_is_user_login(); 369 $login = cmf_is_user_login();
370 $article_id = $this->request->param('article_id');//文章id 370 $article_id = $this->request->param('article_id');//文章id
  371 + $post_url = $this->request->param('post_url');//文章链接
371 if($login){ 372 if($login){
372 $data['uid'] = cmf_get_current_user_id(); 373 $data['uid'] = cmf_get_current_user_id();
373 - $data['post_id'] = $article_id;  
374 - $data['create_time'] = time(); 374 + $data['post_id'] = $article_id;//文章id
  375 + $data['post_url'] = $post_url;
  376 + //查找分类名称
  377 + $category = Db::name('portal_category_post')
  378 + ->where('post_id',$article_id)
  379 + ->field('category_id')
  380 + ->find();
  381 + $category_name = Db::name('portal_category')
  382 + ->where('id',$category['category_id'])
  383 + ->field('name')
  384 + ->find();
  385 +
  386 + //查找城市名称
  387 + $city = Db::name('portal_post')
  388 + ->where('id',$article_id)
  389 + ->where('delete_time',0)
  390 + ->field('city_id')
  391 + ->find();
  392 + $city_name = Db::name('city_category')
  393 + ->where('id',$city['city_id'])
  394 + ->field('name')
  395 + ->find();
  396 + $data['category_name'] = $category_name['name'];//分类名称
  397 + $data['city_name'] = isset($city_name['name']) && !empty($city_name['name'])?$city_name['name']:'';//城市名称
  398 + $data['create_time'] = time();//
375 $data['update_time'] = time(); 399 $data['update_time'] = time();
376 $collectionModel = new CollectionModel(); 400 $collectionModel = new CollectionModel();
377 $res = $collectionModel->allowField(true)->save($data); 401 $res = $collectionModel->allowField(true)->save($data);
@@ -19,6 +19,9 @@ @@ -19,6 +19,9 @@
19 .swiper-container6{ 19 .swiper-container6{
20 overflow: hidden; 20 overflow: hidden;
21 } 21 }
  22 + .swiper-container6 .swiper-wrapper{
  23 + transition-duration:1.5s !important;
  24 + }
22 </style> 25 </style>
23 </head> 26 </head>
24 27
@@ -788,16 +791,13 @@ @@ -788,16 +791,13 @@
788 791
789 792
790 var swiper = new Swiper('.swiper-container6', { 793 var swiper = new Swiper('.swiper-container6', {
  794 + slidesPerView: 1,
791 spaceBetween: 0, 795 spaceBetween: 0,
792 centeredSlides: true, 796 centeredSlides: true,
793 autoplay: { 797 autoplay: {
794 delay: 4000, 798 delay: 4000,
795 disableOnInteraction: false, 799 disableOnInteraction: false,
796 }, 800 },
797 -// pagination: {  
798 -// el: '.swiper-pagination',  
799 -// clickable: true,  
800 -// },  
801 navigation: { 801 navigation: {
802 nextEl: '.swiper-button-nextban', 802 nextEl: '.swiper-button-nextban',
803 prevEl: '.swiper-button-prevban' 803 prevEl: '.swiper-button-prevban'
@@ -43,7 +43,7 @@ @@ -43,7 +43,7 @@
43 <span>修改资料</span> 43 <span>修改资料</span>
44 </div> 44 </div>
45 <!--我的收藏--> 45 <!--我的收藏-->
46 - <div class="Collection clearfix"> 46 + <div class="Collection clearfix" id="myCollection">
47 <div class="Collection_icon"> 47 <div class="Collection_icon">
48 <img src="__TMPL__/public/assets/starImg/aicon_86.png" alt=""> 48 <img src="__TMPL__/public/assets/starImg/aicon_86.png" alt="">
49 </div> 49 </div>
  1 +<!DOCTYPE html>
  2 +<html lang="en">
  3 +
  4 +<head>
  5 + <meta charset="UTF-8">
  6 + <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7 + <title>我的收藏</title>
  8 + <meta http-equiv="X-UA-Compatible" content="ie=edge">
  9 + <link rel="stylesheet" href="__TMPL__/public/assets/css/bootstrap4.0.css">
  10 + <link rel="stylesheet" href="__TMPL__/public/assets/css/header1.css">
  11 + <link rel="stylesheet" href="__TMPL__/public/assets/css/collection.css">
  12 + <style>
  13 + .post_url{
  14 + cursor: pointer;
  15 + }
  16 + .post_url:hover{
  17 + text-decoration: none;
  18 + }
  19 + .collection_item_title:hover{
  20 + color:#09FF8E;
  21 + }
  22 + </style>
  23 +</head>
  24 +
  25 +<body>
  26 + <include file="public@header"/>
  27 + <!--内容-->
  28 + <main>
  29 + <div class="container">
  30 + <!--收藏-->
  31 + <div class="collection">
  32 + <div class="collection_list">
  33 + <volist name="res" id="vo">
  34 + <div class="collection_item">
  35 + <a href="{$vo.post_url}" class="post_url">
  36 + <div class="collection_item_title">
  37 + {$vo.post_title}
  38 + </div>
  39 + </a>
  40 + <div class="collection_item_main">
  41 + {$vo.post_excerpt}
  42 + </div>
  43 + <div class="collection_item_bottom clearfix">
  44 + <div class="collection_item_bottom_left clearfix">
  45 + <div class="collection_bottom_left_item">{$vo.category_name}</div>
  46 + <notempty name="vo.city_name">
  47 + <div class="collection_bottom_left_item">{$vo.city_name}</div>
  48 + </notempty>
  49 + </div>
  50 + <div class="collection_item_bottom_right clearfix">
  51 + <div class="collection_bottom_right_img">
  52 + <img src="__TMPL__/public/assets/starImg/bicon_13.png" alt="">
  53 + </div>
  54 + <div class="collection_bottom_right_num">{$vo.post_favorites}</div>
  55 + </div>
  56 + </div>
  57 + </div>
  58 + </volist>
  59 + </div>
  60 + <!--分页-->
  61 + <div class="pagination">
  62 + {$page|default=''}
  63 + </div>
  64 + </div>
  65 + </div>
  66 + </main>
  67 + <!-- 底部 -->
  68 + <include file="public@footer"/>
  69 + <script src="__TMPL__/public/assets/js/jquery-3.2.1.min.js"></script>
  70 + <script src="__TMPL__/public/assets/js/public.js"></script>
  71 +
  72 +</body>
  73 +
  74 +</html>
  1 +.container{
  2 + width: 1200px;
  3 + margin: 0 auto;
  4 +}
  5 +body{
  6 + background: #3C3C94;
  7 +}
  8 +main{
  9 + padding-top: 74px;
  10 + box-sizing: border-box;
  11 + padding-bottom: 100px;
  12 +}
  13 +main .container{
  14 + width: 900px;
  15 + margin: 0 auto;
  16 + background: #fff;
  17 + margin-bottom:50px;
  18 +}
  19 +.collection_list{
  20 + background: #fff;
  21 + padding: 0 30px;
  22 +}
  23 +.collection_item{
  24 + width: 100%;
  25 + border-bottom: 1px solid #EBEBEB;
  26 + padding-bottom: 30px;
  27 +}
  28 +.collection_item_title{
  29 + font-size: 18px;
  30 + color: #1A1A1A;
  31 + font-weight: bold;
  32 + padding-top: 30px;
  33 +}
  34 +.collection_item_main{
  35 + padding: 20px 0;
  36 + font-size: 14px;
  37 + color: #999999;
  38 +}
  39 +.collection_bottom_left_item{
  40 + padding-right: 10px;
  41 + padding-left: 10px;
  42 + border-right: 1px solid #EBEBEB;
  43 + float: left;
  44 +}
  45 +.collection_bottom_left_item:first-child{
  46 + padding-left: 0;
  47 +}
  48 +.collection_item_bottom_left,.collection_item_bottom_right,.collection_bottom_right_num{
  49 + float: left;
  50 +}
  51 +.collection_bottom_right_img{
  52 + float: left;
  53 +}
  54 +.collection_bottom_right_img img{
  55 + width: 14px;
  56 + height: 12px;
  57 + vertical-align: middle;
  58 + margin-left: 10px;
  59 + margin-right: 7px;
  60 + cursor: pointer;
  61 +}
  1 +body,
  2 +ol,
  3 +ul,
  4 +h1,
  5 +h2,
  6 +h3,
  7 +h4,
  8 +h5,
  9 +h6,
  10 +p,
  11 +th,
  12 +td,
  13 +dl,
  14 +dd,
  15 +form,
  16 +fieldset,
  17 +legend,
  18 +input,
  19 +textarea,
  20 +select {
  21 + margin: 0;
  22 + padding: 0
  23 +}
  24 +
  25 +body {
  26 + font: 12px "微软雅黑", "MicrosoftYaHei", HELVETICA;
  27 + background: #fff;
  28 + -webkit-text-size-adjust: 100%;
  29 + color: rgba(51, 51, 51, 1);
  30 +}
  31 +
  32 +a {
  33 + color: #2d374b;
  34 + text-decoration: none
  35 +}
  36 +
  37 +em,
  38 +i {
  39 + font-style: normal
  40 +}
  41 +
  42 +li {
  43 + list-style: none
  44 +}
  45 +
  46 +img {
  47 + border: 0;
  48 + vertical-align: middle
  49 +}
  50 +
  51 +table {
  52 + border-collapse: collapse;
  53 + border-spacing: 0
  54 +}
  55 +
  56 +p {
  57 + word-wrap: break-word
  58 +}
  59 +
  60 +
  61 +/* 头部 */
  62 +
  63 +#header {
  64 + width: 100%;
  65 + background: #fff;
  66 + margin: 0 auto;
  67 + height: 80px;
  68 + line-height: 80px
  69 +}
  70 +
  71 +#header section {
  72 + float: left;
  73 +}
  74 +
  75 +
  76 +/* logo */
  77 +
  78 +#header .home_logo {
  79 + width: 110px;
  80 + height: 70px;
  81 + margin: 0 75px 0 0px;
  82 +}
  83 +
  84 +#header .home_logo img {
  85 + width: 100%;
  86 + height: 100%
  87 +}
  88 +
  89 +
  90 +/* 导航栏 */
  91 +
  92 +#header .home_nav ul li {
  93 + float: left;
  94 + font-size: 17px;
  95 + color: rgba(77, 77, 77, 1);
  96 + width: 70px;
  97 + height: 76px;
  98 + margin: 0 15px;
  99 + text-align: center;
  100 + border-top: 4px solid rgba(255, 255, 255, 1);
  101 +}
  102 +
  103 +/* 搜索框 */
  104 +
  105 +#header .home_search {
  106 + position: relative;
  107 +/* width: 308px;*/
  108 +}
  109 +
  110 +
  111 +/* 图标 */
  112 +
  113 +#header .home_search .search_icon {
  114 + position: absolute;
  115 + left: 30px;
  116 + top: 30px;
  117 + background-image: url("../starImg/aicon_23.png");
  118 + background-repeat: no-repeat;
  119 + background-position: 0px 0px;
  120 + width: 18px;
  121 + height: 18px;
  122 + z-index: 3
  123 +}
  124 +
  125 +
  126 +/* 输入框 */
  127 +
  128 +#header .home_search input {
  129 + margin: 0 16px 0 16px;
  130 + width: 160px;
  131 + height: 33px;
  132 + background: rgba(242, 242, 242, 1);
  133 + border-radius: 17px;
  134 + outline: none;
  135 + border: none;
  136 + padding-left: 40px;
  137 +}
  138 +
  139 +
  140 +/* 登录注册按钮 */
  141 +
  142 +#header .home_login span p {
  143 + float: left;
  144 + margin-left: 16px
  145 +}
@@ -97,11 +97,16 @@ $(function(){ @@ -97,11 +97,16 @@ $(function(){
97 window.location.href = '/portal/login/editInfo'; 97 window.location.href = '/portal/login/editInfo';
98 }); 98 });
99 99
  100 + //我的收藏页面
  101 + $('#myCollection').click(function(){
  102 + window.location.href = '/portal/login/myCollection';
  103 + });
  104 +
100 //评论 105 //评论
101 $('#comment').click(function(){ 106 $('#comment').click(function(){
102 var content = $('#comment_content').val(); 107 var content = $('#comment_content').val();
103 var article_id = getUrlParam('id'); 108 var article_id = getUrlParam('id');
104 - var url = window.location.href; 109 + var url = window.location.pathname+window.location.search;
105 $.ajax({ 110 $.ajax({
106 type: 'POST', 111 type: 'POST',
107 url: "/portal/star/comment", 112 url: "/portal/star/comment",
@@ -133,11 +138,13 @@ $(function(){ @@ -133,11 +138,13 @@ $(function(){
133 function operation(url){ 138 function operation(url){
134 var article_id = getUrlParam('id'); 139 var article_id = getUrlParam('id');
135 var is_login = 1; 140 var is_login = 1;
  141 + var post_url = window.location.pathname+window.location.search;
136 $.ajax({ 142 $.ajax({
137 type: 'POST', 143 type: 'POST',
138 url: url, 144 url: url,
139 data: { 145 data: {
140 'article_id':article_id, 146 'article_id':article_id,
  147 + 'post_url':post_url
141 }, 148 },
142 dataType: 'json', 149 dataType: 'json',
143 async : false, 150 async : false,