Bladeren bron

路由调整,开启快速访问

huwhois 3 jaren geleden
bovenliggende
commit
e6f04fe421

+ 1 - 1
app/common/model/Article.php

@@ -38,7 +38,7 @@ class Article extends Base
 
     public function category()
     {
-        return $this->belongsTo('Category', 'cid')->bind(['category_name' => 'name', 'category_url' => 'url']);
+        return $this->belongsTo('Category', 'cid')->bind(['category_name' => 'name', 'category_url' => 'url', 'route' => 'route']);
     }
 
     public static function queryPage($params)

+ 0 - 6
app/index/controller/Article.php

@@ -94,9 +94,6 @@ class Article extends Base
         View::assign('seo',  $this->seo);
 
         $html = View::fetch();
-        if ($this->html) {
-            $this->makeHtmlFile($html);
-        }
 
         return $html;
     }
@@ -199,9 +196,6 @@ class Article extends Base
         ]);
 
         $html = View::fetch();
-        if ($this->html) {
-            $this->makeHtmlFile($html);
-        }
 
         return $html;
     }

+ 0 - 29
app/index/controller/Base.php

@@ -109,33 +109,4 @@ abstract class Base
             'last_lists' => $last_lists,
         ]);
     }
-
-    protected  function makeHtmlFile($html)
-    {
-        $basepath = $this->app->getRootPath() . 'public';
-
-        $url = $this->request->baseUrl();
-
-        if (substr($url, -1) === '/') {
-            $url .= 'index.html';
-        }
-
-        if (empty(pathinfo($url, PATHINFO_EXTENSION))) {
-            $url .= '.html';
-        }
-        
-        $filename = $basepath . $url;
-        
-        $force = $this->request->has('force') ? (boolean) $this->request->param('force') : false;
-        
-        if (!file_exists($filename) || filectime($filename) <= time()-60*60*24*5 || $force == true) {
-            $dir = dirname($filename);
-            if (!file_exists($dir) ) {
-                mkdir($dir, 0755, true);
-                @file_put_contents($dir.'/index.html', "");  // 添加空html文件
-            }
-
-            @file_put_contents($filename, $html);
-        }
-    }
 }

+ 1 - 9
app/index/controller/Index.php

@@ -14,8 +14,6 @@ use think\Request;
 use app\index\controller\Base;
 use app\common\model\Article;
 use app\common\model\GuestBook;
-use app\common\service\MakeHtmkFile;
-use think\facade\Config;
 
 class Index extends Base
 {
@@ -41,10 +39,7 @@ class Index extends Base
         ]);
 
         $html = View::fetch();
-        if ($this->html) {
-            $this->makeHtmlFile($html);
-        }
-
+        
         return $html;
     }
 
@@ -54,9 +49,6 @@ class Index extends Base
     public function about()
     {
         $html = View::fetch();
-        if ($this->html) {
-            $this->makeHtmlFile($html);
-        }
 
         return $html;
     }

+ 0 - 4
app/index/route/app.php

@@ -22,10 +22,6 @@ Route::pattern([
     'day' => '\d+',
 ]); 
 
-Route::get('think', function () {
-    return 'hello,ThinkPHP6!';
-});
-
 Route::get('/index', 'index/index/index');
 Route::get('/', 'index/index/index');
 Route::view('/404', '404');

+ 31 - 9
app/sys/controller/Index.php

@@ -1,5 +1,6 @@
 <?php
-declare (strict_types = 1);
+
+declare(strict_types=1);
 
 namespace app\sys\controller;
 
