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