diff --git a/app/admin/BaseController.php b/app/admin/BaseController.php index 33c0d38..c8bda54 100644 --- a/app/admin/BaseController.php +++ b/app/admin/BaseController.php @@ -2,7 +2,8 @@ declare(strict_types = 1); namespace app\admin; - +use think\exception\HttpResponseException; +use think\facade\Request; use think\App; /** @@ -53,4 +54,115 @@ abstract class BaseController { $this->param = $this->request->param(); } + + // + // 以下为新增,为了使用旧版的 success error redirect 跳转 start + // + + /** + * 操作成功跳转的快捷方法 + * @access protected + * @param mixed $msg 提示信息 + * @param string $url 跳转的URL地址 + * @param mixed $data 返回的数据 + * @param integer $wait 跳转等待时间 + * @param array $header 发送的Header信息 + * @return void + */ + protected function success($msg = '', string $url = null, $data = '', int $wait = 3, array $header = []) + { + if (is_null($url) && isset($_SERVER["HTTP_REFERER"])) { + $url = $_SERVER["HTTP_REFERER"]; + } elseif ($url) { + $url = (strpos($url, '://') || 0 === strpos($url, '/')) ? $url : app('route')->buildUrl($url); + } + + $result = [ + 'code' => 1, + 'msg' => $msg, + 'data' => $data, + 'url' => $url, + 'wait' => $wait, + ]; + + $type = $this->getResponseType(); + if ($type == 'html'){ + $response = view($this->app->config->get('app.dispatch_success_tmpl'), $result); + } else if ($type == 'json') { + $response = json($result); + } + throw new HttpResponseException($response); + } + + /** + * 操作错误跳转的快捷方法 + * @access protected + * @param mixed $msg 提示信息 + * @param string $url 跳转的URL地址 + * @param mixed $data 返回的数据 + * @param integer $wait 跳转等待时间 + * @param array $header 发送的Header信息 + * @return void + */ + protected function error($msg = '', string $url = null, $data = '', int $wait = 3, array $header = []) + { + if (is_null($url)) { + $url = $this->request->isAjax() ? '' : 'javascript:history.back(-1);'; + } elseif ($url) { + $url = (strpos($url, '://') || 0 === strpos($url, '/')) ? $url : $this->app->route->buildUrl($url); + } + + $result = [ + 'code' => 0, + 'msg' => $msg, + 'data' => $data, + 'url' => $url, + 'wait' => $wait, + ]; + + $type = $this->getResponseType(); + if ($type == 'html'){ + $response = view($this->app->config->get('app.dispatch_error_tmpl'), $result); + } else if ($type == 'json') { + $response = json($result); + } + throw new HttpResponseException($response); + } + + /** + * URL重定向 自带重定向无效 + * @access protected + * @param string $url 跳转的URL表达式 + * @param array|integer $params 其它URL参数 + * @param integer $code http code + * @param array $with 隐式传参 + * @return void + */ + protected function redirect($url, $params = [], $code = 302, $with = []) + { + $response = Response::create($url, 'redirect'); + + if (is_integer($params)) { + $code = $params; + $params = []; + } + + $response->code($code)->params($params)->with($with); + + throw new HttpResponseException($response); + } + + /** + * 获取当前的response 输出类型 + * @access protected + * @return string + */ + protected function getResponseType() + { + return $this->request->isJson() || $this->request->isAjax() ? 'json' : 'html'; + } + + // + // 以上为新增,为了使用旧版的 success error redirect 跳转 end + // } diff --git a/app/admin/controller/Database.php b/app/admin/controller/Database.php index 0dcd121..1653e29 100644 --- a/app/admin/controller/Database.php +++ b/app/admin/controller/Database.php @@ -125,7 +125,7 @@ class Database extends BaseController # 将反斜杠 替换成正斜杠 $file_path = str_replace('\\','/',$file_path); if(!file_exists($file_path)){ - echo "下载文件不存在!";exit; //如果提示这个错误,很可能你的路径不对,可以打印$file_sub_path查看 + $this->error('下载文件不存在!');exit; //如果提示这个错误,很可能你的路径不对,可以打印$file_sub_path查看 } $fp = fopen($file_path,"r"); // 以可读的方式打开这个文件 # 如果出现图片无法打开,可以在这个位置添加函数 diff --git a/app/common.php b/app/common.php index 2858b95..2562362 100644 --- a/app/common.php +++ b/app/common.php @@ -243,3 +243,22 @@ function get_file($id) } return false; } + + +/** + * 判断是否是手机浏览器 + */ +function isMobile() +{ + if (isset($_SERVER['HTTP_VIA']) && stristr($_SERVER['HTTP_VIA'], "wap")) { + return true; + } elseif (isset($_SERVER['HTTP_ACCEPT']) && strpos(strtoupper($_SERVER['HTTP_ACCEPT']), "VND.WAP.WML")) { + return true; + } elseif (isset($_SERVER['HTTP_X_WAP_PROFILE']) || isset($_SERVER['HTTP_PROFILE'])) { + return true; + } elseif (isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/(blackberry|configuration\/cldc|hp |hp-|htc |htc_|htc-|iemobile|kindle|midp|mmp|motorola|mobile|nokia|opera mini|opera |Googlebot-Mobile|YahooSeeker\/M1A1-R2D2|android|iphone|ipod|mobi|palm|palmos|pocket|portalmmm|ppc;|smartphone|sonyericsson|sqh|spv|symbian|treo|up.browser|up.link|vodafone|windows ce|xda |xda_)/i', $_SERVER['HTTP_USER_AGENT'])) { + return true; + } else { + return false; + } +} diff --git a/config/app.php b/config/app.php index 1b689d1..b294366 100644 --- a/config/app.php +++ b/config/app.php @@ -35,4 +35,8 @@ return [ 'session_user' => 'gougu_user', 'session_admin' => 'gougu_admin', + + // 默认跳转页面对应的模板文件【新增】 + 'dispatch_success_tmpl' => app()->getRootPath() . '/public/tpl/dispatch_jump.tpl', + 'dispatch_error_tmpl' => app()->getRootPath() . '/public/tpl/dispatch_jump.tpl', ]; diff --git a/public/tpl/default_index.tpl b/public/tpl/default_index.tpl new file mode 100644 index 0000000..8538b4d --- /dev/null +++ b/public/tpl/default_index.tpl @@ -0,0 +1,10 @@ +*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }
+$value) { ?>
+ | + + | +