xxxrrrdddd 3 年之前
父节点
当前提交
e56250d65e
共有 4 个文件被更改,包括 237 次插入140 次删除
  1. 195 0
      application/service/Layui.php
  2. 11 0
      application/sub/config.php
  3. 6 0
      application/sub/controller/Order.php
  4. 25 140
      application/sub/view/order/mobile.html

+ 195 - 0
application/service/Layui.php

@@ -0,0 +1,195 @@
+<?php
+namespace app\service;
+
+use think\Paginator;
+
+class Layui extends Paginator{
+
+    /**
+     * 上一页按钮
+     * @param string $text
+     * @return string
+     */
+    protected function getPreviousButton($text = "上一页")
+    {
+
+        if ($this->currentPage() <= 1) {
+            return $this->getDisabledTextWrapper($text);
+        }
+
+        $url = $this->url(
+            $this->currentPage() - 1
+        );
+
+        return $this->getPageLinkWrapper($url, $text);
+    }
+
+    /**
+     * 下一页按钮
+     * @param string $text
+     * @return string
+     */
+    protected function getNextButton($text = '下一页')
+    {
+        if (!$this->hasMore) {
+            return $this->getDisabledTextWrapper($text);
+        }
+
+        $url = $this->url($this->currentPage() + 1);
+
+        return $this->getPageLinkWrapper($url, $text);
+    }
+
+    /**
+     * 页码按钮
+     * @return string
+     */
+    protected function getLinks()
+    {
+        if ($this->simple)
+            return '';
+
+        $block = [
+            'first' => null,
+            'slider' => null,
+            'last' => null
+        ];
+
+        $side = 3;
+        $window = $side * 2;
+
+        if ($this->lastPage < $window + 6) {
+            $block['first'] = $this->getUrlRange(1, $this->lastPage);
+        } elseif ($this->currentPage <= $window) {
+            $block['first'] = $this->getUrlRange(1, $window + 2);
+            $block['last'] = $this->getUrlRange($this->lastPage - 1, $this->lastPage);
+        } elseif ($this->currentPage > ($this->lastPage - $window)) {
+            $block['first'] = $this->getUrlRange(1, 2);
+            $block['last'] = $this->getUrlRange($this->lastPage - ($window + 2), $this->lastPage);
+        } else {
+            $block['first'] = $this->getUrlRange(1, 2);
+            $block['slider'] = $this->getUrlRange($this->currentPage - $side, $this->currentPage + $side);
+            $block['last'] = $this->getUrlRange($this->lastPage - 1, $this->lastPage);
+        }
+
+        $html = '';
+
+        if (is_array($block['first'])) {
+            $html .= $this->getUrlLinks($block['first']);
+        }
+
+        if (is_array($block['slider'])) {
+            $html .= $this->getDots();
+            $html .= $this->getUrlLinks($block['slider']);
+        }
+
+        if (is_array($block['last'])) {
+            $html .= $this->getDots();
+            $html .= $this->getUrlLinks($block['last']);
+        }
+
+        return $html;
+    }
+
+    /**
+     * 渲染分页html
+     * @return mixed
+     */
+    public function render()
+    {
+        if ($this->hasPages()) {
+            if ($this->simple) {
+                return sprintf(
+                    '<div class="layui-box layui-laypage layui-laypage-default">%s %s</div>',
+                    $this->getPreviousButton(),
+                    $this->getNextButton()
+                );
+            } else {
+                return sprintf(
+                    '<div class="layui-box layui-laypage layui-laypage-default">%s %s %s</div>',
+                    $this->getPreviousButton(),
+                    $this->getLinks(),
+                    $this->getNextButton()
+                );
+            }
+        }
+    }
+
+    /**
+     * 生成一个可点击的按钮
+     *
+     * @param string $url
+     * @param int $page
+     * @return string
+     */
+    protected function getAvailablePageWrapper($url, $page)
+    {
+        return '<a href="' . htmlentities($url) . '">' . $page . '</a>';
+    }
+
+    /**
+     * 生成一个禁用的按钮
+     *
+     * @param string $text
+     * @return string
+     */
+    protected function getDisabledTextWrapper($text)
+    {
+        return "<span class=\"layui-laypage-curr\"><em class=\"layui-laypage-em\"></em><em>{$text}</em></span>";
+    }
+
+    /**
+     * 生成一个激活的按钮
+     *
+     * @param string $text
+     * @return string
+     */
+    protected function getActivePageWrapper($text)
+    {
+        return "<span class=\"layui-laypage-curr\"><em class=\"layui-laypage-em\"></em><em>{$text}</em></span>";
+    }
+
+    /**
+     * 生成省略号按钮
+     *
+     * @return string
+     */
+    protected function getDots()
+    {
+        return $this->getDisabledTextWrapper('...');
+    }
+
+    /**
+     * 批量生成页码按钮.
+     *
+     * @param array $urls
+     * @return string
+     */
+    protected function getUrlLinks(array $urls)
+    {
+        $html = '';
+
+        foreach ($urls as $page => $url) {
+            $html .= $this->getPageLinkWrapper($url, $page);
+        }
+
+        return $html;
+    }
+
+    /**
+     * 生成普通页码按钮
+     *
+     * @param string $url
+     * @param int $page
+     * @return string
+     */
+    protected function getPageLinkWrapper($url, $page)
+    {
+        if ($page == $this->currentPage()) {
+            return $this->getActivePageWrapper($page);
+        }
+
+        return $this->getAvailablePageWrapper($url, $page);
+    }
+
+}

