pboot轮播图多图

刚开始做pbootcms的网站,记录一下以备不时之需,也分享给大家,亲测有效,有问题欢迎评论留言

1.修改文件/apps/admin/view/default/content/slide.html

<div class="layui-form-item">
                     <label class="layui-form-label">图片</label>
                     <div class="layui-input-inline">
                     	<input type="text" name="pic" id="pic" required  lay-verify="required" value="{$slide->pic}" placeholder="请上传图片"  class="layui-input">
                     </div>
                     <button type="button" class="layui-btn upload" data-des="pic">
					 	 <i class="layui-icon">&#xe67c;</i>上传图片
					 </button>
					 <div id="pic_box" class="pic">{if([$slide->pic])}<dl><dt><img src="{SITE_DIR}{$slide->pic}" data-url="{$slide->pic}"></dt><dd>删除</dd></dl>{/if}</div>
                </div>


                <div class="layui-form-item">
                     <label class="layui-form-label">图一</label>
                     <div class="layui-input-inline">
                        <input type="text" name="pic1" id="pic1"    value="{$slide->pic1}" placeholder="请上传图片"  class="layui-input">
                     </div>
                     <button type="button" class="layui-btn upload" data-des="pic1">
                         <i class="layui-icon">&#xe67c;</i>上传图片
                     </button>
                     <div id="pic1_box" class="pic1">{if([$slide->pic1])}<dl><dt><img src="{SITE_DIR}{$slide->pic1}" data-url="{$slide->pic1}"></dt><dd>删除</dd></dl>{/if}</div>
                </div>

2、修改css /apps/admin/view/default/css/comm.css

.pic,
.pic1,
.pic2 {
	margin-left: 130px;
}
.pic dl,
.pic1 dl,
.pic2 dl {
	float: left;
	position: relative;
}

.pic dl dd,
.pic1 dl dd,
.pic2 dl dd {
	position: absolute;
	right: 5px;
	top: 5px;
	cursor: pointer;
	background: #666;
	color: #fff;
	padding: 2px;
}

.pic img,
.pic1 img,
.pic2 img {
	max-height: 100px;
	margin: 5px 0;
	margin-right: 5px;
}

3、修改/apps/admin/view/default/js/mylayui.js

  //图片页面删除功能
  $('.pic').on("click",'dl dd',function(){
	  var id=$(this).parents('.pic').attr('id');
	  var url=$(this).siblings('dt').find('img').data('url');
	  var input=$('#'+id.replace('_box',''));
	  var value = input.val();
	  value = value.replace(url,'');
	  value = value.replace(/^,/, '');
	  value = value.replace(/,$/, '');
	  value = value.replace(/,,/, ',');
      input.val(value);
	  $(this).parents('dl').remove();
  });

    //图片1页面删除功能
  $('.pic1').on("click",'dl dd',function(){
	  var id=$(this).parents('.pic1').attr('id');
	  var url=$(this).siblings('dt').find('img').data('url');
	  var input=$('#'+id.replace('_box',''));
	  var value = input.val();
	  value = value.replace(url,'');
	  value = value.replace(/^,/, '');
	  value = value.replace(/,$/, '');
	  value = value.replace(/,,/, ',');
      input.val(value);
	  $(this).parents('dl').remove();
  });

