huwhois преди 2 години
родител
ревизия
bc340d96a8

+ 13 - 0
app/common/model/Category.php

@@ -47,4 +47,17 @@ class Category extends Base
         return self::where($where)->field("id,parent_id,name,url,route,tablename,template,type,is_nav,remark,sort,title,keywords,
             description,is_blank,create_time,update_time")->order($order)->select();
     }
+
+    // 导航状态修改 1,显示; 0,不显示
+    public static function navStaus(int $id)
+    {
+        try {
+            $info         = self::find($id);
+            $info->is_nav = 1 - $info['is_nav'];
+            $info->save();
+            return json(['code' => 0, 'msg' => '修改成功!', 'is_nav'=>$info->is_nav]);
+        } catch (\Exception $e) {
+            return json(['code' => 1, 'msg' => $e->getMessage()]);
+        }
+    }
 }

+ 0 - 1
app/sys/controller/Base.php

@@ -17,7 +17,6 @@ namespace app\sys\controller;
 use think\App;
 use think\exception\HttpResponseException;
 use think\exception\ValidateException;
-use think\facade\Cache;
 use think\facade\Config;
 use think\facade\Request;
 use think\facade\Session;

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

@@ -88,7 +88,19 @@ class Category extends Base
                 return ['code' => 0, 'msg' => '子栏目不为空, 若要删除请先清空子栏目'];
             }
 
-            return CategoryModel::del($id);
+            if (CategoryModel::destroy($id)) {
+                return ['code' => 0,'msg'=>'删除成功'];
+            } else {
+                return ['code' => 1,'msg'=>'删除失败'];
+            }
+        }
+    }
+
+    // 导航状态变更
+    public function navStatus(int $id)
+    {
+        if ($this->app->request->isPost()) {
+            return CategoryModel::navStaus($id);
         }
     }
 }

+ 0 - 3
app/sys/controller/Login.php

@@ -13,8 +13,6 @@ use think\facade\View;
 
 use app\common\model\SysUser;
 
-use think\facade\Cache;
-
 class Login
 {
     // 登录页面
@@ -38,7 +36,6 @@ class Login
 
     // 退出登录
     public function logout(){
-        Cache::clear();
         Session::delete('adminuser');
         return redirect((string) url('login/index'));
     }

+ 0 - 1
app/sys/controller/SysMenu.php

@@ -49,7 +49,6 @@ class SysMenu extends Base
                     ]);
                 }
                 // 删除菜单目录缓存
-                \think\Facade\Cache::set('menus', null);
             } catch (\Exception $e) {
                 $msg = $e->getMessage();
 

+ 1 - 7
app/sys/middleware/Admin.php

@@ -10,7 +10,6 @@ namespace app\sys\middleware;
 
 use think\facade\Config;
 use think\facade\Session;
-use think\facade\Cache;
 use think\Response;
 use think\exception\HttpResponseException;
 use think\facade\Request;
@@ -69,12 +68,7 @@ class Admin
             return true;
         }
 
-        $menus = Cache::get('menus');
-        if (!$menus) {
-            $menus = \app\common\model\SysMenu::getUserMenuList($rid);
-
-            Cache::set('menus', $menus);
-        }
+        $menus = \app\common\model\SysMenu::getUserMenuList($rid);
 
         if (!Config::get('app.auth_on')) {
             return true;

+ 20 - 0
public/static/sys/js/admin.js

@@ -259,4 +259,24 @@ $(function () {
             }
         }, 'json');
     });
+
+    // 排序
+    $(".input-sort").change(function () {
+        var sort = $(this).val();
+        var id = $(this).data('id');
+
+        console.log(id);
+        console.log(sort);
+        $.post('sort', {
+            'id': id,
+            'sort': sort
+        }, function (res) {
+            if (res.code == 0) {
+                topalert({ type: 0, content: res.msg, speed: 2000 });
+            } else {
+                topalert({ type: 1, content: res.msg, speed: 2000 });
+                return false;
+            }
+        }, 'json');
+    });
 });

+ 2 - 2
view/index/index/index.html

@@ -1,9 +1,9 @@
 <div class="box">
   <!-- PHP -->
   <div class="newsbox f_l ">
-    <div class="newstitle"><span><a href="/php.html">+</a></span><b>PHP</b></div>
+    <div class="newstitle"><span><a href="/back.html">+</a></span><b>WEB后端</b></div>
     <ul class="newsli">
-      {tp:listbycid cid="1" name="val" limit="7"}
+      {tp:listbycid cid="2" name="val" limit="7"}
       <li><a href="/{$val.create_time|date='Y/m-d'}/{$val.id}.html" title="{$val.title}">{$val.title}</a></li>
       {/tp:listbycid}
     </ul>

+ 1 - 1
view/index/layout.html

@@ -13,7 +13,7 @@
 
 <body>
   <header>
-    <div class="logo"><a href="{:url('/index')}">huwhois个人博客</a></div>
+    <div class="logo"><a href="{:url('/index')}">huwhois的自留地</a></div>
     <nav>
       <ul id="starlist">
         <li><a href="{:url('/index')}">网站首页</a></li>

+ 1 - 1
view/sys/article/index.html

@@ -83,7 +83,7 @@
         </table>
     </div>
     <div class="cl pd-5 bg-1 bk-gray mt-20 ">
