程序安装引导优化

This commit is contained in:
zhao 2020-02-09 12:19:43 +08:00
parent e309828d42
commit 00a9cbf129
8 changed files with 100 additions and 19 deletions

View File

@ -14,7 +14,7 @@ class Index extends BaseController
*/ */
// 检测是否安装过 // 检测是否安装过
protected function initialize(){ protected function initialize(){
if(is_file('../install.lock')){ if(file_exists('../install.lock')){
echo "<script>alert('已经成功安装了TaoLer社区系统安装系统已锁定。如需重新安装请删除根目录下的install.lock文件')</script>"; echo "<script>alert('已经成功安装了TaoLer社区系统安装系统已锁定。如需重新安装请删除根目录下的install.lock文件')</script>";
die(); die();
} }
@ -38,7 +38,7 @@ class Index extends BaseController
} }
} }
//test //create
public function create(){ public function create(){
if(Session::get('install') == 2){ if(Session::get('install') == 2){
Session::set('install',3); Session::set('install',3);
@ -48,17 +48,18 @@ class Index extends BaseController
} }
} }
// 安装成功页面 // 安装
public function complete(){ public function install(){
if(Session::get('install') != 3){ //if(Session::get('install') != 3){
return redirect('./create.html'); // return redirect('./create.html');
} //}
// 判断是否为post // 判断是否为post
if ($_SERVER['REQUEST_METHOD'] == 'POST') { //if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if(Request::isAjax()){
$data = $_POST; $data = Request::param();
//$data = $_POST;
//var_dump($data); //var_dump($data);
if (!preg_match("/^[a-zA-Z]{1}([0-9a-zA-Z]|[._]){4,19}$/", $data['admin_user'])) { if (!preg_match("/^[a-zA-Z]{1}([0-9a-zA-Z]|[._]){4,19}$/", $data['admin_user'])) {
die("<script>alert('后台管理用户名不符合规范至少包含4个字符需以字母开头');history.go(-1)</script>"); die("<script>alert('后台管理用户名不符合规范至少包含4个字符需以字母开头');history.go(-1)</script>");
@ -194,9 +195,10 @@ php;
//安装上锁 //安装上锁
file_put_contents('../install.lock', 'lock'); file_put_contents('../install.lock', 'lock');
Session::clear(); Session::clear();
return View::fetch('complete'); //return View::fetch('complete');
return json(['code' => 0,'msg'=>'安装成功','url'=>'/install.php/success/complete']);
} else { } else {
return '安装失败'; return '请求失败!';
} }
} }

View File

@ -0,0 +1,14 @@
<?php
namespace app\install\controller;
use app\common\controller\BaseController;
use think\facade\View;
class Success extends BaseController
{
// 安装成功页面
public function complete(){
return View::fetch('complete');
}
}

View File

@ -22,3 +22,6 @@ $response = $http->run();
$response->send(); $response->send();
$http->end($response); $http->end($response);
if(file_exists('../install.lock') != 'true'){
header('Location: http://www.tp6.com/install.php');
}

24
public/install.php Normal file
View File

@ -0,0 +1,24 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2019 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
// [ 应用入口文件 ]
namespace think;
require __DIR__ . '/../vendor/autoload.php';
// 执行HTTP应用并响应
$http = (new App())->http;
$response = $http->run();
$response->send();
$http->end($response);

View File

@ -18,7 +18,7 @@
<a>拒绝安装</a> <a>拒绝安装</a>
</div> </div>
<div class="inout2"> <div class="inout2">
<a href="{:url('install/index/test')}">同意安装</a> <a href="{:url('/index/test')}">同意安装</a>
</div> </div>
</div> </div>
</br> </br>

View File

@ -3,7 +3,7 @@
{block name="body"} {block name="body"}
<div class="inside2"> <div class="inside2">
<div class="inwp cl"> <div class="inwp cl">
<form class="layui-form layui-form-pane" action="/install/index/complete" method="post"> <form class="layui-form layui-form-pane" >
<h2>创建数据库:</h2> <h2>创建数据库:</h2>
<input type="hidden" name="DB_TYPE" value="mysql"> <input type="hidden" name="DB_TYPE" value="mysql">
@ -85,7 +85,7 @@
</div> </div>
</div> </div>
<div class="inout1"> <div class="inout1">
<a href="/install/index/test">上一步</a> <a href="{:url('/index/test')}">上一步</a>
</div> </div>
<div class="inout2"> <div class="inout2">
<input type="submit" lay-submit lay-filter="formDemo" value="确认安装"> <input type="submit" lay-submit lay-filter="formDemo" value="确认安装">
@ -93,7 +93,45 @@
</form> </form>
<script> <script>
layui.use('form', function() { layui.use('form', function() {
var form = layui.form; var $ = layui.jquery,
form = layui.form;
form.on('submit(formDemo)', function(data){
var field = data.field;
//console.log(field); //当前容器的全部表单字段,名值对形式:{name: value}
loading = layer.load(2, {
shade: [0.2, '#000'],
time: 2000,
});
$.ajax({
type:"post",
url:"{:url('/index/install')}",
data:{"DB_TYPE":field.DB_TYPE,"DB_HOST":field.DB_HOST,"DB_USER":field.DB_USER,"DB_PWD":field.DB_PWD,"DB_PORT":field.DB_PORT,"DB_NAME":field.DB_NAME,"DB_PREFIX":field.DB_PREFIX,"webname":field.webname,"webtitle":field.webtitle,"admin_user":field.admin_user,"admin_email":field.admin_email,"admin_pass":field.admin_pass,"admin_pass2":field.admin_pass2},
daType:"json",
success:function (data){
if (data.code == 0) {
layer.close(loading);
layer.msg(data.msg,{
icon:6,
time:2000
}, function(){
location.href = data.url;
});
} else {
layer.open({
tiele:'安装失败',
content:data.msg,
icon:5,
anim:6
});
}
}
});
return false; //阻止表单跳转。如果需要表单跳转,去掉这段即可。
});
}); });
</script> </script>
</div> </div>

View File

@ -85,7 +85,7 @@
</tr> </tr>
</table> </table>
<div class="inout1"> <div class="inout1">
<a href="/install/index/index">上一步</a> <a href="{:url('/index/index')}">上一步</a>
</div> </div>
<div class="inout2"> <div class="inout2">
<a href="javascript:;" onclick="testClick()">下一步</a> <a href="javascript:;" onclick="testClick()">下一步</a>
@ -97,7 +97,7 @@
if ($('.yes').length != 5) { if ($('.yes').length != 5) {
alert('您的配置或权限不符合要求'); alert('您的配置或权限不符合要求');
} else { } else {
location.href = '{:url('install/index/create')}'; location.href = '{:url('/index/create')}';
} }
} }
</script> </script>