重写了插件后台入口模板
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
yiqiu
2025-11-21 00:07:12 +08:00
parent cbd6250967
commit 98e046c160
2 changed files with 126 additions and 78 deletions

View File

@@ -1,82 +1,96 @@
<!DOCTYPE html> <link rel="stylesheet" href="/plugins/addon/theme_configurator/template/admin/theme.css" />
<html lang="zh-cn">
<head> <div id="theme-config-app" class="template" v-cloak>
<meta charset="UTF-8" /> <com-config>
<title>主题配置</title> <t-card class="theme-card">
<style> <div class="theme-card__header">
body { <div>
padding: 24px; <h3>主题配置</h3>
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif; <p class="theme-desc">
background: #f5f6fa; 在此集中维护 BlackFruit-UI 的导航、页脚、SEO、企业信息、轮播和侧边浮窗等配置。
} </p>
</div>
<div>
<t-button variant="outline" @click="loadConfig" :loading="loading">
刷新
</t-button>
<t-button theme="primary" class="ml-10" @click="saveConfig" :loading="saving">
保存
</t-button>
</div>
</div>
<t-textarea v-model="configText" :autosize="{ minRows: 18, maxRows: 22 }" class="theme-textarea"
:placeholder="langPlaceholder"></t-textarea>
<p class="theme-tip">
JSON 结构与 `/console/v1/common` 返回值保持一致,保存后即可供前台调用。
</p>
</t-card>
</com-config>
</div>
.card { <script src="/plugins/addon/theme_configurator/template/admin/lang/index.js"></script>
background: #fff; <script>
border-radius: 8px; (function () {
padding: 24px; const host = location.origin;
box-shadow: 0 5px 16px rgba(0, 0, 0, 0.08); const adminPath = location.pathname.split("/")[1];
max-width: 960px; const base = `${host}/${adminPath}/v1/theme/config`;
margin: 0 auto;
}
textarea { new Vue({
width: 100%; el: "#theme-config-app",
min-height: 280px; data() {
border-radius: 8px; return {
border: 1px solid #dfe3ec; configText: "",
padding: 12px; loading: false,
font-family: "JetBrains Mono", Consolas, monospace; saving: false,
font-size: 13px; langPlaceholder: "请严格按照 JSON 格式填写主题配置...",
background: #0f172a; };
color: #e2e8f0; },
} created() {
this.loadConfig();
button { },
margin-top: 16px; methods: {
padding: 10px 24px; loadConfig() {
border: none; this.loading = true;
border-radius: 6px; axios
background-color: #2563eb; .get(base, {
color: #fff; headers: {
cursor: pointer; Authorization: "Bearer " + localStorage.getItem("backJwt"),
font-size: 14px; },
} })
</style> .then((res) => {
</head> const data = (res.data && res.data.data) || {};
this.configText = JSON.stringify(data, null, 2);
<body> })
<div class="card"> .finally(() => {
<h2>主题配置 JSON</h2> this.loading = false;
<p>此页面演示如何通过插件快速调整 BlackFruit-UI 的导航、页脚、SEO、轮播、侧边栏以及企业信息。直接编辑下方 JSON 提交即可。</p> });
<textarea id="themeConfig"></textarea> },
<button id="saveBtn">保存配置</button> saveConfig() {
</div> if (!this.configText.trim()) {
return this.$message.warning("内容不能为空");
<script> }
const input = document.getElementById("themeConfig"); let payload;
const request = (url, options = {}) => try {
fetch(url, Object.assign({ headers: { "Content-Type": "application/json" } }, options)) payload = JSON.parse(this.configText);
.then((res) => res.json()); } catch (err) {
return this.$message.error("JSON 解析失败:" + err.message);
request("/<?= DIR_ADMIN ?>/v1/theme/config").then((res) => { }
input.value = JSON.stringify(res.data, null, 2); this.saving = true;
axios
.post(base, payload, {
headers: {
Authorization: "Bearer " + localStorage.getItem("backJwt"),
},
})
.then((res) => {
this.$message.success(res.data.msg || "保存成功");
this.configText = JSON.stringify(res.data.data, null, 2);
})
.finally(() => {
this.saving = false;
});
},
},
}); });
})();
document.getElementById("saveBtn").addEventListener("click", () => { </script>
try {
const payload = JSON.parse(input.value);
request("/<?= DIR_ADMIN ?>/v1/theme/config", {
method: "POST",
body: JSON.stringify(payload),
}).then((res) => {
alert(res.msg || "保存成功");
});
} catch (err) {
alert("JSON 解析失败: " + err.message);
}
});
</script>
</body>
</html>

View File

@@ -0,0 +1,34 @@
.theme-card {
margin: 20px;
}
.theme-card__header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
}
.theme-card__header h3 {
margin: 0;
font-size: 20px;
}
.theme-desc {
margin: 4px 0 0;
color: #6b7280;
}
.theme-textarea textarea {
font-family: "JetBrains Mono", Consolas, monospace;
}
.theme-tip {
margin-top: 12px;
color: #9ca3af;
font-size: 12px;
}
.ml-10 {
margin-left: 10px;
}