@@ -41,10 +42,10 @@ class Index  extends Base
     private function getIndexTips()
     {
         $user = $this->getSysUser();
-        
+
         $defaultPassword = Config::get('app.default_password') ?: 'admin';
 
-        if ($user->password == md5($defaultPassword.$user->salt)) {
+        if ($user->password == md5($defaultPassword . $user->salt)) {
             return '<h6 class="mb-0"><i class="icon fas fa-fw fa-exclamation-triangle"></i> 请尽快修改后台初始密码!</h6>';
         }
         return '';
@@ -54,10 +55,10 @@ class Index  extends Base
     {
         if ($this->request->isAjax()) {
             $dirname = $this->app->getRootPath();
-            
+
             $dirsize = get_dir_size($dirname);
-            
-            return ['code'=>0, 'size'=>format_bytes($dirsize)];
+
+            return ['code' => 0, 'size' => format_bytes($dirsize)];
         }
     }
 
@@ -65,7 +66,7 @@ class Index  extends Base
     {
         if ($this->request->isAjax()) {
             $runtime_path = $this->app->getRootPath() . 'runtime' . DIRECTORY_SEPARATOR;
-            
+
             try {
                 $cache_dir = $runtime_path . 'cache' . DIRECTORY_SEPARATOR;
                 $admin_dir = $runtime_path . 'admin' . DIRECTORY_SEPARATOR;
@@ -77,9 +78,30 @@ class Index  extends Base
                 deldir($index_dir);
                 deldir($api_dir);
             } catch (\Exception $e) {
-                return ['code'=>0, 'msg'=>$e->getMessage()];
+                return ['code' => 0, 'msg' => $e->getMessage()];
             }
-            return ['code'=>1, 'msg'=>'清除成功'];
+            return ['code' => 1, 'msg' => '清除成功'];
         }
     }
+    // 刷新栏目页
+    // public function reClass($classid)
+    // {
+    //     $classess = Enewsclass::with('module')->field("classid, bclassid,classname,modid,classpath,islast,islist,listtempid,classurl")->order('classid desc')->select();
+
+    //     $publicpath = app()->getRootPath() . 'public/';
+
+    //     foreach ($classess as $key => $class) {
+    //         if ($class->islast == 1) {   // 列表模板, 其他的再说
+    //             $model = "\app\common\model\\" . $class->modelName;
+    //             $path = $publicpath . $class->classpath;
+    //             if (!file_exists($path)) {
+    //                 mkdir($path, 0755, true);
+    //             }
+
+    //             $listpage = 25; // 每页25条
+
+    //             // $total = 
+    //         }
+    //     }
+    // }
 }

+ 4 - 1
config/app.php

@@ -14,7 +14,10 @@ return [
     'default_app'      => 'index',
     // 默认时区
     'default_timezone' => 'Asia/Shanghai',
-
+    // 开启多应用
+    'auto_multi_app'   => true,
+    // 开启快速访问
+    'app_express'      => true,
     // 应用映射(自动多应用模式有效)
     'app_map'          => [],
     // 域名绑定(自动多应用模式有效)

+ 2 - 1
public/.gitignore

@@ -1,3 +1,4 @@
 # 静态文件
 /index
-index.html
+index.html
+/html

+ 4 - 4
view/index/article/archive.html

@@ -6,7 +6,7 @@
   <div class="blogs">
     {foreach $list as $val}
     <div class="bloglist">
-      <h2><a href="/index/{$val.create_time|date='Y/m-d'}/{$val.id}.html" title="{$val.title}">{$val.title}</a></h2>
+      <h2><a href="/{$val.create_time|date='Y/m-d'}/{$val.id}.html" title="{$val.title}">{$val.title}</a></h2>
       <div class="bloginfo">
         <ul>
           <li class="author"><a href="{:url($val.category_url)}"> {$val.category_name} </a></li>
@@ -19,11 +19,11 @@
     </div>
     {/foreach}
     <div class="pagelist">
-      {if $page > 1} <a href="/index/{:str_replace('-','/',$yearMonth)}-{$page-1}.html">«</a> {/if}
+      {if $page > 1} <a href="/{:str_replace('-','/',$yearMonth)}-{$page-1}.html">«</a> {/if}
       {for start="1" end="$lastPage+1"}
-      {if $page == $i} <b>{$i}</b>&nbsp; {else /} <a href="/index/{:str_replace('-','/',$yearMonth)}-{$i}.html">{$i}</a>&nbsp; {/if}
+      {if $page == $i} <b>{$i}</b>&nbsp; {else /} <a href="/{:str_replace('-','/',$yearMonth)}-{$i}.html">{$i}</a>&nbsp; {/if}
       {/for}
-      {if $page < $lastPage} <a href="/index/{:str_replace('-','/',$yearMonth)}-{$page+1}.html">»</a> {/if}
+      {if $page < $lastPage} <a href="/{:str_replace('-','/',$yearMonth)}-{$page+1}.html">»</a> {/if}
     </div>
   </div>
   {include file="aside"}

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

@@ -1,6 +1,6 @@
 <div class="box">
   <div class="place">
-    <a href="/index/all.html" class="{$cid==0 ? 'current_category': ''}">All</a>
+    <a href="/all.html" class="{$cid==0 ? 'current_category': ''}">All</a>
     {foreach $cate_lists as $value}
     <a href="{$value.url}.html" class="{$cid==$value.id ? 'current_category': ''}">{$value.name}</a>
     {/foreach}
@@ -9,7 +9,7 @@
   <div class="blogs">
     {foreach $list as $val}
     <div class="bloglist">
-      <h2><a href="/index/{$val.create_time|date='Y/m-d'}/{$val.id}.html" title="{$val.title}">{$val.title}</a></h2>
+      <h2><a href="/{$val.create_time|date='Y/m-d'}/{$val.id}.html" title="{$val.title}">{$val.title}</a></h2>
       <div class="bloginfo">
         <ul>
           <li class="author"><a href="{$val.category_url}.html"> {$val.category_name} </a></li>

+ 7 - 5
view/index/article/read.html

@@ -14,10 +14,12 @@
         </ul>
       </div>
       <div class="tags">
+        {if $data->keywords != ""}
         {php}$tags = explode(',',$data->keywords);{/php}
         {foreach $tags as $value}
-        <a href="/index/tags/{$value}"  rel="tag" data-wpel-link="internal">{$value}</a> &nbsp;
+        <a href="/tags/{$value}"  rel="tag" data-wpel-link="internal">{$value}</a> &nbsp;
         {/foreach}
+        {/if}
       </div>
       <div class="news_about"><strong>简介</strong>{$data.summary}</div>
       <div class="news_con" id="preview">
@@ -29,13 +31,13 @@
       {empty name="prev_next.prev"}
       <p>上一篇:<a >没有了</a></p>
       {else}
-      <p>上一篇:<a href="/index/{$prev_next['prev']['create_time']|date='Y/m-d'}/{$prev_next['prev']['id']}" title="{$prev_next.prev.title}">{$prev_next.prev.title}</a></p>
+      <p>上一篇:<a href="/{$prev_next['prev']['create_time']|date='Y/m-d'}/{$prev_next['prev']['id']}" title="{$prev_next.prev.title}">{$prev_next.prev.title}</a></p>
       {/empty}
       {empty name="prev_next.next"}
-      <p>下一篇:<a href="{$data.category_url}">返回列表</a></p>
+      <p>下一篇:<a href="{:url($data.route)}">返回列表</a></p>
       {else}
       <p>下一篇:<a
-          href="/index/{$prev_next['next']['create_time']|date='Y/m-d'}/{$prev_next['next']['id']}"
+          href="/{$prev_next['next']['create_time']|date='Y/m-d'}/{$prev_next['next']['id']}"
           title="{$prev_next.next.title}">{$prev_next.next.title}</a></p>
       {/empty}
     </div>
@@ -68,7 +70,7 @@
 
   function getLike(id) {
     var num = parseInt($('#diggnum').text());
-    $.post('/index/dolike', {
+    $.post('/dolike', {
       'id': id
     }, function (res) {
       if (res.code==0) {

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

@@ -6,10 +6,10 @@
   <div class="blogs">
     {foreach $list as $val}
     <div class="bloglist">
-      <h2><a href="/index/{$val.create_time|date='Y/m-d'}/{$val.id}.html" title="{$val.title}">{$val.title}</a></h2>
+      <h2><a href="/{$val.create_time|date='Y/m-d'}/{$val.id}.html" title="{$val.title}">{$val.title}</a></h2>
       <div class="bloginfo">
         <ul>
-          <li class="author"><a href="/index/{$val.category_url}"> {$val.category_name} </a></li>
+          <li class="author"><a href="/{$val.route}"> {$val.category_name} </a></li>
           <li class="timer">{$val.create_time}</li>
           <li class="view">{$val.hits} 已阅读</li>
           <li class="like">{$val.likes}</li>

+ 4 - 4
view/index/article/time.html

@@ -2,16 +2,16 @@
   <div class="timebox">
     <ul>
       {foreach $list as $val}
-      <li><span>{$val.create_time|date="Y-m-d"}</span><i><a href="/index/{$val.create_time|date='Y/m-d'}/{$val.id}"
+      <li><span>{$val.create_time|date="Y-m-d"}</span><i><a href="/{$val.create_time|date='Y/m-d'}/{$val.id}"
             title="{$val.title}">{$val.title}</a></i></li>
       {/foreach}
     </ul>
   </div>
   <div class="pagelist">
-    {if $page > 1} <a href="/index/time-{$page-1}.html">«</a> {/if}
+    {if $page > 1} <a href="/time-{$page-1}.html">«</a> {/if}
     {for start="1" end="$lastPage+1"}
-    {if $page == $i} <b>{$i}</b>&nbsp; {else /} <a href="/index/time-{$i}.html">{$i}</a>&nbsp; {/if}
+    {if $page == $i} <b>{$i}</b>&nbsp; {else /} <a href="/time-{$i}.html">{$i}</a>&nbsp; {/if}
     {/for}
-    {if $page < $lastPage} <a href="/index/time-{$page+1}.html">»</a> {/if}
+    {if $page < $lastPage} <a href="/time-{$page+1}.html">»</a> {/if}
   </div>
 </article>

+ 2 - 2
view/index/aside.html

@@ -24,7 +24,7 @@
     <h2>博文推荐</h2>
     <ul>
       {foreach $top_lists as $value}
-      <li><a href="/index/{$value.create_time|date='Y/m-d'}/{$value.id}.html" title="{$value.title}">{$value.title}</a></li>
+      <li><a href="/{$value.create_time|date='Y/m-d'}/{$value.id}.html" title="{$value.title}">{$value.title}</a></li>
       {/foreach}
     </ul>
   </div>
@@ -32,7 +32,7 @@
     <h2>归档</h2>
     <ul>
       {foreach $time_lists as $value}
-      <li><a href="/index/{:str_replace('-','/',$value)}" title="{$value}">{:str_replace('-','年',$value)}月</a></li>
+      <li><a href="/{:str_replace('-','/',$value)}" title="{$value}">{:str_replace('-','年',$value)}月</a></li>
       {/foreach}
     </ul>
   </div>

+ 9 - 9
view/index/index/index.html

@@ -1,19 +1,19 @@
 <div class="box">
   <!-- PHP -->
   <div class="newsbox f_l ">
-    <div class="newstitle"><span><a href="/index/php.html">+</a></span><b>PHP</b></div>
+    <div class="newstitle"><span><a href="/php.html">+</a></span><b>PHP</b></div>
     <ul class="newsli">
       {foreach $php_data as $val}
-      <li><a href="/index/{$val.create_time|date='Y/m-d'}/{$val.id}.html" title="{$val.title}">{$val.title}</a></li>
+      <li><a href="/{$val.create_time|date='Y/m-d'}/{$val.id}.html" title="{$val.title}">{$val.title}</a></li>
       {/foreach}
     </ul>
   </div>
   <!-- notes_data -->
   <div class="newsbox f_r ">
-    <div class="newstitle"><span><a href="/index/all.html">+</a></span><b>其他</b></div>
+    <div class="newstitle"><span><a href="/all.html">+</a></span><b>其他</b></div>
     <ul class="newsli">
       {foreach $other_data as $val}
-      <li><a href="/index/{$val.create_time|date='Y/m-d'}/{$val.id}.html" title="{$val.title}">{$val.title}</a></li>
+      <li><a href="/{$val.create_time|date='Y/m-d'}/{$val.id}.html" title="{$val.title}">{$val.title}</a></li>
       {/foreach}
     </ul>
   </div>
@@ -21,7 +21,7 @@
   <!-- top -->
   {foreach $top_data as  $key=> $val}
   <div class="sbox  {switch name='key'}{case value='1'}f_l ml{/case}{case value='2'}f_r{/case}{default /}f_l{/switch}"> <span>{$val.category_name}</span>
-    <h2><a href="/index/{$val.create_time|date='Y/m-d'}/{$val.id}.html" title="{$val.title}">{$val.title}</a></h2>
+    <h2><a href="/{$val.create_time|date='Y/m-d'}/{$val.id}.html" title="{$val.title}">{$val.title}</a></h2>
     <p>{$val.summary}</p>
   </div>
   {/foreach}
@@ -30,7 +30,7 @@
   <div class="blogs">
     {foreach $all_data as $val}
     <div class="bloglist">
-      <h2><a href="/index/{$val.create_time|date='Y/m-d'}/{$val.id}.html" title="{$val.title}">{$val.title}</a></h2>
+      <h2><a href="/{$val.create_time|date='Y/m-d'}/{$val.id}.html" title="{$val.title}">{$val.title}</a></h2>
       <div class="bloginfo">
         <ul>
           <li class="author"><a href="/{$val.category_url}.html"> {$val.category_name} </a></li>
@@ -55,7 +55,7 @@
       <h2>点击排行</h2>
       <ul>
         {foreach $hits_lists as $value}
-        <li><a href="/index/{$value.create_time|date='Y/m-d'}/{$value.id}.html" title="{$value.title}">{$value.title}</a></li>
+        <li><a href="/{$value.create_time|date='Y/m-d'}/{$value.id}.html" title="{$value.title}">{$value.title}</a></li>
         {/foreach}
       </ul>
     </div>
@@ -63,7 +63,7 @@
       <h2>博文推荐</h2>
       <ul>
         {foreach $top_lists as $value}
-        <li><a href="/index/{$value.create_time|date='Y/m-d'}/{$value.id}.html" title="{$value.title}">{$value.title}</a></li>
+        <li><a href="/{$value.create_time|date='Y/m-d'}/{$value.id}.html" title="{$value.title}">{$value.title}</a></li>
         {/foreach}
       </ul>
     </div>
@@ -71,7 +71,7 @@
       <h2>归档</h2>
       <ul>
         {foreach $time_lists as $value}
-        <li><a href="/index/{:str_replace('-','/',$value)}" title="{$value}">{:str_replace('-','年',$value)}月</a></li>
+        <li><a href="/{:str_replace('-','/',$value)}" title="{$value}">{:str_replace('-','年',$value)}月</a></li>
         {/foreach}
       </ul>
     </div>

+ 2 - 2
view/index/layout.html

@@ -1,5 +1,5 @@
 <!doctype html>
-<html>
+<html lang="zh-cn">
 
 <head>
   <meta charset="utf-8">
@@ -18,7 +18,7 @@
       <ul id="starlist">
         <li><a href="{:url('/index')}">网站首页</a></li>
         {foreach $categories as $val}
-        <li><a href="{:url($val.url)}">{$val.name}</a></li>
+        <li><a href="{:url($val.route)}">{$val.name}</a></li>
         {/foreach}
       </ul>
     </nav>

+ 23 - 13
view/sys/index/index.html

@@ -186,7 +186,7 @@
                         </div>
                         <!-- /.card-header -->
                         <div class="card-body">
-                            <a class="btn btn-app" href="javascript:makeHtmlFile('index');">
+                            <a class="btn btn-app" onclick="reIndex();">
                                 <i class="Hui-iconfont">&#xe681;</i>
                                 <span>刷新首页</span>
                             </a>
@@ -227,21 +227,31 @@
         }, 'json');
     }
 
-    function  reflushIndex() {
-        $.get('/?force=true');
-        $.get('/index/index?force=true');
+    function reIndex() {
+        var url = '/index/make_html/reIndex';
+
+        putPost(url, {'force':true});
     }
 
-    function makeHtmlFile(url) {
-        $.post('/sys/index/makehtmlfile',{'url': url}, function (res) {
-            console.log(res);
-            if (res.code == 0) {
-                layer.msg('清除成功', {
-                    icon: 1,
-                    time: 1000
-                });
+    function reClass() {
+        var data = {};
+
+        putPost('reClass', data);
+    }
+
+    function putPost(url, data) {
+        data = data || {}
+        $.post(url, data, function (res) {
+            var icon = 5;
+            if (res.code == 1) {
+                icon = 1;
             }
-        }, 'json');
+            layer.msg(res.msg, {
+                icon: icon,
+                time: 1000
+            });
+        });
     }
+
 </script>
 <!--请在上方写此页面业务相关的脚本-->

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

@@ -19,9 +19,9 @@
                         <span id="top_time"></span>
                     </li>
                     <li>
-                        <a aria-hidden="false" class="logo navbar-logo f-l mr-10 hidden-xs" href="/sys">
+                        <a aria-hidden="false" class="logo navbar-logo f-l mr-10 hidden-xs" href="/sys/index.html">
                             <i class="Hui-iconfont">&#xe625;</i>系统首页</a>
-                        <a aria-hidden="false" class="logo navbar-logo f-l mr-10 hidden-xs" href="/index"
+                        <a aria-hidden="false" class="logo navbar-logo f-l mr-10 hidden-xs" href="/index.html"
                             target="_blank">
                             <i class="Hui-iconfont">&#xe67f;</i>网站首页</a>
                     </li>