+ 11 - 0
application/sub/config.php

@@ -0,0 +1,11 @@
+<?php
+
+use app\service\Layui;
+
+return [
+    'paginate'               => [
+        'type'      => Layui::class,
+        'var_page'  => 'page',
+        'list_rows' => 15,
+    ],
+];

+ 6 - 0
application/sub/controller/Order.php

@@ -4,6 +4,7 @@ namespace app\sub\controller;
 
 
 use app\common\model\Attachment;
+use app\common\model\Mobile;
 use think\Cookie;
 use think\Hook;
 use think\Validate;
@@ -17,6 +18,11 @@ class Order extends SubCommon
     protected $noNeedRight="*";
 
     public function mobile(){
+        $list=Mobile::
+            //where('s_id',$this->auth->id)
+            order('id','desc')
+            ->paginate();
+        $this->assign('list',$list);
         return view();
     }
 }

+ 25 - 140
application/sub/view/order/mobile.html

@@ -14,12 +14,6 @@
         <a class="layui-btn layui-btn-normal newsAdd_btn">添加文章</a>
     </div>
     <div class="layui-inline">
-        <a class="layui-btn recommend" style="background-color:#5FB878">推荐文章</a>
-    </div>
-    <div class="layui-inline">
-        <a class="layui-btn audit_btn">审核文章</a>
-    </div>
-    <div class="layui-inline">
         <a class="layui-btn layui-btn-danger batchDel">批量删除</a>
     </div>
     <div class="layui-inline">
@@ -29,20 +23,20 @@
 <div class="layui-form news_list">
     <table class="layui-table">
         <colgroup>
-            <col width="50">
             <col>
-            <col width="9%">
-            <col width="9%">
-            <col width="9%">
-            <col width="9%">
-            <col width="9%">
-            <col width="15%">
+            <col>
+            <col>
+            <col>
+            <col>
+            <col>
+            <col>
+            <col>
         </colgroup>
         <thead>
         <tr>
-            <th><input type="checkbox" name="" lay-skin="primary" lay-filter="allChoose" id="allChoose"></th>
-            <th style="text-align:left;">文章标题</th>
-            <th>发布人</th>
+            <th><input type="checkbox" lay-skin="primary" lay-filter="allChoose" id="allChoose"></th>
+            <th>ID</th>
+            <th>手机号</th>
             <th>审核状态</th>
             <th>浏览权限</th>
             <th>是否展示</th>
@@ -50,50 +44,32 @@
             <th>操作</th>
         </tr>
         </thead>
-        <tbody class="news_content"></tbody>
+        <tbody class="news_content">
+        {foreach name="list" item="a"}
+        <tr>
+            <th><input type="checkbox" lay-skin="primary" lay-filter="allChoose" id="id-{$a.id}"></th>
+            <td>{$a.id}</td>
+            <td>{$a.no}</td>
+        </tr>
+        {/foreach}
+        </tbody>
     </table>
 </div>
-<div id="page"></div>
+<div id="page">
+    {$list->render()}
+</div>
 {/block}
 {block name='js'}
+
 <script>
     layui.config({
-        base : "js/"
+        base : "__SUB__/js/"
     }).use(['form','layer','jquery','laypage'],function(){
         var form = layui.form(),
             layer = parent.layer === undefined ? layui.layer : parent.layer,
             laypage = layui.laypage,
             $ = layui.jquery;
 
-        //加载页面数据
-        var newsData = '';
-        $.get("../../json/newsList.json", function(data){
-            var newArray = [];
-            //单击首页“待审核文章”加载的信息
-            if($(".top_tab li.layui-this cite",parent.document).text() == "待审核文章"){
-                if(window.sessionStorage.getItem("addNews")){
-                    var addNews = window.sessionStorage.getItem("addNews");
-                    newsData = JSON.parse(addNews).concat(data);
-                }else{
-                    newsData = data;
-                }
-                for(var i=0;i<newsData.length;i++){
-                    if(newsData[i].newsStatus == "待审核"){
-                        newArray.push(newsData[i]);
-                    }
-                }
-                newsData = newArray;
-                newsList(newsData);
-            }else{    //正常加载信息
-                newsData = data;
-                if(window.sessionStorage.getItem("addNews")){
-                    var addNews = window.sessionStorage.getItem("addNews");
-                    newsData = JSON.parse(addNews).concat(newsData);
-                }
-                //执行加载数据的方法
-                newsList();
-            }
-        })
 
         //查询
         $(".search_btn").click(function(){
@@ -183,47 +159,8 @@
                 })
                 layui.layer.full(index);
             })
