edit修改相关内容

This commit is contained in:
admin 2024-01-19 10:31:59 +08:00
parent af7c76697d
commit d4f08d555e
8 changed files with 659 additions and 61 deletions

View File

@ -21,8 +21,8 @@ class Oss
{
$this->accessKeyId = 'LTAI5tMaDbEbWyQWpwmxp24y';
$this->accessKeySecret = '3bjqbBFC08YIub3c8ry9Elz05UF1J7';
$this->bucket = 'cxgjyz';
$this->endpoint = 'https://oss-cn-beijing.aliyuncs.com';
$this->bucket = 'cxgjsz1';
$this->endpoint = 'https://oss-cn-shenzhen.aliyuncs.com';
try {
if (!isset($this->client)) {

View File

@ -28,6 +28,8 @@ use app\models\Model;
* @property int $deleted_at 更新时间
* @property int $media 媒体类型0=图片1=视频
* @property string $video_url 视频
* @property string $text 视频
* @property string $other_img_url 视频
*/
class Banner extends \yii\db\ActiveRecord
{
@ -61,8 +63,9 @@ class Banner extends \yii\db\ActiveRecord
[['cx_mch_id', 'user_id', 'zone_id', 'url_type', 'sort', 'is_delete', 'status', 'created_at', 'updated_at', 'deleted_at', 'media'], 'integer'],
[['app_id'], 'string', 'max' => 64],
[['app_ext'], 'string', 'max' => 1024],
[['img_url', 'page_url', 'video_url'], 'string', 'max' => 2048],
[['img_url', 'page_url', 'video_url','other_img_url'], 'string', 'max' => 2048],
[['title'], 'string', 'max' => 512],
[['text'], 'string'],
];
}
@ -124,6 +127,10 @@ class Banner extends \yii\db\ActiveRecord
'0' => '小程序页面',
'1' => '外部链接',
'2' => '小程序',
'3' => '公众号图片',
'4' => '视频号图片',
'5' => '抖音号图片',
'6' => '文章',
];
}
@ -151,14 +158,14 @@ class Banner extends \yii\db\ActiveRecord
{
return [
'0' => '图片',
'1' => '视频',
// '1' => '视频',
];
}
public static function type()
{
return [
'1' => 'banner',
// '1' => 'banner',
'2' => '轮播',
];
}
@ -178,7 +185,7 @@ class Banner extends \yii\db\ActiveRecord
'cx_mch_id' => $cx_mch_id,
'status' => 1,
])
->select('id,url_type,app_id,app_ext,img_url,title,page_url,media,video_url,type')
->select('id,url_type,app_id,app_ext,img_url,title,page_url,media,video_url,type,other_img_url,text')
->orderBy(['sort' => SORT_ASC, 'created_at' => SORT_DESC])->asArray()->all();
foreach ($list as $index => $item) {
if ($item['media'] == self::MEDIA_IMG) {

View File

@ -30,6 +30,9 @@ use app\models\PickLinkForm;
class WechatController extends Controller
{
public $ids = [
12,13,14,15,16,17,18,19,20,21,22,23,24,25
];
public function behaviors()
{
return array_merge(parent::behaviors(), [
@ -77,9 +80,18 @@ class WechatController extends Controller
$form->attributes = \Yii::$app->request->get();
$form->zone_id = Banner::ZONE_ID_WXAPP_INDEX;
$form->cx_mch_id = $this->cx_mch_id;
$data = $form->search();
$data = $form->search($this->ids,'not in');
return $this->render('mp-slide', $data);
}
public function actionMpSlideT()
{
$form = new SlideListForm();
$form->attributes = \Yii::$app->request->get();
$form->zone_id = Banner::ZONE_ID_WXAPP_INDEX;
$form->cx_mch_id = $this->cx_mch_id;
$data = $form->search($this->ids,'in');
return $this->render('mp-slide-t', $data);
}
public function actionMpSlideEdit($id = 0)
{
@ -111,10 +123,16 @@ class WechatController extends Controller
return $this->responseHandler($data);
}
$return_url = \Yii::$app->request->referrer;
$is = false;
if(in_array($id,$this->ids)){
$is = true;
}
return $this->render('mp-slide-edit', [
'model' => $model,
'return_url' => $return_url,
'links' => (new PickLinkForm())->getPickLink()
'links' => (new PickLinkForm())->getPickLink(),
'is' => $is,
'id' => $id,
]);
}

View File

@ -561,6 +561,13 @@ class Menu
'is_show' => true,
'route' => 'admin/wechat/mp-slide',
],
[
'name' => '首页配置',
'is_menu' => true,
'is_show' => true,
'route' => 'admin/wechat/mp-slide-t',
],
[
'name' => '订阅消息',
'is_menu' => true,

View File

@ -34,16 +34,18 @@ class SlideEditForm extends AdminModel
public $media;
public $status;
public $video_url;
public $other_img_url;
public $text;
public function rules()
{
return [
[['app_id', 'app_ext', 'title', 'page_url', 'video_url'], 'trim'],
[['app_id', 'app_ext', 'title', 'page_url', 'video_url'], 'string'],
[['app_id', 'app_ext', 'title', 'page_url', 'video_url','text','other_img_url'], 'string'],
[['cx_mch_id', 'user_id', 'zone_id', 'url_type', 'sort', 'status','type'],'integer'],
[['status'], 'in', 'range' => [0, 1]],
[['cx_mch_id', 'user_id', 'zone_id', 'url_type', 'model', 'status', 'media'], 'required'],
// [['cx_mch_id', 'user_id', 'zone_id', 'url_type', 'model', 'media'], 'required'],
[['img_url'], 'required', 'on' => 'img'],
[['video_url'], 'required', 'on' => 'video'],
];
@ -81,6 +83,8 @@ class SlideEditForm extends AdminModel
$this->model->title = $this->title;
$this->model->sort = $this->sort;
$this->model->type = $this->type;
$this->model->other_img_url = $this->other_img_url;
$this->model->text = $this->text;
if($this->url_type == Banner::URL_TYPE_MP_PAGE){
$this->model->page_url = $this->page_url;
} else if($this->url_type == Banner::URL_TYPE_MP){

View File

@ -36,7 +36,7 @@ class SlideListForm extends AdminModel
];
}
public function search()
public function search($id,$type='in')
{
if(!$this->validate()){
$pagination = new Pagination([
@ -53,6 +53,8 @@ class SlideListForm extends AdminModel
'zone_id' => $this->zone_id,
"is_delete" => 0,
'cx_mch_id' => $this->cx_mch_id
])->andWhere([
$type,'id',$id
])
->select('id,url_type,app_id,app_ext,img_url,title,page_url,sort,created_at,status,media,video_url');
$count = $query->count();
@ -69,6 +71,9 @@ class SlideListForm extends AdminModel
$item['created_at_cn'] = date('Y-m-d H:i:s',$item['created_at']);
$item['status_cn'] = Banner::getStatus($item['status']);
$item['media_cn'] = Banner::getMedia($item['media']);
if(in_array($item['id'],$id)){
$item['status'] = -1;
}
$list[$index] = $item;
}
return [

View File

@ -13,12 +13,30 @@
use app\widgets\PickLinker;
use app\models\Banner;
use app\widgets\PickFile;
use app\assets\UeditorAsset;
$this->title = '编辑轮播图';
$this->params['breadcrumbs'][] = ['label' => '轮播图' , 'url' => [\Yii::$app->urlManager->createUrl(["admin/wechat/mp-slide"])]];
UeditorAsset::register($this);
$skip_k = [];
if(!$is){
$skip_k = [3,4,5,6,7,8,9];
$this->title = '编辑轮播图';
$this->params['breadcrumbs'][] = ['label' => '轮播图' , 'url' => [\Yii::$app->urlManager->createUrl(["admin/wechat/mp-slide"])]];
}else{
$this->title = '编辑配置';
$this->params['breadcrumbs'][] = ['label' => '配置' , 'url' => [\Yii::$app->urlManager->createUrl(["admin/wechat/mp-slide"])]];
if($id == 12){
$skip_k = [0,1,2,3,4,5,7,8,9];
}else{
$skip_k = [6];
}
}
$this->params['breadcrumbs'][] = $this->title;
$url_type_labels = Banner::urlTypeLabels();
foreach ($url_type_labels as $k=>$v){
if(in_array($k,$skip_k)){
unset($url_type_labels[$k]);
}
}
$status_labels = Banner::statusLabels();
$media_labels = Banner::mediaLabels();
$type = Banner::type();
@ -33,23 +51,35 @@ $type = Banner::type();
<div class="layui-form-item">
<label class="layui-form-label">标题</label>
<div class="layui-input-inline">
<input type="text" name="title" placeholder="请输入标题" autocomplete="off" class="layui-input" value="<?= $model->title ?>">
<input type="text" name="title" placeholder="请输入标题" autocomplete="off" class="layui-input" <?=($is?"readonly":"")?> value="<?= $model->title ?>">
</div>
<div class="layui-form-mid layui-word-aux"></div>
</div>
<div class="layui-form-item">
<?= PickFile::widget([
'accept' => 'images',
'id' => 'img_url_upload',
'name' => 'img_url',
'label' => '主图',
'value' => $model->img_url,
'tip' => '图片大小750×330',
'imageCompressEnable' => 1,
'imageCompressBorder' => 750
])?>
<!--<div class="layui-form-item">
<label class="layui-form-label">类型</label>
<div class="layui-input-block type">
<?php foreach ($type as $key => $val):?>
<input type="radio" name="type" value="<?=$key?>"
title="<?=$val?>" <?= $model->type == $key ? 'checked=""' : ''?>>
<?php endforeach;?>
<?php /*foreach ($type as $key => $val):*/?>
<input type="radio" name="type" value="<?php /*=$key*/?>"
title="<?php /*=$val*/?>" <?php /*= $model->type == $key ? 'checked=""' : ''*/?>>
<?php /*endforeach;*/?>
</div>
<div class="layui-form-mid layui-word-aux"></div>
</div>
</div>-->
<div class="block-url">
<?php if($id != 12):?>
<div class="layui-form-item">
<label class="layui-form-label">链接类型</label>
<label class="layui-form-label">内容</label>
<div class="layui-input-block url-type">
<?php foreach ($url_type_labels as $key => $val):?>
<input type="radio" name="url_type" value="<?=$key?>" title="<?=$val?>" <?= $model->url_type == $key ? 'checked=""' : ''?>>
@ -57,16 +87,19 @@ $type = Banner::type();
</div>
<div class="layui-form-mid layui-word-aux"></div>
</div>
<div class="layui-form-item" v-if="url_type == <?=Banner::URL_TYPE_MP_PAGE?>">
<label class="layui-form-label">小程序页面链接</label>
<div class="layui-inline ">
<input type="text" name="page_url" placeholder="" autocomplete="off" class="layui-input page-url" value="<?= $model->url_type == 0 ? $model->page_url : '' ?>" >
</div>
<!-- <div class="layui-inline ">-->
<!-- <button class="layui-btn pick-link-btn">选择链接</button>-->
<!-- </div>-->
<!-- <div class="layui-inline ">-->
<!-- <button class="layui-btn pick-link-btn">选择链接</button>-->
<!-- </div>-->
<div class="layui-form-mid layui-word-aux"></div>
</div>
<?php endif;?>
<div class="layui-form-item" v-if="url_type == <?=Banner::URL_TYPE_LINK?>">
<label class="layui-form-label">外部链接链接</label>
<div class="layui-input-inline">
@ -81,6 +114,37 @@ $type = Banner::type();
</div>
<div class="layui-form-mid layui-word-aux"></div>
</div>
<div class="layui-form-item" v-if="url_type == 3">
</div>
<!--<div class="layui-form-item" v-if="url_type == 4">
<?php /*= PickFile::widget([
'accept' => 'images',
'id' => 'img_url_uploads2',
'name' => 'img_urls',
'label' => '附图',
'value' => $model->other_img_url,
'tip' => '图片大小750×330',
'imageCompressEnable' => 1,
'imageCompressBorder' => 750
])*/?>
</div>
<div class="layui-form-item" v-if="url_type == 5">
<?php /*= PickFile::widget([
'accept' => 'images',
'id' => 'img_url_uploads3',
'name' => 'img_urls',
'label' => '附图',
'value' => $model->other_img_url,
'tip' => '图片大小750×330',
'imageCompressEnable' => 1,
'imageCompressBorder' => 750
])*/?>
</div>-->
<?php if(!$is):?>
<div class="layui-form-item">
<label class="layui-form-label">排序</label>
<div class="layui-input-inline">
@ -88,27 +152,22 @@ $type = Banner::type();
</div>
<div class="layui-form-mid layui-word-aux">升序,值越小排序越靠前</div>
</div>
<?php endif;?>
<div class="layui-form-item">
<!--<div class="layui-form-item">
<label class="layui-form-label">媒体类型</label>
<div class="layui-input-block media">
<?php foreach ($media_labels as $key => $val):?>
<input type="radio" name="media" value="<?=$key?>" title="<?=$val?>" <?= $model->media == $key ? 'checked=""' : ''?>>
<?php endforeach;?>
<?php /*foreach ($media_labels as $key => $val):*/?>
<input type="radio" name="media" value="<?php /*=$key*/?>" title="<?php /*=$val*/?>" <?php /*= $model->media == $key ? 'checked=""' : ''*/?>>
<?php /*endforeach;*/?>
</div>
<div class="layui-form-mid layui-word-aux"></div>
</div>-->
</div>
</div>
<?= PickFile::widget([
'accept' => 'images',
'id' => 'img_url_upload',
'name' => 'img_url',
'label' => '图片',
'value' => $model->img_url,
'tip' => '图片大小750×330',
'imageCompressEnable' => 1,
'imageCompressBorder' => 750
])?>
<?= PickFile::widget([
'accept' => 'video',
'id' => 'video_url_upload',
@ -117,7 +176,7 @@ $type = Banner::type();
'value' => $model->video_url,
'tip' => ''
])?>
<?php if(!$is):?>
<div class="layui-form-item">
<label class="layui-form-label">状态</label>
<div class="layui-input-block url-type">
@ -126,6 +185,31 @@ $type = Banner::type();
</div>
<div class="layui-form-mid layui-word-aux"></div>
</div>
<?php endif;?>
<?php if($is && $id != 12):?>
<?= PickFile::widget([
'accept' => 'images',
'id' => 'img_url_uploads11231',
'name' => 'other_img_url',
'label' => '附图',
'value' => $model->other_img_url,
// 'tip' => '图片大小750×330',
'imageCompressEnable' => 1,
'imageCompressBorder' => 750
])?>
<?php endif;?>
<?php if($id == 12):?>
<div class="layui-form-item">
<label class="layui-form-label">内容</label>
<div class="layui-input-inline">
<textarea id="editor" style="width: 600px" name="content" rows="30" ><?=$model->text?></textarea>
</div>
</div>
<?php endif;?>
<div class="layui-form-item">
<div class="layui-input-block">
<div class="" >
@ -174,7 +258,17 @@ $type = Banner::type();
//console.log(obj)
var url = '<?= \Yii::$app->urlManager->createUrl(["/admin/wechat/mp-slide-edit", 'id' => $model->id ? $model->id : 0]) ?>';
var returnUrl = "<?= $return_url ?>";
console.log(returnUrl)
var data = obj.field;
try{
data.text = UE.getEditor('editor').getContent();
}catch (e){
}
if('<?=$id?>' == 12){
data.url_type = 6
}
data._csrf = _csrf;
$.ajax(url, {
type: "POST",
@ -249,6 +343,62 @@ $type = Banner::type();
init_page();
});
var ue = UE.getEditor('editor', {
serverUrl: "<?= \Yii::$app->urlManager->createUrl(['file/upload']) ?>",
toolbars: [
[
'anchor', //锚点
'undo', //撤销
'redo', //重做
'bold', //加粗
'indent', //首行缩进
'italic', //斜体
'underline', //下划线
'strikethrough', //删除线
'subscript', //下标
'fontborder', //字符边框
'superscript', //上标
'formatmatch', //格式刷
'source', //源代码
'blockquote', //引用
'pasteplain', //纯文本粘贴模式
'selectall', //全选
'preview', //预览
'horizontal', //分隔线
'removeformat', //清除格式
'time', //时间
'date', //日期
'unlink', //取消链接
'cleardoc', //清空文档
'insertcode', //代码语言
'fontfamily', //字体
'fontsize', //字号
'paragraph', //段落格式
'simpleupload', //单图上传
'insertimage', //多图上传
'link', //超链接
'emotion', //表情
'spechars', //特殊字符
'help', //帮助
'justifyleft', //居左对齐
'justifyright', //居右对齐
'justifycenter', //居中对齐
'justifyjustify', //两端对齐
'forecolor', //字体颜色
'insertorderedlist', //有序列表
'insertunorderedlist', //无序列表
'fullscreen', //全屏
'rowspacingtop', //段前距
'rowspacingbottom', //段后距
'wordimage', //图片转存
'lineheight', //行间距
'customstyle', //自定义标题
'autotypeset', //自动排版
'drafts', // 从草稿箱加载
]
]
});
<?php $this->endBlock(); ?>
</script>
<?php $this->registerJs($this->blocks['js_script_wrap'], \yii\web\View::POS_END); ?>

View File

@ -0,0 +1,407 @@
<?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">
</div>
<div class="layui-inline layui-float-right layui-form">
<div class="layui-inline layui-form-item">
<div class="layui-input-inline">
<select class="layui-select" name="status">
<option value="" <?php /*=$status === null ? 'selected' : ''*/?>>全部状态</option>
<?php /*foreach ($status_labels as $key => $val):*/?>
<option value="<?php /*=$key*/?>" <?php /*=$status == $key && $status != null ? 'selected' : ''*/?>><?php /*=$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="<?php /*=\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"><?php /*=$item['url_type_cn']*/?></span>
<?php /*if($item['url_type'] == Banner::URL_TYPE_MP):*/?>
<?php /*=$item['app_id']*/?>
<?php /*else:*/?>
<?php /*=$item['page_url']*/?>
<?php /*endif;*/?>
</td>-->
<!-- <td>--><?php //=$item["sort"]?><!--</td>-->
<td><?=$item["created_at_cn"]?></td>
<!--<td>
<?php /*if($item['status'] == Banner::STATUS_HIDE):*/?>
<span class="layui-badge layui-bg-gray"><?php /*=$item["status_cn"]*/?></span>
<?php /*elseif($item['status'] == Banner::STATUS_SHOW):*/?>
<span class="layui-badge layui-bg-blue"><?php /*=$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); ?>