mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-06 03:58:00 +08:00
91 lines
2.5 KiB
PHP
91 lines
2.5 KiB
PHP
<?php
|
|
/**
|
|
* 工程基类
|
|
* @since 2017/02/28 创建
|
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
|
*/
|
|
|
|
namespace app\wiki\controller;
|
|
|
|
|
|
use think\Config;
|
|
use think\Controller;
|
|
use think\exception\HttpResponseException;
|
|
use think\Request;
|
|
use think\Response;
|
|
use think\View as ViewTemplate;
|
|
use think\Url;
|
|
|
|
class Base extends Controller {
|
|
|
|
protected $appInfo;
|
|
|
|
public function checkLogin() {
|
|
$appInfo = session('app_info');
|
|
if ($appInfo) {
|
|
$this->appInfo = json_decode($appInfo, true);
|
|
} else {
|
|
$this->redirect(url('/wiki/login'));
|
|
}
|
|
}
|
|
|
|
public function error($msg = '', $url = null, $data = '', $wait = 3, array $header = []) {
|
|
if (is_null($url)) {
|
|
$url = Request::instance()->isAjax() ? '' : 'javascript:history.back(-1);';
|
|
} elseif ('' !== $url && !strpos($url, '://') && 0 !== strpos($url, '/')) {
|
|
$url = Url::build($url);
|
|
}
|
|
|
|
$type = 'html';
|
|
$result = [
|
|
'code' => 0,
|
|
'msg' => $msg,
|
|
'data' => $data,
|
|
'url' => $url,
|
|
'wait' => $wait,
|
|
];
|
|
|
|
if ('html' == strtolower($type)) {
|
|
$template = Config::get('template');
|
|
$view = Config::get('view_replace_str');
|
|
|
|
$result = ViewTemplate::instance($template, $view)
|
|
->fetch(Config::get('dispatch_error_tmpl'), $result);
|
|
}
|
|
|
|
$response = Response::create($result, $type)->header($header);
|
|
|
|
throw new HttpResponseException($response);
|
|
}
|
|
|
|
public function success($msg = '', $url = null, $data = '', $wait = 3, array $header = []) {
|
|
if (is_null($url) && !is_null(Request::instance()->server('HTTP_REFERER'))) {
|
|
$url = Request::instance()->server('HTTP_REFERER');
|
|
} elseif ('' !== $url && !strpos($url, '://') && 0 !== strpos($url, '/')) {
|
|
$url = Url::build($url);
|
|
}
|
|
|
|
$type = 'html';
|
|
$result = [
|
|
'code' => 1,
|
|
'msg' => $msg,
|
|
'data' => $data,
|
|
'url' => $url,
|
|
'wait' => $wait,
|
|
];
|
|
|
|
if ('html' == strtolower($type)) {
|
|
$template = Config::get('template');
|
|
$view = Config::get('view_replace_str');
|
|
|
|
$result = ViewTemplate::instance($template, $view)
|
|
->fetch(Config::get('dispatch_success_tmpl'), $result);
|
|
}
|
|
|
|
$response = Response::create($result, $type)->header($header);
|
|
|
|
throw new HttpResponseException($response);
|
|
}
|
|
|
|
}
|