国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

擴展webman原生模版 Raw類-支持Layout布局

wzj177

擴展

視圖類

class LayoutRaw extends Raw
{
    public static function render(string $template, array $vars, ?string $app = null, ?string $plugin = null, ?string $layout = null): string
    {
        $request = request();
        $plugin = $plugin === null ? ($request->plugin ?? '') : $plugin;
        $configPrefix = $plugin ? "plugin.$plugin." : '';
        $viewSuffix = config("{$configPrefix}view.options.view_suffix", 'html');
        $app = $app === null ? ($request->app ?? '') : $app;
        $baseViewPath = $plugin ? base_path() . "/plugin/$plugin/app" : app_path();
        $__template_path__ = $template[0] === '/' ? base_path() . "$template.$viewSuffix" : ($app === '' ? "$baseViewPath/view/$template.$viewSuffix" : "$baseViewPath/$app/view/$template.$viewSuffix");
        $layoutPath = $layout ? $baseViewPath . "/view/$layout" : null;
        $viewCache = config("{$configPrefix}view.options.view_cache", true);
        if ($viewCache) {
            $cacheKey = md5($__template_path__);
            $viewPath = runtime_path('views');
            !is_dir($viewPath) && mkdir($viewPath, 0755, true);
            $cachePhpFile = runtime_path('views') . "/$cacheKey.php";
            $cachePhpTimeFile = runtime_path('views') . "/$cacheKey.php.txt";
            if (is_file($cachePhpFile) && is_file($cachePhpTimeFile)) {
                $cachePhpTime = intval(file_get_contents($cachePhpTimeFile));
                // 緩存文件是否過期
                if ($cachePhpTime === filemtime($__template_path__)) {
                    ob_start();
                    try {
                        include $cachePhpFile;
                    } catch (Throwable $e) {
                        ob_end_clean();
                        throw $e;
                    }

                    return ob_get_clean();
                }
            }
        }

        if (isset($request->_view_vars)) {
            extract((array)$request->_view_vars);
        }

        extract($vars);

        ob_start();
        try {
            include $__template_path__;
        } catch (Throwable $e) {
            ob_end_clean();
            throw $e;
        }

        $page_body_content = ob_get_clean();
        if ($layout) {
            if (file_exists($layoutPath)) {
                preg_match_all('/<style.*?>(.*?)<\/style>/is', $page_body_content, $styleMatches);
                preg_match_all('/<script\s+src=["\'](.*?)["\'].*?><\/script>/is', $page_body_content, $scriptMatches);
                preg_match_all('/<link\s+rel=["\'].*?["\'].*?href=["\'](.*?)["\'].*?>/is', $page_body_content, $linkMatches);
                $block_link = implode("\n", $linkMatches[0]) . "\n";
                $block_style = implode("\n", $styleMatches[0]) . "\n";
                $block_script = implode("\n", $scriptMatches[0]);
                $page_body_content = preg_replace('/<style.*?<\/style>/is', '', $page_body_content);
                $page_body_content = preg_replace('/<script\s+src=["\'].*?["\'].*?><\/script>/is', '', $page_body_content);
                $page_body_content = preg_replace('/<link\s+rel=["\'].*?["\'].*?href=["\'].*?["\'].*?>/is', '', $page_body_content);

                ob_start();
                // 提取布局和視圖的內(nèi)容
                extract(compact('page_body_content', 'block_link', 'block_style', 'block_script'));
                include $layoutPath;
                $renderedContent = ob_get_clean();
                if ($viewCache) {
                    file_put_contents($cachePhpFile, $renderedContent);
                    file_put_contents($cachePhpTimeFile, filemtime($__template_path__));
                }

                return $renderedContent;
            }
        }
        return $page_body_content;
    }
}

模板 _layout.html

根據(jù)上面的改造,布局文件放在應(yīng)用的view目錄下

<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="utf-8">
    <title><?= $page_title ?? '管理后臺' ?></title>
    <link rel="stylesheet" href="/app/admin/component/pear/css/pear.css"/>
    <link rel="stylesheet" href="/app/admin/component/jsoneditor/css/jsoneditor.css" />
    <link rel="stylesheet" href="/app/admin/admin/css/reset.css"/>
    <?= isset($block_link) ? $block_link : '' ?>
    <?= isset($block_style) ? $block_style : '' ?>
</head>
<body class="pear-container">
<?= $page_body_content ?? '<div class="content"><img src="/app/admin/admin/images/404.svg" alt=""><div class="content-r"><h1>404</h1><p>抱歉,你訪問的頁面不存在或仍在開發(fā)中</p></div></div>' ?>
<script src="/app/admin/component/layui/layui.js?v=2.8.12"></script>
<script src="/app/admin/component/pear/pear.js"></script>
<script src="/app/admin/component/jsoneditor/jsoneditor.js"></script>
<script src="/app/admin/admin/js/common.js"></script>
<?= isset($block_script) ? $block_script : '' ?>
</body>
</html>

特性

  • 支持layout布局
  • 支持模板緩存

案例:single-vue-cms-admin

693 4 0
4個評論

liziyu

感覺是個好東西,但沒看懂!哈哈

  • wzj177 2024-12-30

    就和tp那些框架的layout的一樣。做一個統(tǒng)一的layout。其他視圖文件只需要編寫代碼塊(比如:列表就只有查詢表單、列表、分頁、業(yè)務(wù)js的代碼;form表單就是表單內(nèi)容和業(yè)務(wù)js),在layout里面統(tǒng)一引入公共css、公共js,視圖里面就少了些代碼,
    其他也沒啥。主要是看個人習(xí)慣是否習(xí)慣。

  • liziyu 2024-12-30

    哦哦,類似之前l(fā)ayui的“單頁版”的,謝謝!~

xianrenqh

感覺是個好東西,但沒看懂!哈哈

  • wzj177 2024-12-30

    就和tp那些框架的layout的一樣。做一個統(tǒng)一的layout。其他視圖文件只需要編寫代碼塊(比如:列表就只有查詢表單、列表、分頁、業(yè)務(wù)js的代碼;form表單就是表單內(nèi)容和業(yè)務(wù)js),在layout里面統(tǒng)一引入公共css、公共js,視圖里面就少了些代碼,
    其他也沒啥。主要是看個人習(xí)慣是否習(xí)慣。

efnic

666,已購買。

  • wzj177 2024-12-30

    感謝支持,有問題可以找我

  • wzj177 2024-12-30

    如果下載不是1.0.1版本,請重新下載

efnic

大佬,購買后沒有 cms的菜單,是不是我漏了什么步驟?

  • wzj177 2025-01-03

    抱歉忘記更新菜單。你在http://www.wtbis.cn/app/view/single-vue-cms-admin 去吧,我加了說明。我晚點更新一個版本

  • wzj177 2025-01-03

    版本已更新可以去下載了。如果沒下,還有修改cms內(nèi)容form.html的狀態(tài)表單項bug,改成: <div class="layui-form-item">
    <label class="layui-form-label">狀態(tài)</label>
    <div class="layui-input-block">
    <input type="radio" name="status" v-for="m in statusItems" v-model="form.status" :value="m.value" :title="m.label" lay-filter="status" :checked="m.value == form.status">
    </div>
    </div>

wzj177

726
積分
0
獲贊數(shù)
0
粉絲數(shù)
2019-06-03 加入
??