-        }).resize();
+        }).resize()
 
-        //推荐文章
-        $(".recommend").click(function(){
-            var $checkbox = $(".news_list").find('tbody input[type="checkbox"]:not([name="show"])');
-            if($checkbox.is(":checked")){
-                var index = layer.msg('推荐中,请稍候',{icon: 16,time:false,shade:0.8});
-                setTimeout(function(){
-                    layer.close(index);
-                    layer.msg("推荐成功");
-                },2000);
-            }else{
-                layer.msg("请选择需要推荐的文章");
-            }
-        })
-
-        //审核文章
-        $(".audit_btn").click(function(){
-            var $checkbox = $('.news_list tbody input[type="checkbox"][name="checked"]');
-            var $checked = $('.news_list tbody input[type="checkbox"][name="checked"]:checked');
-            if($checkbox.is(":checked")){
-                var index = layer.msg('审核中,请稍候',{icon: 16,time:false,shade:0.8});
-                setTimeout(function(){
-                    for(var j=0;j<$checked.length;j++){
-                        for(var i=0;i<newsData.length;i++){
-                            if(newsData[i].newsId == $checked.eq(j).parents("tr").find(".news_del").attr("data-id")){
-                                //修改列表中的文字
-                                $checked.eq(j).parents("tr").find("td:eq(3)").text("审核通过").removeAttr("style");
-                                //将选中状态删除
-                                $checked.eq(j).parents("tr").find('input[type="checkbox"][name="checked"]').prop("checked",false);
-                                form.render();
-                            }
-                        }
-                    }
-                    layer.close(index);
-                    layer.msg("审核成功");
-                },2000);
-            }else{
-                layer.msg("请选择需要审核的文章");
-            }
-        })
 
         //批量删除
         $(".batchDel").click(function(){
@@ -311,58 +248,6 @@
                 layer.close(index);
             });
         })
-
-        function newsList(that){
-            //渲染数据
-            function renderDate(data,curr){
-                var dataHtml = '';
-                if(!that){
-                    currData = newsData.concat().splice(curr*nums-nums, nums);
-                }else{
-                    currData = that.concat().splice(curr*nums-nums, nums);
-                }
-                if(currData.length != 0){
-                    for(var i=0;i<currData.length;i++){
-                        dataHtml += '<tr>'
-                            +'<td><input type="checkbox" name="checked" lay-skin="primary" lay-filter="choose"></td>'
-                            +'<td align="left">'+currData[i].newsName+'</td>'
-                            +'<td>'+currData[i].newsAuthor+'</td>';
-                        if(currData[i].newsStatus == "待审核"){
-                            dataHtml += '<td style="color:#f00">'+currData[i].newsStatus+'</td>';
-                        }else{
-                            dataHtml += '<td>'+currData[i].newsStatus+'</td>';
-                        }
-                        dataHtml += '<td>'+currData[i].newsLook+'</td>'
-                            +'<td><input type="checkbox" name="show" lay-skin="switch" lay-text="是|否" lay-filter="isShow"'+currData[i].isShow+'></td>'
-                            +'<td>'+currData[i].newsTime+'</td>'
-                            +'<td>'
-                            +  '<a class="layui-btn layui-btn-mini news_edit"><i class="iconfont icon-edit"></i> 编辑</a>'
-                            +  '<a class="layui-btn layui-btn-normal layui-btn-mini news_collect"><i class="layui-icon">&#xe600;</i> 收藏</a>'
-                            +  '<a class="layui-btn layui-btn-danger layui-btn-mini news_del" data-id="'+data[i].newsId+'"><i class="layui-icon">&#xe640;</i> 删除</a>'
-                            +'</td>'
-                            +'</tr>';
-                    }
-                }else{
-                    dataHtml = '<tr><td colspan="8">暂无数据</td></tr>';
-                }
-                return dataHtml;
-            }
-
-            //分页
-            var nums = 13; //每页出现的数据量
-            if(that){
-                newsData = that;
-            }
-            laypage({
-                cont : "page",
-                pages : Math.ceil(newsData.length/nums),
-                jump : function(obj){
-                    $(".news_content").html(renderDate(newsData,obj.curr));
-                    $('.news_list thead input[type="checkbox"]').prop("checked",false);
-                    form.render();
-                }
-            })
-        }
     })
 
 </script>