417 lines
19 KiB
PHP
417 lines
19 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2020-11-24
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
use yii\widgets\LinkPager;
|
|
use app\models\Banner;
|
|
|
|
$this->title = '轮播图';
|
|
$this->params['breadcrumbs'][] = $this->title;
|
|
$status_labels = Banner::statusLabels();
|
|
$status = \Yii::$app->request->get('status');
|
|
?>
|
|
<div class="layui-fluid">
|
|
<div class="layui-card">
|
|
<div class="layui-card-header">
|
|
<?= $this->title ?>
|
|
</div>
|
|
<div class="layui-card-header layuiadmin-card-header-auto">
|
|
<div class="layui-form-item">
|
|
<div class="layui-inline">
|
|
<a class=" layui-btn layui-btn-sm" href="<?=\Yii::$app->urlManager->createUrl(["admin/wechat/mp-slide-edit"])?>">添加轮播图</a>
|
|
</div>
|
|
<div class="layui-inline layui-float-right layui-form">
|
|
<div class="layui-inline layui-form-item">
|
|
<div class="layui-inline">
|
|
<div class="layui-input-inline">
|
|
<select class="layui-select" lay-filter="batch-action">
|
|
<option value="0">批量操作</option>
|
|
<option value="hide">批量隐藏</option>
|
|
<option value="show">批量显示</option>
|
|
<option value="del">批量删除</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="layui-inline layui-form-item">
|
|
<div class="layui-input-inline">
|
|
<select class="layui-select" name="status">
|
|
<option value="" <?=$status === null ? 'selected' : ''?>>全部状态</option>
|
|
<?php foreach ($status_labels as $key => $val):?>
|
|
<option value="<?=$key?>" <?=$status == $key && $status != null ? 'selected' : ''?>><?=$val?></option>
|
|
<?php endforeach;?>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
<div class="layui-inline layui-form-item">
|
|
<label class="layui-form-label">关键词</label>
|
|
<div class="layui-input-block">
|
|
<input type="text" name="keywords" placeholder="搜索标题" autocomplete="off" class="layui-input" value="<?=\Yii::$app->request->get("keywords")?>">
|
|
</div>
|
|
</div>
|
|
<div class="layui-inline">
|
|
<button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="layui-form-search">
|
|
<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="layui-card-body">
|
|
<table class="layui-table layui-form">
|
|
<thead>
|
|
<tr>
|
|
<th>
|
|
<div class="layui-table-cell laytable-cell-checkbox">
|
|
<input type="checkbox" name="layuitable_checkbox" lay-skin="primary" >
|
|
</div>
|
|
</th>
|
|
<th>ID</th>
|
|
<th>标题</th>
|
|
<th>内容</th>
|
|
<th>链接</th>
|
|
<th>排序</th>
|
|
<th>添加时间</th>
|
|
<th>状态</th>
|
|
<th>操作</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($list as $index => $item):?>
|
|
<tr>
|
|
<td>
|
|
<div class="layui-table-cell laytable-cell-checkbox">
|
|
<input type="checkbox" name="layuitable_checkbox" lay-skin="primary" value="<?=$item['id']?>">
|
|
</div>
|
|
</td>
|
|
<td><?=$item["id"]?></td>
|
|
<td><?=$item["title"]?></td>
|
|
<td>
|
|
<?php if($item['media'] == Banner::MEDIA_IMG):?>
|
|
<img src="<?=$item["img_url"]?>" style="width:168px;max-width: 168px;">
|
|
<?php endif;?>
|
|
<?php if($item['media'] == Banner::MEDIA_VIDEO):?>
|
|
<video src="<?=$item["video_url"]?>" style="width:168px;max-width: 168px;" controls=""></video>
|
|
<?php endif;?>
|
|
</td>
|
|
<td>
|
|
<span class="layui-badge layui-bg-orange"><?=$item['url_type_cn']?></span>
|
|
<?php if($item['url_type'] == Banner::URL_TYPE_MP):?>
|
|
<?=$item['app_id']?>
|
|
<?php else:?>
|
|
<?=$item['page_url']?>
|
|
<?php endif;?>
|
|
</td>
|
|
<td><?=$item["sort"]?></td>
|
|
<td><?=$item["created_at_cn"]?></td>
|
|
<td>
|
|
<?php if($item['status'] == Banner::STATUS_HIDE):?>
|
|
<span class="layui-badge layui-bg-gray"><?=$item["status_cn"]?></span>
|
|
<?php elseif($item['status'] == Banner::STATUS_SHOW):?>
|
|
<span class="layui-badge layui-bg-blue"><?=$item["status_cn"]?></span>
|
|
<?php endif;?>
|
|
</td>
|
|
<td>
|
|
<?php if($item['status'] == Banner::STATUS_HIDE):?>
|
|
<a href="javascript:;" data-id="<?=$item["id"]?>" class="layui-btn layui-btn-normal layui-btn-xs show-btn">显示</a>
|
|
<a href="javascript:;" data-id="<?=$item["id"]?>" class="layui-btn layui-btn-danger layui-btn-xs del-btn">删除</a>
|
|
<?php elseif($item['status'] == Banner::STATUS_SHOW):?>
|
|
<a href="javascript:;" data-id="<?=$item["id"]?>" class="layui-btn layui-btn-warm layui-btn-xs hide-btn">隐藏</a>
|
|
<?php endif;?>
|
|
<a href="<?=\Yii::$app->urlManager->createUrl(['admin/wechat/mp-slide-edit', 'id' => $item['id']])?>" class="layui-btn layui-btn-xs">编辑</a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach;?>
|
|
</tbody>
|
|
</table>
|
|
<div class="layui-table-page layui-text-center">
|
|
<?php echo LinkPager::widget([
|
|
'pagination' => $pagination,
|
|
'prevPageLabel' => '上一页',
|
|
'nextPageLabel' => '下一页',
|
|
'firstPageLabel' => '首页',
|
|
'lastPageLabel' => '尾页',
|
|
'maxButtonCount' => 5,
|
|
'options' => [
|
|
'class' => 'layui-pagination layui-laypage',
|
|
],
|
|
'prevPageCssClass' => 'layui-laypage-prev',
|
|
'pageCssClass' => "layui-laypage-item",
|
|
'nextPageCssClass' => 'layui-laypage-first',
|
|
'firstPageCssClass' => 'layui-laypage-last',
|
|
'lastPageCssClass' => 'layui-laypage-last',
|
|
'linkOptions' => [
|
|
'class' => 'page-link',
|
|
],
|
|
'disabledListItemSubTagOptions' => ['tag' => 'a', 'class' => 'layui-disabled'],
|
|
])
|
|
?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script>
|
|
<?php $this->beginBlock('js_script_wrap') ?>
|
|
layui.config({
|
|
base: '/statics/layuiadmin/' //静态资源所在路径
|
|
}).extend({
|
|
index: 'lib/index' //主入口模块
|
|
}).use(['index', 'user'], function () {
|
|
var $ = layui.$
|
|
, form = layui.form
|
|
, admin = layui.admin;
|
|
//pagination search
|
|
$(".layui-pagination").append('<span class="layui-laypage-skip " style="margin-left:15px;">到第<input type="text" min="1" value="" class="layui-input" id="invalue">页<button type="button" class="layui-laypage-btn" id="skip">确定</button></span>');
|
|
$('#skip').click(function() {
|
|
var a_elem = $('.layui-pagination .layui-laypage-item.active a');
|
|
var href = a_elem.attr('href');
|
|
var cur_page = a_elem.attr('data-page');
|
|
cur_page = cur_page * 1 + 1;
|
|
var page = $('#invalue').val();
|
|
var before_str = 'page=' + cur_page;
|
|
var after_str = 'page=' + page;
|
|
var reg = new RegExp(before_str);
|
|
var href = href.replace(reg,after_str);
|
|
location.href = href;
|
|
});
|
|
form.render();
|
|
//search
|
|
form.on('submit(layui-form-search)', function (obj) {
|
|
var url = '<?=\Yii::$app->urlManager->createUrl(["admin/wechat/mp-slide"])?>';
|
|
url += '?' + wrx.object_to_url_params(obj.field);
|
|
location.href = url;
|
|
});
|
|
//全选操作
|
|
$('.layui-table .laytable-cell-checkbox').eq(0).on('click','.layui-form-checkbox',function(){
|
|
var checked = $('.layui-table .laytable-cell-checkbox').eq(0).find("input").prop("checked");
|
|
//console.log(checked)
|
|
if(checked){
|
|
//select all
|
|
$('.layui-table .laytable-cell-checkbox').each(function(index){
|
|
var checked = $('.layui-table .laytable-cell-checkbox').eq(index).find("input").prop("checked");
|
|
if(!checked){
|
|
$('.layui-table .laytable-cell-checkbox').eq(index).find('.layui-form-checkbox').trigger("click");
|
|
}
|
|
});
|
|
} else {
|
|
$('.layui-table .laytable-cell-checkbox').each(function(index){
|
|
var checked = $('.layui-table .laytable-cell-checkbox').eq(index).find("input").prop("checked");
|
|
if(checked){
|
|
$('.layui-table .laytable-cell-checkbox').eq(index).find('.layui-form-checkbox').trigger("click");
|
|
}
|
|
});
|
|
}
|
|
})
|
|
|
|
//显示
|
|
$(".layui-table").on("click",".show-btn",function(){
|
|
var id = $(this).attr("data-id");
|
|
layer.confirm('你确定将此项显示吗?', {
|
|
btn: ['确定','取消']
|
|
}, function(){
|
|
var url = '<?=\Yii::$app->urlManager->createUrl(["/admin/wechat/mp-slide-show"])?>';
|
|
$.ajax(url,{
|
|
type:"POST",
|
|
dataType:"json",
|
|
data:{
|
|
slide_id:id,
|
|
_csrf:_csrf
|
|
},
|
|
success:function(res){
|
|
if(res.code == 0){
|
|
layer.msg(res.msg, {
|
|
offset: '15px'
|
|
,icon: 1
|
|
,time: 1000
|
|
}, function(){
|
|
location.reload();
|
|
});
|
|
} else {
|
|
layer.msg(res.msg, {
|
|
offset: '15px'
|
|
,icon: 2
|
|
,time: 1000
|
|
}, function(){
|
|
});
|
|
}
|
|
},
|
|
error:function(xhr,type,err){
|
|
layer.msg(xhr.responseText, {
|
|
offset: '15px'
|
|
,icon: 2
|
|
,time: 1000
|
|
}, function(){
|
|
});
|
|
}
|
|
})
|
|
}, function(){
|
|
});
|
|
});
|
|
//隐藏
|
|
$(".layui-table").on("click",".hide-btn",function(){
|
|
var id = $(this).attr("data-id");
|
|
layer.confirm('你确定将此项隐藏吗?', {
|
|
btn: ['确定','取消']
|
|
}, function(){
|
|
var url = '<?=\Yii::$app->urlManager->createUrl(["/admin/wechat/mp-slide-hide"])?>';
|
|
$.ajax(url,{
|
|
type:"POST",
|
|
dataType:"json",
|
|
data:{
|
|
slide_id:id,
|
|
_csrf:_csrf
|
|
},
|
|
success:function(res){
|
|
if(res.code == 0){
|
|
layer.msg(res.msg, {
|
|
offset: '15px'
|
|
,icon: 1
|
|
,time: 1000
|
|
}, function(){
|
|
location.reload();
|
|
});
|
|
} else {
|
|
layer.msg(res.msg, {
|
|
offset: '15px'
|
|
,icon: 2
|
|
,time: 1000
|
|
}, function(){
|
|
});
|
|
}
|
|
},
|
|
error:function(xhr,type,err){
|
|
layer.msg(xhr.responseText, {
|
|
offset: '15px'
|
|
,icon: 2
|
|
,time: 1000
|
|
}, function(){
|
|
});
|
|
}
|
|
})
|
|
}, function(){
|
|
});
|
|
});
|
|
//删除
|
|
$(".layui-table").on("click",".del-btn",function(){
|
|
var id = $(this).attr("data-id");
|
|
layer.confirm('你确定将此项删除吗?', {
|
|
btn: ['确定','取消']
|
|
}, function(){
|
|
var url = '<?=\Yii::$app->urlManager->createUrl(["/admin/wechat/mp-slide-del"])?>';
|
|
$.ajax(url,{
|
|
type:"POST",
|
|
dataType:"json",
|
|
data:{
|
|
slide_id:id,
|
|
_csrf:_csrf
|
|
},
|
|
success:function(res){
|
|
if(res.code == 0){
|
|
layer.msg(res.msg, {
|
|
offset: '15px'
|
|
,icon: 1
|
|
,time: 1000
|
|
}, function(){
|
|
location.reload();
|
|
});
|
|
} else {
|
|
layer.msg(res.msg, {
|
|
offset: '15px'
|
|
,icon: 2
|
|
,time: 1000
|
|
}, function(){
|
|
});
|
|
}
|
|
},
|
|
error:function(xhr,type,err){
|
|
layer.msg(xhr.responseText, {
|
|
offset: '15px'
|
|
,icon: 2
|
|
,time: 1000
|
|
}, function(){
|
|
});
|
|
}
|
|
})
|
|
}, function(){
|
|
});
|
|
});
|
|
form.on('select(batch-action)', function(data){
|
|
console.log(data.value); //得到被选中的值
|
|
var v = data.value;
|
|
var ids = [];
|
|
$('.layui-table .laytable-cell-checkbox input:checkbox:checked').each(function(){
|
|
var id = $(this).val();
|
|
ids.push(id)
|
|
});
|
|
if(ids.length == 0){
|
|
return layer.msg("未选中任何选项");
|
|
}
|
|
var url = null;
|
|
var tip = null;
|
|
if(v == 'show'){
|
|
url = '<?=\Yii::$app->urlManager->createUrl(['/admin/wechat/mp-slide-show'])?>';
|
|
tip = '你确定显示此项吗?';
|
|
}
|
|
if(v == 'hide'){
|
|
url = '<?=\Yii::$app->urlManager->createUrl(['/admin/wechat/mp-slide-hide'])?>';
|
|
tip = '你确定隐藏此项吗?';
|
|
}
|
|
if(v == 'del'){
|
|
url = '<?=\Yii::$app->urlManager->createUrl(['/admin/wechat/mp-slide-del'])?>';
|
|
tip = '你确定删除此项吗?';
|
|
}
|
|
//console.log(url,tip);
|
|
if(url == null){
|
|
return ;
|
|
}
|
|
layer.confirm(tip, {
|
|
btn: ['确定','取消']
|
|
}, function(){
|
|
$.ajax(url,{
|
|
type:"POST",
|
|
dataType:"json",
|
|
data:{
|
|
slide_id:ids,
|
|
_csrf:_csrf
|
|
},
|
|
success:function(res){
|
|
if(res.code == 0){
|
|
layer.msg(res.msg, {
|
|
offset: '15px'
|
|
,icon: 1
|
|
,time: 1000
|
|
}, function(){
|
|
location.reload();
|
|
});
|
|
} else {
|
|
layer.msg(res.msg, {
|
|
offset: '15px'
|
|
,icon: 2
|
|
,time: 1000
|
|
}, function(){
|
|
});
|
|
}
|
|
},
|
|
error:function(xhr,type,err){
|
|
layer.msg(xhr.responseText, {
|
|
offset: '15px'
|
|
,icon: 2
|
|
,time: 1000
|
|
}, function(){
|
|
});
|
|
}
|
|
})
|
|
}, function(){
|
|
});
|
|
});
|
|
});
|
|
<?php $this->endBlock(); ?>
|
|
</script>
|
|
<?php $this->registerJs($this->blocks['js_script_wrap'], \yii\web\View::POS_END); ?>
|