mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-07 18:42:49 +08:00
将js代码架构改为app下渲染;
This commit is contained in:
@@ -9,6 +9,7 @@ use app\common\service\AuthService;
|
||||
use think\facade\Env;
|
||||
use think\facade\View;
|
||||
use think\Model;
|
||||
use think\template\exception\TemplateNotFoundException;
|
||||
use think\Validate;
|
||||
|
||||
/**
|
||||
@@ -140,6 +141,29 @@ class AdminController extends BaseController
|
||||
return $this->app->view->assign($name, $value);
|
||||
}
|
||||
|
||||
protected function fetchJS()
|
||||
{
|
||||
$content_js = '';
|
||||
|
||||
try {
|
||||
$content_js .= View::layout(false)
|
||||
->config([
|
||||
'view_suffix' => 'js',
|
||||
])->fetch('_common');
|
||||
|
||||
$content_js .= View::layout(false)
|
||||
->config([
|
||||
'view_suffix' => 'js',
|
||||
])->fetch();
|
||||
} catch (TemplateNotFoundException $th) {
|
||||
if (Env::get('adminsystem.strict_view_js', true)) {
|
||||
throw $th;
|
||||
}
|
||||
}
|
||||
|
||||
return "<script>{$content_js}</script>";
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析和获取模板内容 用于输出.
|
||||
* @param string $template
|
||||
@@ -150,7 +174,17 @@ class AdminController extends BaseController
|
||||
{
|
||||
$this->assign('data_brage', json_encode($this->dataBrage));
|
||||
|
||||
return $this->app->view->fetch($template, $vars);
|
||||
$vars['content_js'] = $this->fetchJS();
|
||||
|
||||
$content_main = View::layout($this->layout)
|
||||
->config([
|
||||
'view_suffix' => 'html',
|
||||
])->fetch($template, $vars);
|
||||
|
||||
$html = '';
|
||||
$html .= $content_main;
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -36,4 +36,16 @@ class View extends ThinkView
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置模板引擎.
|
||||
* @param array $config 参数
|
||||
* @return $this
|
||||
*/
|
||||
public function config(array $config)
|
||||
{
|
||||
$this->driver()->config($config);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ use think\facade\App;
|
||||
class PathTools
|
||||
{
|
||||
/**
|
||||
* 系统生成的文件,这些文件应当是可以任意删除的
|
||||
* 系统生成的文件,这些文件应当是可以任意删除的.
|
||||
*
|
||||
* @param string $file_name
|
||||
* @return string
|
||||
@@ -49,6 +49,29 @@ class PathTools
|
||||
if (!is_dir($dir_name)) {
|
||||
mkdir($dir_name, 0777, true);
|
||||
}
|
||||
|
||||
return $file_path;
|
||||
}
|
||||
|
||||
public static function mapDir($dir, $callback = null)
|
||||
{
|
||||
$result = [];
|
||||
$cdir = scandir($dir);
|
||||
foreach ($cdir as $key => $value) {
|
||||
if (!in_array($value, ['.', '..'])) {
|
||||
$current_path = $dir . DS . $value;
|
||||
if (is_dir($current_path)) {
|
||||
$result[$value] = self::mapDir($current_path, $callback);
|
||||
} else {
|
||||
if (is_callable($callback)) {
|
||||
$result[$value] = $callback($current_path, $value, $dir);
|
||||
} else {
|
||||
$result[$value] = $current_path;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user