【TP5】对于广告分类跟搜索的解决方案

【TP5】对于广告分类跟搜索的解决方案,第1张

概述author:咔咔wechat:fangkangfk需求:点击广告分类,在点击查询,需要查询本分类下的广告首先我们需要固定的就是样式问题第一次进入的时候显示的是全部的广告,那么我们的全部广告就需要被点击的样式,所以我们直接就给全部广告加了一个checked点击全部广告是不需要条件的,所有地址没有追加参数点击其他的广告分类,带上各自在数据...

author:咔咔

wechat:fangkangfk

需求:点击广告分类,在点击查询,需要查询本分类下的广告

首先我们需要固定的就是样式问题

第一次进入的时候显示的是全部的广告,那么我们的全部广告就需要被点击的样式,所以我们直接就给全部广告加了一个checked

点击全部广告是不需要条件的,所有地址没有追加参数

点击其他的广告分类,带上各自在数据库的标识,然候使用参数传递给后台

同样后台也会接收这个参数,去数据库查询

由于是a链接跳转,所以我们使用addClass的方式是肯定不行的,这个时候就需要后台传递参数给前端,然候根据这个值进行判断点击的是那个

现在点击分类的业务处理好了,还需要处理查询时查询当下分类的数据

我们就需要在点击查询的form表单里边放置一个隐藏域,并且name值需要跟点击广告追加的参数名相同,这个隐藏域的value值,同样是不可以直接使用attr的方式添加,所以依然使用后台传递的方式

 

这样在点击查询的时候就会将这个条件带上

下来我们做一个测试

我们设置了俩条banner数据,但是标题不一样

 点击banner

查询kak

结果:

前端代码

{include file="../../../application/admin/vIEw/public/head" /}<style>    .layui-badge-rim{        margin: 0 30px;    }    .type{        margin: 50px 50px 50px 10px;        background-color: #009818;    }    .checked{        background-color: #666;    }</style><form  method="post">    {if condition="isset($showType)"}    <a  attr="1" href="{:url('index')}"> 全部广告</a><a  attr="1" href="{:url('index')}?showType=1"> Banner广告</a><a  attr="2" href="{:url('index')}?showType=2"> 专题广告</a><a  attr="3" href="{:url('index')}?showType=3"> 详情页广告</a><a  attr="4" href="{:url('index')}"> 启动页广告</a>    {else if}    <a  attr="1" href="{:url('index')}"> 全部广告</a>    <a  attr="1" href="{:url('index')}?showType=1"> Banner广告</a>    <a  attr="2" href="{:url('index')}?showType=2"> 专题广告</a>    <a  attr="3" href="{:url('index')}?showType=3"> 详情页广告</a>    <a  attr="4" href="{:url('index')}"> 启动页广告</a>    {/if}</form><div >    <form  method="post" ID="PagelistForm">        <div >            <div >                <a data-full="1" data-href="{:url('addBanner')}" ><i >&#xe654;</i>添加广告</a>            </div>        </div>        {if condition="isset($showType)"}        <!--存放点击的类型-->        <input type="hIDden" ID="showType" name="showType" value="{$showType}">        {/if}        <div >            <select name="vt_ID" >                <option value="">视频类型</option>                {foreach name='subject' item='v'}                {if condition="isset($param['vt_ID'])"}                <option {if condition="$param['vt_ID'] eq $v['vt_ID']"} selected {/if} value="{$v['vt_ID']}"  >{$v['vt_name']}</option>                {else if /}                <option value="{$v['vt_ID']}"  >{$v['vt_name']}</option>                {/if}                {/foreach}            </select>        </div>        <div >            <input type="text" autocomplete="off" placeholder="请输入广告名" ID="content"  name="b_Title" value="{$param['b_Title']?$param['b_Title']:''}">        </div>        <button  ID="query"> 查询</button>        <table  lay-size="sm">        <thead>            <tr >                <th >ID</th>                <th >标题</th>                <th >分类</th>                <th >对应视频名</th>                <th >展示类型</th>                <th >排序</th>                <th > *** 作</th>            </tr>        </thead>            {foreach name='bannerList' item='v'}            <tr height="50">                <th>{$v['b_ID']}</th>                <td>{$v['b_Title']}</td>                <td>{$v['banner_type']['vt_name']}</td>                <td>{$v['banner_vs_vIDeo_name']['vi_Title']}</td>                {if condition="$v['b_showType'] eq 1"}                <td>banner广告</td>                {/if}                {if condition="$v['b_showType'] eq 2"}                <td>专题</td>                {/if}                {if condition="$v['b_showType'] eq 3"}                <td>详情页</td>                {/if}                <td>{$v['b_sort']}</td>                <td wIDth="500">                    <a  wIDth="100" data-full="1" data-href="{:url('editBanner?b_ID='.$v.b_ID)}" href="JavaScript:;" title="编辑">编辑</a>                    <a  data-ID="{$v.b_ID}" data-href="" href="JavaScript:;" title="删除">删除</a>                </td>            </tr>            {/foreach}        </table>    </form></div><div ID="pages" ></div>{include file="../../../application/admin/vIEw/public/foot" /}<script type="text/JavaScript">    layui.use(['jquery',],function(args){        var $= layui.jquery;        $('.type').click(function () {            var showType = $(this).attr('attr');            alert(showType)            $('#showType').val(showType);        })    });    // 点击删除    $(document).on('click','.del',function(){        var that = $(this),href = !that.attr('data-href') ? that.attr('href') : that.attr('data-href');        layer.confirm('删除之后无法恢复,您确定要删除吗?',{Title:false,closeBtn:0},function(index){            if (!href) {                layer.msg('请设置data-href参数');                return false;            }            $.get(href,function(res){                layer.msg(res.msg);                if (res.code == 1) {                    that.parents('tr').remove();                }            });            layer.close(index);        });        return false;    })    /**     * 更改数据顺序     */    layui.use('laypage',function(){        var laypage = layui.laypage,layer = layui.layer,$ = layui.$;        $(document).on('blur','.sort',function(){            var that = $(this),b_sort = that.val();            var b_ID = that.attr('b_ID');            $.post("{:url('banner/editSort')}",{b_sort:b_sort,b_ID:b_ID},function(res){                if(res == 1){                    loadData()                }            });        })    });</script></body></HTML>

后台代码:

    /**     * banner列表     * @return array     */    public function index()    {        $param = $this->request->param();        $where = [];        if(!empty($param['vt_ID'])){            $where['vt_ID'] = $param['vt_ID'];        }        if(!empty($param['b_Title'])){            $where['b_Title'] = ['like',"%".$param['b_Title']."%"];        }        if(!empty($param['showType'])){            $where['b_showType'] = $param['showType'];        }        if(!empty($param['vt_ID']) && !empty($param['b_targettype']) && !empty($paran['b_Title'])){            $where = '1 = 1';        }        // banner列表        $bannerList = $this->bannerModel->bannerList($where);        // 类型        $vIDeoTypeList = Db::name($this->vIDeoTypeModel->tablename)->select();        if(!empty($param)){            $this->assign('param',$param);        }        if(!empty($param['showType'])){            $this->assign('showType',$param['showType']);        }        $this->assign([            'subject' => $vIDeoTypeList,'bannerList' => $bannerList,]);        return $this->fetch();    }

总结

以上是内存溢出为你收集整理的【TP5】对于广告分类跟搜索的解决方案全部内容,希望文章能够帮你解决【TP5】对于广告分类跟搜索的解决方案所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1220926.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存