mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-09 19:42:47 +08:00
增加response的事件机制;为login增加事件;发布新版本
This commit is contained in:
@@ -36,6 +36,10 @@ class Login extends AdminController
|
|||||||
*/
|
*/
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
|
event_response('AdminLoginIndex', [
|
||||||
|
'controller' => $this,
|
||||||
|
]);
|
||||||
|
|
||||||
$captcha = Env::get('adminsystem.captcha', 1);
|
$captcha = Env::get('adminsystem.captcha', 1);
|
||||||
if ($this->request->isPost()) {
|
if ($this->request->isPost()) {
|
||||||
$post = $this->request->post();
|
$post = $this->request->post();
|
||||||
|
|||||||
@@ -4,10 +4,12 @@
|
|||||||
|
|
||||||
use app\commno\exception\EventException;
|
use app\commno\exception\EventException;
|
||||||
use app\common\service\AuthService;
|
use app\common\service\AuthService;
|
||||||
|
use think\exception\HttpResponseException;
|
||||||
use think\facade\Cache;
|
use think\facade\Cache;
|
||||||
use think\facade\Env;
|
use think\facade\Env;
|
||||||
use think\facade\Event;
|
use think\facade\Event;
|
||||||
use think\facade\Filesystem;
|
use think\facade\Filesystem;
|
||||||
|
use think\response\View;
|
||||||
use think\route\Url;
|
use think\route\Url;
|
||||||
|
|
||||||
include_once __DIR__ . '/common/app/functions.php';
|
include_once __DIR__ . '/common/app/functions.php';
|
||||||
@@ -230,9 +232,9 @@ function build_upload_url($url, $upload_type = null)
|
|||||||
return Filesystem::disk($upload_type)->url($url);
|
return Filesystem::disk($upload_type)->url($url);
|
||||||
}
|
}
|
||||||
|
|
||||||
function event_handle_result($name, $key, $type = 'all') : array
|
function event_handle_result($name, $key, $type = 'all', $params = []) : array
|
||||||
{
|
{
|
||||||
$list_result = Event::trigger($name);
|
$list_result = Event::trigger($name, $params);
|
||||||
|
|
||||||
$result = [];
|
$result = [];
|
||||||
|
|
||||||
@@ -287,3 +289,20 @@ function event_view_replace_js($name)
|
|||||||
|
|
||||||
return "<script id='event-replace-js-{$name}' type='text/plain'>{$content_event}</script>";
|
return "<script id='event-replace-js-{$name}' type='text/plain'>{$content_event}</script>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function event_response($name, $params = [])
|
||||||
|
{
|
||||||
|
$list_result = event_handle_result($name, 'response', 'last', $params);
|
||||||
|
|
||||||
|
if (empty($list_result)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = $list_result[0];
|
||||||
|
|
||||||
|
if (is_string($response)) {
|
||||||
|
$response = View::create($response);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new HttpResponseException($response);
|
||||||
|
}
|
||||||
|
|||||||
@@ -14,13 +14,13 @@ use think\facade\App;
|
|||||||
|
|
||||||
class Version extends Command
|
class Version extends Command
|
||||||
{
|
{
|
||||||
public const VERSION = 'v2.0.38';
|
public const VERSION = 'v2.0.3';
|
||||||
|
|
||||||
public const LAYUI_VERSION = '2.8.16';
|
public const LAYUI_VERSION = '2.8.16';
|
||||||
|
|
||||||
public const COMMENT = [
|
public const COMMENT = [
|
||||||
'增加js的事件处理',
|
'增加response的事件机制',
|
||||||
'增加忘记密码的js替换事件',
|
'为login增加事件',
|
||||||
'发布新版本',
|
'发布新版本',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -141,20 +141,22 @@ class AdminController extends BaseController
|
|||||||
return $this->app->view->assign($name, $value);
|
return $this->app->view->assign($name, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function fetchJS()
|
public function fetchJS($template = '')
|
||||||
{
|
{
|
||||||
$content_js = '';
|
$content_js = '';
|
||||||
|
|
||||||
try {
|
$common_template = '_common';
|
||||||
$content_js .= View::layout(false)
|
|
||||||
->config([
|
|
||||||
'view_suffix' => 'js',
|
|
||||||
])->fetch('_common');
|
|
||||||
|
|
||||||
$content_js .= View::layout(false)
|
if (!empty($template)) {
|
||||||
->config([
|
$template_arr = explode('/', $template);
|
||||||
'view_suffix' => 'js',
|
unset($template_arr[count($template_arr) - 1]);
|
||||||
])->fetch();
|
$template_arr[] = '_common';
|
||||||
|
$common_template = implode('/', $template_arr);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$content_js .= View::layout(false)->fetchJS($common_template);
|
||||||
|
$content_js .= View::layout(false)->fetchJS($template);
|
||||||
} catch (TemplateNotFoundException $th) {
|
} catch (TemplateNotFoundException $th) {
|
||||||
if (Env::get('adminsystem.strict_view_js', true)) {
|
if (Env::get('adminsystem.strict_view_js', true)) {
|
||||||
throw $th;
|
throw $th;
|
||||||
@@ -174,7 +176,7 @@ class AdminController extends BaseController
|
|||||||
{
|
{
|
||||||
$this->assign('data_brage', json_encode($this->dataBrage));
|
$this->assign('data_brage', json_encode($this->dataBrage));
|
||||||
|
|
||||||
$vars['content_js'] = $this->fetchJS();
|
$vars['content_js'] = $this->fetchJS($template);
|
||||||
|
|
||||||
$content_main = View::layout($this->layout)
|
$content_main = View::layout($this->layout)
|
||||||
->config([
|
->config([
|
||||||
|
|||||||
17
app/common/event/AdminLoginIndex/Index.php
Normal file
17
app/common/event/AdminLoginIndex/Index.php
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\common\event\AdminLoginIndex;
|
||||||
|
|
||||||
|
class Index
|
||||||
|
{
|
||||||
|
public function handle($params)
|
||||||
|
{
|
||||||
|
$controller = $params['controller'];
|
||||||
|
|
||||||
|
$controller->assign('captcha',1);
|
||||||
|
|
||||||
|
return [
|
||||||
|
'response' => $controller->fetch('login/ext/index'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -48,4 +48,36 @@ class View extends ThinkView
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析和获取模板内容 用于输出.
|
||||||
|
* @param string $template 模板文件名或者内容
|
||||||
|
* @param array $vars 模板变量
|
||||||
|
* @return string
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function fetch(string $template = '', array $vars = []): string
|
||||||
|
{
|
||||||
|
return $this->config([
|
||||||
|
'view_suffix' => 'html',
|
||||||
|
])->getContent(function () use ($vars, $template) {
|
||||||
|
$this->engine()->fetch($template, array_merge($this->data, $vars));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析和获取模板内容 用于输出.
|
||||||
|
* @param string $template 模板文件名或者内容
|
||||||
|
* @param array $vars 模板变量
|
||||||
|
* @return string
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function fetchJS(string $template = '', array $vars = []): string
|
||||||
|
{
|
||||||
|
return $this->config([
|
||||||
|
'view_suffix' => 'js',
|
||||||
|
])->getContent(function () use ($vars, $template) {
|
||||||
|
$this->engine()->fetch($template, array_merge($this->data, $vars));
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user