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

增加封面图片管理

<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 小夏 < 449134904@qq.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;
use cmf\controller\AdminBaseController;
use app\portal\model\ImageModel;
use think\Db;
//封面图片管理
class AdminImageController extends AdminBaseController
{
//首页
public function index(){
$type = $this->request->param('type');
$imageModel = new ImageModel();
if(!empty($type) && isset($type)){
$image = $imageModel->where('type',$type)->order('weigh desc')->select();
}else{
$image = $imageModel->order('weigh desc')->select();
}
$this->assign('image', $image);
//封面图分类
$list = $this->getImgCategory();
$this->assign('list',$list);
$this->assign('type',$type);
return $this->fetch();
}
//添加页面
public function add(){
//封面图分类
$list = $this->getImgCategory();
$this->assign('list',$list);
return $this->fetch();
}
//自定义封面图分类
private function getImgCategory(){
$imgCategory = [
['id'=>1,'name'=>'首页'],
['id'=>2,'name'=>'星球画廊'],
['id'=>3,'name'=>'星享体验'],
['id'=>4,'name'=>'星探推荐'],
['id'=>5,'name'=>'星际活动']
];
return $imgCategory;
}
//提交保存
public function addPost(){
$data = $this->request->param();
$imageModel = new ImageModel();
$result = $this->validate($data, 'AdminImage');
if ($result !== true) {
$this->error($result);
}
$imageModel->allowField(true)->save($data);
$this->success("添加成功!", url("AdminImage/index"));
}
//编辑页面
public function edit(){
$id = $this->request->param('id', 0, 'intval');
$imageModel = new ImageModel();
$image = $imageModel->get($id);
//封面图分类
$list = $this->getImgCategory();
$this->assign('list',$list);
$this->assign('image', $image);
return $this->fetch();
}
//编辑保存页面
public function editPost()
{
$data = $this->request->param();
$imageModel = new ImageModel();
$result = $this->validate($data, 'AdminImage');
if ($result !== true) {
$this->error($result);
}
$imageModel->allowField(true)->isUpdate(true)->save($data);
$this->success("保存成功!", url("AdminImage/index"));
}
//删除
public function delete(){
$id = $this->request->param('id', 0, 'intval');
$imageModel = new ImageModel();
$imageModel->where('id',$id)->delete();
$this->success("删除成功!", url("AdminImage/index"));
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\portal\model;
use think\Model;
class ImageModel extends Model
{
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 小夏 < 449134904@qq.com>
// +----------------------------------------------------------------------
namespace app\portal\validate;
use think\Validate;
class AdminImageValidate extends Validate
{
protected $rule = [
'type' => 'require',
'image' => 'require',
];
protected $message = [
'type.require' => '请选择分类!',
'image.require' => '请上传封面图!',
];
protected $scene = [
// 'add' => ['user_login,user_pass,user_email'],
// 'edit' => ['user_login,user_email'],
];
}
\ No newline at end of file
... ...
... ... @@ -187,6 +187,7 @@ return array (
'PORTAL_ADMINENJOYSKY_EDITPOST' => '编辑提交',
'PORTAL_ADMINENJOYSKY_INDEX' => '户外天堂',
'PORTAL_ADMINEXE_DEFAULT' => '星际活动',
'PORTAL_ADMINIMAGE_INDEX' => '封面图管理',
'PORTAL_ADMININDEX_DEFAULT' => '门户管理',
'PORTAL_ADMINPAGE_ADD' => '添加页面',
'PORTAL_ADMINPAGE_ADDPOST' => '添加页面提交',
... ... @@ -301,6 +302,7 @@ return array (
'PORTAL_COMMENT_INDEX' => '评论管理',
'PORTAL_COMMENT_TOGGLE' => '审核通过与驳回',
'PORTAL_COMMENTMANAGE_DEFAULT' => '评论管理',
'PORTAL_IMAGES_DEFAULT' => '封面图管理',
'USER_ADMINASSET_DELETE' => '删除文件',
'USER_ADMINASSET_INDEX' => '资源管理',
'USER_ADMININDEX_BAN' => '本站用户拉黑',
... ...
<include file="public@header"/>
<style type="text/css">
.pic-list li {
margin-bottom: 5px;
}
</style>
</head>
<body>
<div class="wrap js-check-wrap">
<ul class="nav nav-tabs">
<li><a href="{:url('AdminImage/index')}">封面图管理</a></li>
<li class="active"><a href="{:url('AdminImage/add')}">添加封面图</a></li>
</ul>
<form action="{:url('AdminImage/addPost')}" method="post" class="form-horizontal js-ajax-form margin-top-20">
<div class="row">
<div class="col-md-9">
<table class="table table-bordered">
<tr width="150">
<th width="100">分类<span class="form-required">*</span></th>
<td>
<select class="form-control check_city" name="type" id="input-parent" style="width:400px;">
<option value="">请选择分类</option>
<foreach name="list" item="vo">
<option value="{$vo.id}">{$vo.name}</option>
</foreach>
</select>
</td>
</tr>
<tr>
<th>权重</th>
<td>
<input class="form-control" type="number" name="weigh" value="0">
</td>
</tr>
</table>
<hook name="portal_admin_article_edit_view_main"/>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary js-ajax-submit">{:lang('ADD')}</button>
<a class="btn btn-default" href="{:url('AdminImage/index')}">{:lang('BACK')}</a>
</div>
</div>
</div>
<div class="col-md-3">
<table class="table table-bordered">
<tr>
<th><b>封面图</b><span class="form-required">*</span></th>
</tr>
<tr>
<td>
<div style="text-align: center;">
<input type="hidden" name="image" id="thumbnail" value="">
<a href="javascript:uploadOneImage('图片上传','#thumbnail');">
<img src="__TMPL__/public/assets/images/default-thumbnail.png"
id="thumbnail-preview"
width="135" style="cursor: pointer"/>
</a>
<input type="button" class="btn btn-sm btn-cancel-thumbnail" value="取消图片">
</div>
</td>
</tr>
</table>
<hook name="portal_admin_article_edit_view_right_sidebar"/>
</div>
</div>
</form>
</div>
<script type="text/javascript" src="__STATIC__/js/admin.js"></script>
<script type="text/javascript">
//编辑器路径定义
var editorURL = GV.WEB_ROOT;
</script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript">
$(function () {
editorcontent = new baidu.editor.ui.Editor();
editorcontent.render('content');
try {
editorcontent.sync();
} catch (err) {
}
$('.btn-cancel-thumbnail').click(function () {
$('#thumbnail-preview').attr('src', '__TMPL__/public/assets/images/default-thumbnail.png');
$('#thumbnail').val('');
});
});
function doSelectCategory() {
var selectedCategoriesId = $('#js-categories-id-input').val();
openIframeLayer("{:url('AdminCategory/select')}?ids=" + selectedCategoriesId, '请选择分类', {
area: ['700px', '400px'],
btn: ['确定', '取消'],
yes: function (index, layero) {
//do something
var iframeWin = window[layero.find('iframe')[0]['name']];
var selectedCategories = iframeWin.confirm();
if (selectedCategories.selectedCategoriesId.length == 0) {
layer.msg('请选择分类');
return;
}
$('#js-categories-id-input').val(selectedCategories.selectedCategoriesId.join(','));
$('#js-categories-name-input').val(selectedCategories.selectedCategoriesName.join(' '));
//console.log(layer.getFrameIndex(index));
layer.close(index); //如果设定了yes回调,需进行手工关闭
}
});
}
</script>
</body>
</html>
... ...
<include file="public@header"/>
<style type="text/css">
.pic-list li {
margin-bottom: 5px;
}
</style>
</head>
<body>
<div class="wrap js-check-wrap">
<ul class="nav nav-tabs">
<li><a href="{:url('AdminImage/index')}">封面图管理</a></li>
<li>
<a href="{:url('AdminImage/add')}">添加封面图</a>
</li>
<li class="active"><a href="#">编辑封面图</a></li>
</ul>
<form action="{:url('AdminImage/editPost')}" method="post" class="form-horizontal js-ajax-form margin-top-20">
<div class="row">
<div class="col-md-9">
<table class="table table-bordered">
<input id="post-id" type="hidden" name="id" value="{$image.id}">
<tr>
<th width="150">分类<span class="form-required">*</span></th>
<td>
<select class="form-control check_city" name="type" id="input-parent" style="width:400px;">
<option value="">请选择分类</option>
<foreach name="list" item="vo">
<option value="{$vo.id}" <eq name="vo.id" value="$image.type">selected</eq>>{$vo.name}</option>
</foreach>
</select>
</td>
</tr>
<tr>
<th>权重</th>
<td>
<input class="form-control" type="number" name="weigh" value="{$image.weigh}">
</td>
</tr>
</table>
<hook name="portal_admin_article_edit_view_main"/>
</div>
<div class="col-md-3">
<table class="table table-bordered">
<tr>
<th>缩略图<span class="form-required">*</span></th>
</tr>
<tr>
<td>
<div style="text-align: center;">
<input type="hidden" name="image" id="thumbnail"
value="{$image.image|default=''}">
<a href="javascript:uploadOneImage('图片上传','#thumbnail');">
<if condition="empty($image.image)">
<img src="__TMPL__/public/assets/images/default-thumbnail.png"
id="thumbnail-preview"
width="135" style="cursor: pointer"/>
<else/>
<img src="{:cmf_get_image_preview_url($image.image)}"
id="thumbnail-preview"
width="135" style="cursor: pointer"/>
</if>
</a>
<input type="button" class="btn btn-sm btn-cancel-thumbnail" value="取消图片">
</div>
</td>
</tr>
</table>
<hook name="portal_admin_article_edit_view_right_sidebar"/>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary js-ajax-submit">{:lang('SAVE')}</button>
<a class="btn btn-default" href="javascript:history.back(-1);">{:lang('BACK')}</a>
</div>
</div>
</form>
</div>
<script type="text/javascript" src="__STATIC__/js/admin.js"></script>
<script type="text/javascript">
//编辑器路径定义
var editorURL = GV.WEB_ROOT;
</script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript">
$(function () {
editorcontent = new baidu.editor.ui.Editor();
editorcontent.render('content');
try {
editorcontent.sync();
} catch (err) {
}
$('.btn-cancel-thumbnail').click(function () {
$('#thumbnail-preview').attr('src', '__TMPL__/public/assets/images/default-thumbnail.png');
$('#thumbnail').val('');
});
$('#more-template-select').val("{$post.more.template|default=''}");
});
function doSelectCategory() {
var selectedCategoriesId = $('#js-categories-id-input').val();
openIframeLayer("{:url('AdminCategory/select')}?ids=" + selectedCategoriesId, '请选择分类', {
area: ['700px', '400px'],
btn: ['确定', '取消'],
yes: function (index, layero) {
//do something
var iframeWin = window[layero.find('iframe')[0]['name']];
var selectedCategories = iframeWin.confirm();
if (selectedCategories.selectedCategoriesId.length == 0) {
layer.msg('请选择分类');
return;
}
$('#js-categories-id-input').val(selectedCategories.selectedCategoriesId.join(','));
$('#js-categories-name-input').val(selectedCategories.selectedCategoriesName.join(' '));
//console.log(layer.getFrameIndex(index));
layer.close(index); //如果设定了yes回调,需进行手工关闭
}
});
}
</script>
<script>
var publishYesUrl = "{:url('AdminImage/publish',array('yes'=>1))}";
var publishNoUrl = "{:url('AdminImage/publish',array('no'=>1))}";
var topYesUrl = "{:url('AdminImage/top',array('yes'=>1))}";
var topNoUrl = "{:url('AdminImage/top',array('no'=>1))}";
var recommendYesUrl = "{:url('AdminImage/recommend',array('yes'=>1))}";
var recommendNoUrl = "{:url('AdminImage/recommend',array('no'=>1))}";
var postId = $('#post-id').val();
//发布操作
$("#post-status-checkbox").change(function () {
if ($('#post-status-checkbox').is(':checked')) {
//发布
$.ajax({
url: publishYesUrl, type: "post", dataType: "json", data: {ids: postId}, success: function (data) {
if (data.code != 1) {
$('#post-status-checkbox').removeAttr("checked");
$('#post-status-error').html(data.msg).show();
} else {
$('#post-status-error').hide();
}
}
});
} else {
//取消发布
$.ajax({
url: publishNoUrl, type: "post", dataType: "json", data: {ids: postId}, success: function (data) {
if (data.code != 1) {
$('#post-status-checkbox').prop("checked", 'true');
$('#post-status-error').html(data.msg).show();
} else {
$('#post-status-error').hide();
}
}
});
}
});
//置顶操作
$("#is-top-checkbox").change(function () {
if ($('#is-top-checkbox').is(':checked')) {
//置顶
$.ajax({
url: topYesUrl, type: "post", dataType: "json", data: {ids: postId}, success: function (data) {
if (data.code != 1) {
$('#is-top-checkbox').removeAttr("checked");
$('#is-top-error').html(data.msg).show();
} else {
$('#is-top-error').hide();
}
}
});
} else {
//取消置顶
$.ajax({
url: topNoUrl, type: "post", dataType: "json", data: {ids: postId}, success: function (data) {
if (data.code != 1) {
$('#is-top-checkbox').prop("checked", 'true');
$('#is-top-error').html(data.msg).show();
} else {
$('#is-top-error').hide();
}
}
});
}
});
//推荐操作
$("#recommended-checkbox").change(function () {
if ($('#recommended-checkbox').is(':checked')) {
//推荐
$.ajax({
url: recommendYesUrl, type: "post", dataType: "json", data: {ids: postId}, success: function (data) {
if (data.code != 1) {
$('#recommended-checkbox').removeAttr("checked");
$('#recommended-error').html(data.msg).show();
} else {
$('#recommended-error').hide();
}
}
});
} else {
//取消推荐
$.ajax({
url: recommendNoUrl, type: "post", dataType: "json", data: {ids: postId}, success: function (data) {
if (data.code != 1) {
$('#recommended-checkbox').prop("checked", 'true');
$('#recommended-error').html(data.msg).show();
} else {
$('#recommended-error').hide();
}
}
});
}
});
</script>
</body>
</html>
... ...
<include file="public@header"/>
</head>
<body>
<div class="wrap js-check-wrap">
<ul class="nav nav-tabs">
<li class="active"><a href="javascript:;">所有封面图</a></li>
<li><a href="{:url('AdminImage/add')}">添加封面图</a></li>
</ul>
<form class="well form-inline margin-top-20" method="post" action="{:url('AdminImage/index')}">
分类:
<select class="form-control" name="type" style="width: 140px;">
<option value='0'>全部</option>
<foreach name="list" item="vo">
<option value="{$vo.id}" <eq name="vo.id" value="$type">selected</eq>>{$vo.name}</option>
</foreach>
</select> &nbsp;&nbsp;
<input type="submit" class="btn btn-primary" id="search" value="搜索"/>
<a class="btn btn-danger" href="{:url('AdminImage/index')}">清空</a>
</form>
<form class="js-ajax-form" action="" method="post">
<div class="table-actions">
</div>
<table class="table table-hover table-bordered table-list">
<thead>
<tr>
<th width="15">
<label>
<input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">
</label>
</th>
<!--<notempty name="category">-->
<!--<th width="50">{:lang('SORT')}</th>-->
<!--</notempty>-->
<th width="50">ID</th>
<th width="200">类型</th>
<th width="100">封面图</th>
<th width="70">权重</th>
<th width="100">操作</th>
</tr>
</thead>
<foreach name="image" item="vo">
<tr>
<td>
<input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="ids[]"
value="{$vo.id}" title="ID:{$vo.id}">
</td>
<!--<notempty name="category">-->
<!--<td>-->
<!--<input name="list_orders[{$vo.post_category_id}]" class="input-order" type="text"-->
<!--value="{$vo.list_order}">-->
<!--</td>-->
<!--</notempty>-->
<td><b>{$vo.id}</b></td>
<td>
<switch name="vo.type">
<case value="1">首页</case>
<case value="2">星球画廊</case>
<case value="3">星享体验</case>
<case value="4">星探推荐</case>
<case value="5">星际活动</case>
</switch>
</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>
<b>{$vo.weigh}</b>
</td>
<td>
<a class="btn btn-xs btn-primary" href="{:url('AdminImage/edit',array('id'=>$vo['id']))}">{:lang('EDIT')}</a>
<a class="btn btn-xs btn-danger js-ajax-delete"
href="{:url('AdminImage/delete',array('id'=>$vo['id']))}">{:lang('DELETE')}</a>
</td>
</tr>
</foreach>
</table>
</form>
</div>
<script src="__STATIC__/js/admin.js"></script>
<script>
function reloadPage(win) {
win.location.reload();
}
</script>
</body>
</html>
\ No newline at end of file
... ...