Browse Source

8-6分页获取分类列表

Home 5 years ago
parent
commit
b2c4235ee8

+ 13 - 1
app/admin/controller/Category.php

@@ -15,7 +15,19 @@ class Category extends AdminBase
      */
     public function index()
     {
-        return View::fetch();
+        $pid = input('param.id', 0, 'intval');
+        $data = [
+            "pid" => $pid
+        ];
+        try {
+            $categorys = (new CategoryBusiness())->getLists($data, 5);
+        } catch (\Exception $e) {
+            $categorys = [];
+        }
+
+        return View::fetch('', [
+            'categorys' => $categorys
+        ]);
     }
 
     /**

+ 36 - 56
app/admin/view/category/index.html

@@ -30,24 +30,30 @@
 <body>
 <div class="layuimini-container">
     <div class="layuimini-main">
-        <a href="{:url('add')}"><button type="button" class="layui-btn add">添 加</button></a>
+        <a href="{:url('add')}">
+            <button type="button" class="layui-btn add">添 加</button>
+        </a>
 
         <div class="layui-form" style="margin-top: 20px;">
             <table class="layui-table">
                 <colgroup>
-                    <col width="90">
-                    <col width="110">
-                    <col width="800">
+                    <col width="40">
+                    <col width="60">
+                    <col width="100">
                     <col width="130">
+                    <col width="130">
+                    <col width="70">
                     <col width="70">
-                    <col width="85">
+                    <col width="185">
                 </colgroup>
                 <thead>
                 <tr>
                     <th>id</th>
-                    <th>一级分类</th>
-                    <th class="text-center">二 / 三级分类</th>
+                    <th>标题</th>
+                    <th>排序</th>
                     <th class="text-center">创建时间</th>
+                    <th class="text-center">操作时间</th>
+                    <th class="text-center">操作人</th>
                     <th class="text-center">状 态</th>
                     <th>操作管理</th>
                 </tr>
@@ -56,56 +62,30 @@
                 <!--一级类目循环-->
                 <tr>
                     <td>
-                        <div class="layui-input-inline">
-                          <input type="text" value="1" data-id="1" class="changeSort layui-input">
-                        </div>
+                        1
+                    </td>
+                    <td>
+                        abcd
                     </td>
                     <td>
                         <div class="layui-input-inline">
-                            <input type="text" name="p0" autocomplete="off" class="layui-input" value="一级类目"
-                                   onchange="editCls(this,id=1,ptype=1)">
+                            <input type="text" value="1" data-id="1" class="changeSort layui-input">
                         </div>
                     </td>
                     <td>
-                        <!--二级类目循环 start-->
-                        <div class="layui-input-block" style="margin-left: 0;">
-                            <button data-ptype="2" type="button"
-                                    class="layui-btn layui-btn-primary layui-btn-sm del-child"
-                                    style="border: none;"><i class="layui-icon"></i></button>
-                            <div class="layui-input-inline">
-                                <input type="text" name="p1" style="background: #ffb800;" autocomplete="off"
-                                       class="inoutCls" onchange="editCls(this,id=1,ptype=2)" value="二级类目">
-                            </div>
-
-                            <!-- 三级类目循环 start-->
-                            <div class="layui-input-inline">
-                                --<input type="text" name="p1" autocomplete="off" class="inoutCls"
-                                         onchange="editCls(this,id=1,ptype=3)" value="1。1">
-                            </div>
-                            <div class="layui-input-inline">
-                                --<input type="text" name="p1" autocomplete="off" class="inoutCls"
-                                         onchange="editCls(this,id=1,ptype=3)" value="1。2">
-                            </div>
-                            <div class="layui-input-inline">
-                                --<input type="text" name="p1" autocomplete="off" class="inoutCls"
-                                         onchange="editCls(this,id=1,ptype=3)" value="1。3">
-                            </div>
-                            <!-- 三级类目循环 end-->
-                        </div>
-
-                        <!--二级类目循环 end-->
+                        创建时间
                     </td>
-                    <td>2019-11-20 10:40</td>
-
-                    <td data-id="1"><input type="checkbox" checked="" name="status" lay-skin="switch"
-                                           lay-filter="switchTest"
-                                           lay-text="ON|OFF">
+                    <td>
+                        更新时间
+                    </td>
+                    <td>
+                        singwa
+                    </td>
+                    <td data-id="1"><input type="checkbox" checked="" name="status" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">
                     </td>
-
-
                     <td>
-                        <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete del-child" data-ptype="1"
-                           lay-event="delete" data-id="$id">删除</a>
+                        <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete del-child" data-ptype="1" lay-event="delete" data-id="$id">删除</a>
+                        <a href="{:url('index', ['pid'=>1])}">获取子栏目</a>
                     </td>
                 </tr>
                 <!--一级类目循环 end-->
@@ -161,8 +141,8 @@
             if (!name && type == 3) { // 演示 应该放到修改回调中  进行处理
                 return $(that).parent().remove()
             }
-            let   url = '{:url("admin/edit")}?id=' + id + '&name=' + name
-            layObj.get(url,  (res) =>{
+            let url = '{:url("admin/edit")}?id=' + id + '&name=' + name
+            layObj.get(url, (res) => {
                 if (name && res) {
                     $(that).val(name)
                 }
@@ -188,24 +168,24 @@
                 msg = '二';
             }
             layObj.box(`是否删除${msg}级分类`, () => {
-                let   url = '{:url("admin/del")}?id=' + id
-                layObj.get(url,  (res) =>{
+                let url = '{:url("admin/del")}?id=' + id
+                layObj.get(url, (res) => {
                     $(this).parent().remove()
                 })
 
             })
         })
 
-        $('.changeSort').on('change',function () {
+        $('.changeSort').on('change', function () {
             let id = $(this).attr('data-id');
             let val = $(this).val();
 
-            if(!val){
+            if (!val) {
                 return;
             }
-            let url = '{:url("admin/sort")}?id=' + id + '&sort='+val;
+            let url = '{:url("admin/sort")}?id=' + id + '&sort=' + val;
             // let url = 'http:www.baidu.com';
-            layObj.get(url,function (res) {
+            layObj.get(url, function (res) {
                 console.log(res, 'sort');
             })
 

+ 17 - 1
app/common/business/Category.php

@@ -50,9 +50,25 @@ class Category
         $field = "id, name, pid";
         $categorys = $this->categoryObj->getNormalCategory($field);
         if (!$categorys) {
-            $categorys = [];
+            return [];
         }
         $categorys = $categorys->toArray();
         return $categorys;
     }
+
+    /**
+     * 分页获取分类列表
+     * @param $data
+     * @param $num
+     * @return array
+     * @throws \think\db\exception\DbException
+     */
+    public function getLists($data, $num)
+    {
+        $list = $this->categoryObj->getLists($data, $num);
+        if (!$list) {
+            return [];
+        }
+        return $list->toArray();
+    }
 }

+ 19 - 0
app/common/model/mysql/Category.php

@@ -30,4 +30,23 @@ class Category extends Model
 
         return $this->where($where)->field($field)->select();
     }
+
+    /**
+     * 分页获取未删除的分类列表
+     * @param $where
+     * @param int $num
+     * @return \think\Paginator
+     * @throws \think\db\exception\DbException
+     */
+    public function getLists($where, $num = 10)
+    {
+        $order = [
+            'listorder' => 'desc',
+            'id' => 'desc',
+        ];
+        return $this->where('status', '<>', config('status.mysql.table_delete'))
+            ->where($where)
+            ->order($order)
+            ->paginate($num);
+    }
 }