4、修改/apps/admin/controller/content/SlideController.php

    // 轮播图增加
    public function add()
    {
        if ($_POST) {
            // 获取数据
            $gid = post('gid', 'int');
            $pic = post('pic');
            $pic1 = post('pic1');
            $pic2 = post('pic2');
            $link = post('link');
            $title = post('title');
            $subtitle = post('subtitle');
            $sorting = post('sorting', 'int');
            
            if (! $gid) {
                $gid = $this->model->getMaxGid() + 1;
            }
            
            if (! $pic) {
                alert_back('图片不能为空!');
            }
            
            // 构建数据
            $data = array(
                'acode' => session('acode'),
                'gid' => $gid,
                'pic' => $pic,
                'pic1' => $pic1,
                'pic2' => $pic2,
                'link' => $link,
                'title' => $title,
                'subtitle' => $subtitle,
                'sorting' => $sorting,
                'create_user' => session('username'),
                'update_user' => session('username')
            );
            
            // 执行添加
            if ($this->model->addSlide($data)) {
                $this->log('新增轮播图成功!');
                if (! ! $backurl = get('backurl')) {
                    success('新增成功!', base64_decode($backurl));
                } else {
                    success('新增成功!', url('/admin/Slide/index'));
                }
            } else {
                $this->log('新增轮播图失败!');
                error('新增失败!', - 1);
            }
        }
    }

    // 轮播图删除
    public function del()
    {
        if (! $id = get('id', 'int')) {
            error('传递的参数值错误!', - 1);
        }
        
        if ($this->model->delSlide($id)) {
            $this->log('删除轮播图' . $id . '成功!');
            success('删除成功!', - 1);
        } else {
            $this->log('删除轮播图' . $id . '失败!');
            error('删除失败!', - 1);
        }
    }

    // 轮播图修改
    public function mod()
    {
        if (! ! $submit = post('submit')) {
            switch ($submit) {
                case 'sorting': // 修改列表排序
                    $listall = post('listall');
                    if ($listall) {
                        $sorting = post('sorting');
                        foreach ($listall as $key => $value) {
                            if ($sorting[$key] === '' || ! is_numeric($sorting[$key]))
                                $sorting[$key] = 255;
                            $this->model->modSlide($value, "sorting=" . $sorting[$key]);
                        }
                        $this->log('批量修改轮播图排序成功!');
                        success('修改成功!', - 1);
                    } else {
                        alert_back('排序失败,无任何内容!');
                    }
                    break;
            }
        }
        
        if (! $id = get('id', 'int')) {
            error('传递的参数值错误!', - 1);
        }
        
        // 单独修改状态
        if (($field = get('field', 'var')) && ! is_null($value = get('value', 'var'))) {
            if ($this->model->modSlide($id, "$field='$value',update_user='" . session('username') . "'")) {
                location(- 1);
            } else {
                alert_back('修改失败!');
            }
        }
        
        // 修改操作
        if ($_POST) {
            
            // 获取数据
            $gid = post('gid', 'int');
            $pic = post('pic');
            $pic1 = post('pic1');
            $pic2 = post('pic2');
            $link = post('link');
            $title = post('title');
            $subtitle = post('subtitle');
            $sorting = post('sorting', 'int');
            
            if (! $gid) {
                $gid = $this->model->getMaxGid() + 1;
            }
            
            if (! $pic) {
                alert_back('图片不能为空!');
            }
            
            // 构建数据
            $data = array(
                'gid' => $gid,
                'pic' => $pic,
                'pic1' => $pic1,
                'pic2' => $pic2,
                'link' => $link,
                'title' => $title,
                'subtitle' => $subtitle,
                'sorting' => $sorting,
                'update_user' => session('username')
            );
            
            // 执行添加
            if ($this->model->modSlide($id, $data)) {
                $this->log('修改轮播图' . $id . '成功!');
                if (! ! $backurl = get('backurl')) {
                    success('修改成功!', base64_decode($backurl));
                } else {
                    success('修改成功!', url('/admin/Slide/index'));
                }
            } else {
                location(- 1);
            }
        } else {
            // 调取修改内容
            $this->assign('mod', true);
            if (! $result = $this->model->getSlide($id)) {
                error('编辑的内容已经不存在!', - 1);
            }
            $this->assign('gids', $this->model->getGid());
            $this->assign('slide', $result);
            $this->display('content/slide.html');
        }
    }
}

4.数据库添加字段(可以使用DB Browser for SQLite 编辑器)
在这里插入图片描述
alter table ay_slide add pic1 int;
update ay_slide set pic1 = pic;
alter table ay_slide add pic2 int;
update ay_slide set pic2 = pic;

5.修改文件/apps/home/controller/ParserController.php

                            case 'i':
                                $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $key), $one_html);
                                break;
                            case 'src':
                                if ($value->pic) {
                                    if (! preg_match('/^http/', $value->pic)) {
                                        $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, SITE_DIR . $value->pic), $one_html);
                                    } else {
                                        $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->pic), $one_html);
                                    }
                                } else {
                                    $one_html = str_replace($matches2[0][$j], '', $one_html);
                                }
                                break;

                                case 'src1':
                                if ($value->pic1) {
                                    if (! preg_match('/^http/', $value->pic1)) {
                                        $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, SITE_DIR . $value->pic1), $one_html);
                                    } else {
                                        $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, $value->pic1), $one_html);
                                    }
                                } else {
                                    $one_html = str_replace($matches2[0][$j], '', $one_html);
                                }
                                break;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值