仰望星辰工作室

better-staridc-MNBT

better-staridc-MNBT/ templates/tdesign/account/_spa_boot.php 4.8 KB · 108 行 原始文件
Z zfhsh first commit 2 个月前
1<?php
2/**
3 * TDesign 用户中心(user_info 插件)SPA 公共启动片段
4 *
5 * 由 app_plugins/user_info 的 user_info_render() 在检测到当前用户主题为
6 * tdesign 时 include。入口页面(index/login/register/profile/password)
7 * 设置 $td_entry / $td_hash 后 include 本文件。
8 */
9if (!defined('IN_CRONLITE')) {
10 exit('Access Denied');
11}
12
13if (!function_exists('user_info_auth_current')) {
14 echo 'user_info 插件未加载';
15 exit;
16}
17
18$td_dist = __DIR__ . '/dist';
19$td_js = $td_dist . '/assets/index.js';
20$td_css = $td_dist . '/assets/index.css';
21$td_ver = is_file($td_js) ? (string)@filemtime($td_js) : (string)time();
22
23$td_user = user_info_auth_current();
24
25$td_base = function_exists('mnbt_home_base') ? mnbt_home_base() : '';
26$td_theme = function_exists('mnbt_theme_name') ? mnbt_theme_name('user') : 'tdesign';
27$td_dist_url = $td_base . '/templates/' . $td_theme . '/account/dist/';
28
29$boot = [
30 'siteName' => $conf['name'] ?? 'MNBT',
31 'footer' => $conf['hxp'] ?? '',
32 'loggedIn' => $td_user ? true : false,
33 'accountUser' => $td_user ? [
34 'id' => (int)$td_user['id'],
35 'username' => (string)$td_user['username'],
36 'email' => (string)($td_user['email'] ?? ''),
37 'qq' => (string)($td_user['qq'] ?? ''),
38 'status' => (int)($td_user['status'] ?? 1),
39 'created_at' => (string)($td_user['created_at'] ?? ''),
40 ] : null,
41 // 路由 API 入口(user_info 插件通过 P2 通用路由暴露 /account/api/*)
42 'routeBase' => $td_base . '/index.php?_r=',
43 'realnameOcrBase' => $td_base . '/app_plugins/realname/assets/ocr/',
44 // 插件能力标志(account SPA 依据此决定是否展示余额/商城功能)
45 'plugins' => [
46 'balance' => function_exists('mnbt_plugin_enabled') ? mnbt_plugin_enabled('balance') : false,
47 'hosting_shop' => function_exists('mnbt_plugin_enabled') ? mnbt_plugin_enabled('hosting_shop') : false,
48 'docker_shop' => function_exists('mnbt_plugin_enabled') ? mnbt_plugin_enabled('docker_shop') : false,
49 'realname' => function_exists('mnbt_plugin_enabled') ? mnbt_plugin_enabled('realname') : false,
50 'zjmf' => function_exists('mnbt_plugin_enabled') ? mnbt_plugin_enabled('zjmfmanager_reserve') : false,
51 ],
52 // 主机管理面板入口(核心 user scope)
53 'panelUrl' => $td_base . '/user/',
54 // Docker 控制台入口(核心 docker scope)
55 'dockerUrl' => $td_base . '/docker/',
56 // 官网首页入口
57 'homeUrl' => $td_base . '/',
58 'theme' => $td_theme,
59 'version' => '0.3.0',
60 'entry' => $td_entry ?? 'dashboard',
61 'hash' => $td_hash ?? '',
62];
63?>
64<!DOCTYPE html>
65<html lang="zh-CN">
66<head>
67<meta charset="UTF-8" />
68<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
69<title><?= htmlspecialchars(($title ?? '用户中心') . ' · ' . ($conf['name'] ?? 'MNBT'), ENT_QUOTES, 'UTF-8') ?></title>
70<link rel="icon" href="<?= htmlspecialchars(mnbt_asset_url('images/logo-ico.png'), ENT_QUOTES, 'UTF-8') ?>" type="image/ico" />
71<link rel="stylesheet" href="<?= htmlspecialchars(mnbt_asset_url('css/materialdesignicons.min.css'), ENT_QUOTES, 'UTF-8') ?>" />
72<?php if (is_file($td_css)): ?>
73<link rel="stylesheet" href="<?= htmlspecialchars($td_dist_url . 'assets/index.css', ENT_QUOTES, 'UTF-8') ?>?v=<?= $td_ver ?>" />
74<?php endif; ?>
75<style>
76 html, body, #app { margin: 0; padding: 0; height: 100%; background: #f2f3f5; }
77 .td-boot-missing { max-width: 540px; margin: 12vh auto; padding: 32px; border-radius: 12px; background: #fff; border: 1px solid #e7e7e7; font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; color: #1a2e28; }
78 .td-boot-missing h2 { margin: 0 0 12px; font-size: 18px; color: #d54941; }
79 .td-boot-missing code { background: #f3f3f3; padding: 2px 8px; border-radius: 4px; font-size: 13px; }
80 .td-boot-missing p { margin: 10px 0; line-height: 1.7; font-size: 14px; }
81</style>
82</head>
83<body>
84<div id="app">
85<?php if (!is_file($td_js)): ?>
86 <div class="td-boot-missing">
87 <h2>用户中心尚未构建</h2>
88 <p>请在服务器或本机执行:</p>
89 <p><code>cd templates/tdesign/spa &amp;&amp; npm install &amp;&amp; npm run build:account</code></p>
90 <p>构建产物应位于 <code>templates/tdesign/account/dist/</code></p>
91 </div>
92<?php endif; ?>
93</div>
94<script>
95window.__TD_BOOT__ = <?= json_encode($boot, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?>;
96<?php if (!empty($td_hash)): ?>
97if (window.__TD_BOOT__.hash) {
98 if (!location.hash || location.hash === '#' || location.hash === '#/') {
99 location.hash = window.__TD_BOOT__.hash;
100 }
101}
102<?php endif; ?>
103</script>
104<?php if (is_file($td_js)): ?>
105<script type="module" src="<?= htmlspecialchars($td_dist_url . 'assets/index.js', ENT_QUOTES, 'UTF-8') ?>?v=<?= $td_ver ?>"></script>
106<?php endif; ?>
107</body>
108</html>