-        <span class="r">{$list->render()}</span>
+        <span class="r">{$list->render()|raw}</span>
     </div>
 </article>
 <script>

+ 43 - 25
view/sys/category/index.html

@@ -1,8 +1,8 @@
 <article class="cl pd-20">
     <div class="cl pd-5 bg-1 bk-gray">
         <span class="l">
-            <a href="javascript:;" onclick="del_all()" class="btn btn-danger radius">
-                <i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
+            <!-- <a href="javascript:;" onclick="del_all()" class="btn btn-danger radius">
+                <i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a> -->
             <a class="btn btn-primary radius" href="javascript:save(0);">
                 <i class="Hui-iconfont">&#xe600;</i> 添加栏目</a>
         </span>
@@ -14,10 +14,10 @@
                     <th width="60px">ID</th>
                     <th>栏目名称</th>
                     <th>url</th>
-                    <th>模型名</th>
-                    <th>列表模板</th>
+                    <!-- <th>模型名</th>
+                    <th>列表模板</th> -->
                     <th>导航状态</th>
-                    <th style="width: 80px;">排序</th>
+                    <th style="width: 100px;">排序</th>
                     <th>类型</th>
                     <th>添加时间</th>
                     <th>更新时间</th>
@@ -30,9 +30,13 @@
                     <td>{$value.id}</td>
                     <td>{$value.name}</td>
                     <td>{$value.url}</td>
-                    <td>{$value.tablename}</td>
-                    <td>{$value.template}</td>
-                    <td>{$value.is_nav}</td>
+                    <!-- <td>{$value.tablename}</td>
+                    <td>{$value.template}</td> -->
+                    <td class="td-status-nav">
+                        <div class="switch size-S" data-on-label="是" data-off-label="否" data-id="{$value.id}">
+                            <input type="checkbox" {if $value.is_nav==1}checked{/if}>
+                        </div>
+                    </td>
                     <td><input type="text" class="input-text input-sort" value="{$value.sort}" data-id="{$value.id}"
                         style="text-align: center;"></td>
                     <td>{$types[$value['type']]}</td>
@@ -50,9 +54,13 @@
                     <td>{$val.id}</td>
                     <td>{$val.name}</td>
                     <td>{$val.url}</td>
-                    <td>{$val.tablename}</td>
-                    <td>{$val.template}</td>
-                    <td>{$val.is_nav}</td>
+                    <!-- <td>{$val.tablename}</td>
+                    <td>{$val.template}</td> -->
+                    <td class="td-status-nav">
+                        <div class="switch size-S" data-on-label="是" data-off-label="否" data-id="{$val.id}">
+                            <input type="checkbox" {if $val.is_nav==1}checked{/if}>
+                        </div>
+                    </td>
                     <td><input type="text" class="input-text input-sort" value="{$val.sort}" data-id="{$val.id}"
                         style="text-align: center;"></td>
                     <td>{$types[$val['type']]}</td>
@@ -70,9 +78,13 @@
                     <td>{$vo.id}</td>
                     <td>{$vo.name}</td>
                     <td>{$vo.url}</td>
-                    <td>{$vo.tablename}</td>
-                    <td>{$vo.template}</td>
-                    <td>{$vo.is_nav}</td>
+                    <!-- <td>{$vo.tablename}</td>
+                    <td>{$vo.template}</td> -->
+                    <td class="td-status-nav">
+                        <div class="switch size-S" data-on-label="是" data-off-label="否" data-id="{$vo.id}">
+                            <input type="checkbox" {if $vo.is_nav==1}checked{/if}>
+                        </div>
+                    </td>
                     <td><input type="text" class="input-text input-sort" value="{$vo.sort}" data-id="{$val.id}"
                         style="text-align: center;"></td>
                     <td>{$types[$vo['type']]}</td>
@@ -99,21 +111,27 @@
         layer_show(title, url, 800, 600);
     }
 
-    // 排序
-    $(".input-sort").change(function () {
-        var sort = $(this).val();
+    // 改变状态
+    $('.td-status-nav .switch').on('switch-change', function () {
         var id = $(this).data('id');
 
-        console.log(id);
-        console.log(sort);
-        $.post('sort', {
-            'id': id,
-            'sort': sort
-        }, function (res) {
+        var data = {
+            'id': parseInt(id)
+        };
+
+        $.post('navStatus', data, function (res) {
             if (res.code == 0) {
-                topalert({ type: 0, content: res.msg, speed: 2000 });
+                topalert({
+                    type: 0,
+                    content: res.msg,
+                    speed: 1000
+                });
             } else {
-                topalert({ type: 1, content: res.msg, speed: 2000 });
+                topalert({
+                    type: 1,
+                    content: res.msg,
+                    speed: 1000
+                });
                 return false;
             }
         }, 'json');

+ 1 - 1
view/sys/public/header.html

@@ -8,7 +8,7 @@
                 <ul class="cl">
                     <li style="position: absolute;left: 200px;">
                         <a href="javascript:;"><i class="Hui-iconfont">&#xe67f;</i> 主菜单 </a>
-                        <a href="javascript:;"><i class="Hui-iconfont">&#xe621;</i> 内容管理 </a>
+                        <!-- <a href="javascript:;"><i class="Hui-iconfont">&#xe621;</i> 内容管理 </a> -->
                     </li>
                 </ul>
             </nav>