添加测试环境和正式环境适配,添加导航栏状态保留

deploy
a74589669 2019-10-01 21:40:21 +08:00
parent d3093bd472
commit 53449ff655
8 changed files with 65 additions and 17 deletions

View File

@ -38,5 +38,6 @@ class Config
* @var boolean
*/
const SHOW_ERRORS = true;
static public $DEBUG = false;
}

View File

@ -6,7 +6,7 @@ use App\Models;
use Core\Controller;
use Core\View;
use Parsedown;
use App\Config;
class Blog extends Controller
{
function indexAction(){
@ -17,26 +17,40 @@ class Blog extends Controller
$obj['title'] = $value['title'];
$obj['id'] = $value['id'];
$obj['content'] = $value['content'];
$obj['type'] = $value['type'];
//数据加工
$markdown = new Parsedown;
$content = $markdown->text($value['content']);
$obj['content'] = $content;
array_push($docs,$obj);
}
View::renderTemplate("/blog/basic.html",['docs'=>$docs,'index'=>true]);
if(\App\Config::$DEBUG)
View::renderTemplate("/blog/basic.html",['docs'=>$docs,'index'=>true,'debug'=>true]);
else{
View::renderTemplate("/blog/basic.html",['docs'=>$docs,'index'=>true,'debug'=>false]);
}
}
function articleAction(){
if(sizeof($this->querys) != 0){
echo '<pre>';
print_r( rawurldecode( $this->querys['title'])); //将字符串的编码从GB2312转到UTF-8($this->querys['title']);
$docModel = new Models\Doc();
$doc = $docModel->titleDoc(rawurldecode( $this->querys['title']));
$markdown = new Parsedown;
$content = $markdown->text($doc[0]['content']);
echo '</pre>';
if(\App\Config::$DEBUG)
View::renderTemplate("/blog/basic.html",['title'=>rawurldecode( $this->querys['title']),
'index'=>false,
'content'=>$content]);
'content'=>$content,
'type' => $this->querys['type'],
'debug' => true,
]);
else
View::renderTemplate("/blog/basic.html",['title'=>rawurldecode( $this->querys['title']),
'index'=>false,
'content'=>$content,
'type' => $this->querys['type']]);
}else{
View::renderTemplate("/blog/basic.html",['title'=>'test','index'=>false]);
}

View File

@ -37,7 +37,7 @@ class Doc extends Model
$result = [];
if(is_integer($id)){
$db = static::getDB();
$stmt = $db->query('select id,title from doc where type = '.$id);
$stmt = $db->query('select id,title,type from doc where type = '.$id);
$recv = $stmt->fetchAll();
foreach ($recv as $key => $value){
$s['id']= $value['id'];

View File

@ -103,9 +103,15 @@
<div style="display: inline;float: right">这是一个纯手敲出来的博客</div>
<div id="sidebar">
<ul style="padding-left: 0px">
{% if debug == true %}
<li><a href="/api/public/Blog/index">文章</a></li>
{%else%}
<li><a href="/wapi/Blog/index">文章</a></li>
{% endif %}
<li>项目</li>
<li>杂文</li>
<li>赞助</li>
</ul>
</div>
</div>
@ -126,7 +132,11 @@
<div style="width: 660px; height: 160px; border-bottom: #0b58a2 solid 2px ;margin: 5px 5px 5px 0px; overflow:hidden;padding-bottom: 4px;">
<div class="title" style="font-size: 12px;font-weight: bold">
<p style="display: inline;margin-left: 5px;">2019-08-04 </p>
<p style="display: inline;margin-left: 5px;"><a href="/wapi/Blog/article?title={{doc.title}}">{{doc.title}}</a></p>
{% if debug == true %}
<p style="display: inline;margin-left: 5px;"><a href="/api/public/Blog/article?title={{doc.title}}&type={{doc.type}}">{{doc.title}}</a></p>
{%else%}
<p style="display: inline;margin-left: 5px;"><a href="/wapi/Blog/article?title={{doc.title}}&type={{doc.type}}">{{doc.title}}</a></p>
{% endif %}
<p style="display: inline;margin:0px;float: right; margin-right: 20px">管理員</p>
</div>
<div style="width: 600px;height: 140px;font-size: 10px;margin-top: 10px;">
@ -149,6 +159,14 @@
{% endif %}
</div>
</div>
<script type="text/javascript" async>
setTimeout( function(){
console.log($("#doc_tyoe_{{type}}").innerText);
$("#doc_type_{{type}}").addClass("active");
$("#doc_type_{{type}}").find('ul.subMenu').slideDown();
console.log({{type}});
},400);
</script>
<div id="footer">
<p style="font-size: 5px;margin: auto;width: 250px;text-align: center">个人网站,备案号: 闽ICP备19002644号-1</p>
<p style="font-size: 5px;margin: auto;width: 150px;text-align: center">testingcloud.club</p>

View File

View File

@ -1,4 +1,4 @@
var baseUrl = 'http://127.0.0.1/api/public/';
function updateMenu(){
//初始化
$('.subMenu').hide();
@ -37,6 +37,13 @@ $(function() {
});
$(document).ready(
function () {
var domain = window.location.host;
console.log(domain);
if(domain === '127.0.0.1'){
console.log("debug mode");
}else{
baseUrl = "https://www.testingcloud.club/wapi/";
}
htmlobj = $.ajax({
method: "POST",
url: "https://www.testingcloud.club/wapi/Doc/docType",
@ -77,11 +84,12 @@ $(document).ready(
// console.log("#type_id_0 li a #" + rand);
$("#" + rand).on("click",(function () {
console.log($("#" + rand).html());
$(location).attr('href', "https://www.testingcloud.club/wapi/Blog/article?title=" + $("#" + rand).html());
$(location).attr('href', baseUrl + "Blog/article?title=" + $("#" + rand).html() + "&type=" + key);
}));
})
}
console.log("加载完毕");
}
}
);
@ -90,9 +98,10 @@ $(document).ready(
}
})
updateMenu();
console.log("注射样式");
var i = 0;
//var type = $.query.get('type');
// 注射样式
$("#right").style.overflow = "scroll";
}
);

View File

@ -38,10 +38,13 @@ abstract class Controller
}
preg_match("/^.{0,}\?(.{0,})$/i", $_SERVER['REQUEST_URI'], $matches);
if(sizeof($matches) > 0){
$pieces = explode("=", $matches['1']);
for ($i = 0;$i < sizeof($pieces) /2 ;$i++){
$this->querys[$pieces[2*$i]] = $pieces[2*$i + 1];
$pieces = explode("&", $matches['1']);
foreach ($pieces as $key => $value) {
$piece = explode("=", $value);
$this->querys[$piece[0]] = $piece[1];
}
}
$this->route_params = $route_params;
}

View File

@ -23,10 +23,13 @@ $router = new Core\Router();
$router->add('', ['controller' => 'Home', 'action' => 'index']);
$router->add('{controller}/{action}');
$router->add('{controller}/{action}/{id:.+}');
if($_SERVER['HTTP_HOST'] == '127.0.0.1')
if($_SERVER['HTTP_HOST'] == '127.0.0.1'){
$router->AddPrefix(\App\Config::ROUTE_PREFIX_DEV);
else
\App\Config::$DEBUG = true;
}
else{
$router->AddPrefix(\App\Config::ROUTE_PREFIX);
}
try{
//for prefight request