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

增加后台城市上传banner图功能

... ... @@ -17,20 +17,19 @@ use think\Db;
class ActiveController extends HomeBaseController
{
private $index_limit = 16;//首页分页
private $more_limit = 6;//更多列表分页
private $more_limit = 5;//更多列表分页
public function index(){
//星际活动
$page = $this->request->param('page',1,'intval');
$position['category_id'] = CityCategoryModel::xjhd_c;
$field = 'id,thumbnail,post_title';
$res_xjhd = $this->getChildArticlePage($position,$field,$page);
$this->assign('res_xjhd',$res_xjhd);
$res = $this->getChildArticlePage($position,$field);
$this->assign('res',$res['data']);
$this->assign('page',$res['page']);
return $this->fetch();
}
//根据子类获取文章分页
public function getChildArticlePage($position,$field,$page,$limit=''){
public function getChildArticlePage($position,$field,$limit=''){
$pre = CityCategoryModel::pre;
$limit = empty($limit)?$this->more_limit:$limit;
$post_id = Db::table($pre.'portal_category_post')
... ... @@ -44,10 +43,10 @@ class ActiveController extends HomeBaseController
->whereIn('id',$post_id)
->where('delete_time', 0)
->field($field)
->page($page,$limit)
->order('weigh desc')
->select()
->toArray();
->paginate($limit);
$arr['data'] = $res->toArray();
$arr['page'] = $res->render();
return $res;
}
... ...
... ... @@ -29,6 +29,11 @@ class StarController extends HomeBaseController
$this->assign('city_name',$city_name);
$this->assign('city_id',$city_id);
$position['city_id'] = $city_id;
//城市名称对应banner图
$city_banner = $this->getCityBanner($city_id);
$this->assign('city_banner',$city_banner);
//星球故事
$position['category_id'] = CityCategoryModel::xqgs;
$field = 'id,thumbnail,post_excerpt,more';
... ... @@ -79,14 +84,24 @@ class StarController extends HomeBaseController
//获取城市名称
public function getCityName($city_id){
$city_name = Db::name('city_category')
$res = Db::name('city_category')
->where('id',$city_id)
->field('id,name')
->find();
$city_name = empty($city_name)?'':$city_name['name'];
$city_name = empty($res['name'])?'':$res['name'];
return $city_name;
}
//获取城市banner图
public function getCityBanner($city_id){
$res = Db::name('city_category')
->where('id',$city_id)
->field('id,image')
->find();
$banner = empty($res['image'])?'':$res['image'];
return $banner;
}
//根据子类获取文章
public function getChildArticle($position,$field,$limit=''){
$pre = CityCategoryModel::pre;
... ...
... ... @@ -33,6 +33,21 @@
</div>
</div>
<div class="form-group">
<label for="thumbnail">banner图</label>
<div>
<input type="text" class="form-control" id="thumbnail" name="image">
<a href="javascript:uploadOneImage('图片上传','#thumbnail');">
<img src="__TMPL__/public/assets/images/default-thumbnail.png"
id="thumbnail-preview"
width="300" height="150" style="cursor: pointer"/>
</a>
<input type="button" class="btn btn-sm btn-cancel-thumbnail" value="取消图片">
<a href="javascript:uploadOneImage('图片上传','#thumbnail');">上传图片</a>
</div>
<span class="form-required">图片参考尺寸:1920*666</span>
</div>
</div>
</div>
<div class="form-group">
... ... @@ -45,4 +60,12 @@
</div>
<script type="text/javascript" src="__STATIC__/js/admin.js"></script>
</body>
</html>
\ No newline at end of file
</html>
<script type="text/javascript">
$(function () {
$('.btn-cancel-thumbnail').click(function () {
$('#thumbnail-preview').attr('src', '__TMPL__/public/assets/images/default-thumbnail.png');
$('#thumbnail').val('');
});
});
</script>
\ No newline at end of file
... ...
... ... @@ -32,6 +32,26 @@
<input type="text" class="form-control" id="input-name" name="name" value="{$category_name.name}">
</div>
</div>
<div class="form-group">
<label for="thumbnail">banner图</label>
<div>
<input type="text" class="form-control" id="thumbnail" name="image" value="{$category_name.image}">
<a href="javascript:uploadOneImage('上传图片','#thumbnail');">
<if condition="empty($category_name.image)">
<img src="__TMPL__/public/assets/images/default-thumbnail.png"
id="thumbnail-preview"
width="300" height="150" style="cursor: pointer"/>
<else/>
<img src="{:cmf_get_image_preview_url($category_name.image)}"
id="thumbnail-preview"
width="300" height="150" style="cursor: pointer"/>
</if>
</a>
<input type="button" class="btn btn-sm btn-cancel-thumbnail" value="取消图片">
<a href="javascript:uploadOneImage('图片上传','#thumbnail');">上传图片</a>
</div>
<span class="form-required">图片参考尺寸:1920*666</span>
</div>
</div>
</div>
... ... @@ -46,4 +66,12 @@
</div>
<script type="text/javascript" src="__STATIC__/js/admin.js"></script>
</body>
</html>
\ No newline at end of file
</html>
<script type="text/javascript">
$(function () {
$('.btn-cancel-thumbnail').click(function () {
$('#thumbnail-preview').attr('src', '__TMPL__/public/assets/images/default-thumbnail.png');
$('#thumbnail').val('');
});
});
</script>
\ No newline at end of file
... ...
... ... @@ -29,7 +29,8 @@
<thead>
<tr>
<th width="200">ID</th>
<th>分类名称</th>
<th width="400">分类名称</th>
<th>banner图</th>
<th width="210">操作</th>
</tr>
</thead>
... ... @@ -38,6 +39,15 @@
<td>{$vo.id}</td>
<td>{$vo.name}</td>
<td>
<notempty name="vo.image">
<a href="javascript:parent.imagePreviewDialog('{:cmf_get_image_preview_url($vo.image)}');">
<i class="fa fa-photo fa-fw"></i>
</a>
<else/>
<i class="fa fa-close fa-fw"></i>
</notempty>
</td>
<td>
<a class="btn btn-xs btn-primary" href="{:url('AdminCityCategory/edit',array('id'=>$vo['id']))}">{:lang('EDIT')}</a>
<a class="btn btn-xs btn-danger js-ajax-delete" href="{:url('AdminCityCategory/delete',array('id'=>$vo['id']))}" class="js-ajax-delete">{:lang('DELETE')}</a>
</td>
... ...
... ... @@ -38,7 +38,7 @@
<div class="select">
<input type="text" value="中国" readonly="readonly">
<img src="__TMPL__/public/assets/starImg/down.png" alt="">
<ul>
<ul style="height:300px;overflow-y: scroll;width:240px;">
<li>所有</li>
<volist name="city_name" id="vo">
<li value="{$vo.id}" <eq name="$vo.id" value="$city_id">selected</eq>>{$vo.name}</li>
... ...
... ... @@ -15,10 +15,10 @@
margin-bottom:100px;
}
.excerpt{
font-size: 14px;
margin: 30px 0 40px 0;
color: rgba(153, 153, 153, 1);
line-height: 22px;
font-size: 16px;
color: rgba(102, 102, 102, 1);
line-height: 32px;
}
</style>
</head>
... ...
... ... @@ -30,7 +30,7 @@
<div class="select">
<input type="text" value="中国" readonly="readonly">
<img src="__TMPL__/public/assets/starImg/down.png" alt="">
<ul>
<ul style="height:300px;overflow-y: scroll;width:145px;">
<li>所有</li>
<volist name="city_name" id="vo">
<li value="{$vo.id}" <eq name="$vo.id" value="$city_id">selected</eq>>{$vo.name}</li>
... ...
... ... @@ -15,7 +15,11 @@
<div class="happy_index">
<!-- banner轮播图 -->
<div class="happy_banner">
<img src="__TMPL__/public/assets/starImg/star_banner.jpg" alt="" />
<notempty name="city_banner">
<img src="{:cmf_get_image_url($city_banner)}" alt="" />
<else/>
<img src="__TMPL__/public/assets/starImg/star_banner.jpg" alt="" />
</notempty>
<h3>Planet Discovery</h3>
</div>
<!-- main 背景 -->
... ...
... ... @@ -107,8 +107,8 @@ body {
line-height: 48px;
text-shadow: 0px 6px 14px rgba(0, 0, 0, 0.3);
position: absolute;
top: 499px;
left: 365px
top: 75%;
left: 19%;
}
... ...