仰望星辰工作室

better-staridc-MNBT

Z zfhsh first commit 2 个月前
1<template>
2 <div class="td-page td-theme-page">
3 <div class="td-page-head">
4 <div>
5 <h3 class="td-page-title"><i class="mdi mdi-palette-outline"></i>前端模板设置</h3>
6 <p class="td-page-subtitle">切换用户端 / 管理端主题皮肤</p>
7 </div>
8 </div>
9
10 <div class="td-set-card">
11 <div class="td-set-card-hd">
12 <div class="td-set-icon"><i class="mdi mdi-palette-outline"></i></div>
13 <div>
14 <h4>前端模板</h4>
15 <p>切换用户端 / 管理端主题皮肤</p>
16 </div>
17 </div>
18 <div class="td-set-card-bd">
19 <t-loading :loading="loading" text="保存中…" size="small">
20 <div class="td-form">
21 <div class="td-form-row">
22 <label>用户端主题</label>
23 <t-select v-model="form.usertheme" placeholder="请选择用户端主题">
24 <t-option
25 v-for="t in userThemes"
26 :key="t.name"
27 :value="t.name"
28 :label="`${t.title}${t.version ? ' v' + t.version : ''} (${t.name})`"
29 />
30 </t-select>
31 <div class="td-form-hint">
32 当前: <code>{{ curUserTheme || '-' }}</code> · 目录 templates/
33 </div>
34 </div>
35
36 <div class="td-form-row">
37 <label>管理端主题</label>
38 <t-select v-model="form.admintheme" placeholder="请选择管理端主题">
39 <t-option
40 v-for="t in adminThemes"
41 :key="t.name"
42 :value="t.name"
43 :label="`${t.title}${t.version ? ' v' + t.version : ''} (${t.name})`"
44 />
45 </t-select>
46 <div class="td-form-hint">
47 当前: <code>{{ curAdminTheme || '-' }}</code> · 缺页回退 default
48 </div>
49 </div>
50
51 <div v-if="dockerThemes.length" class="td-form-row">
52 <label>Docker 控制台主题</label>
53 <t-select v-model="form.dockertheme" placeholder="请选择 Docker 控制台主题">
54 <t-option
55 v-for="t in dockerThemes"
56 :key="t.name"
57 :value="t.name"
58 :label="`${t.title}${t.version ? ' v' + t.version : ''} (${t.name})`"
59 />
60 </t-select>
61 <div class="td-form-hint">
62 当前: <code>{{ curDockerTheme || '-' }}</code> · 缺页回退 default
63 </div>
64 </div>
65
66 <div v-if="homeThemes.length" class="td-form-row">
67 <label>主页主题</label>
68 <t-select v-model="form.hometheme" placeholder="请选择主页主题">
69 <t-option
70 v-for="t in homeThemes"
71 :key="t.name"
72 :value="t.name"
73 :label="`${t.title}${t.version ? ' v' + t.version : ''} (${t.name})`"
74 />
75 </t-select>
76 <div class="td-form-hint">
77 当前: <code>{{ curHomeTheme || '-' }}</code> · 站点根路径 / 的落地页皮肤 · templates/主题/home/
78 </div>
79 </div>
80
81 <div class="td-form-actions">
82 <t-button theme="primary" :loading="loading" @click="save">
83 <i class="mdi mdi-content-save-outline"></i> 保存主题设置
84 </t-button>
85 </div>
86
87 <div class="td-form-note">
88 <b>提示:</b> 保存后用户端立即生效;管理端建议整页刷新。主题包放在
89 <code>templates/主题名/</code> 下即可被扫描。
90 </div>
91 </div>
92 </t-loading>
93 </div>
94 </div>
95
96 <div class="td-set-card">
97 <div class="td-set-card-hd">
98 <div class="td-set-icon"><i class="mdi mdi-format-list-bulleted"></i></div>
99 <div>
100 <h4>已安装主题</h4>
101 <p>共 {{ themeList.length }} 个</p>
102 </div>
103 </div>
104 <div class="td-set-card-bd td-set-card-bd-table">
105 <t-table
106 row-key="name"
107 :data="themeList"
108 :columns="columns"
109 :bordered="false"
110 :hover="true"
111 :stripe="false"
112 size="small"
113 :max-height="600"
114 cell-empty-content="-"
115 >
116 <template #name="{ row }">
117 <code class="theme-code">{{ row.name }}</code>
118 </template>
119 <template #version="{ row }">
120 <t-tag v-if="row.version" size="small" theme="primary" variant="light">
121 v{{ row.version }}
122 </t-tag>
123 <span v-else class="td-text-mute">-</span>
124 </template>
125 <template #has_user="{ row }">
126 <t-tag v-if="row.has_user" size="small" theme="success" variant="light">支持</t-tag>
127 <span v-else class="td-text-mute">—</span>
128 </template>
129 <template #has_admin="{ row }">
130 <t-tag v-if="row.has_admin" size="small" theme="success" variant="light">支持</t-tag>
131 <span v-else class="td-text-mute">—</span>
132 </template>
133 <template #has_docker="{ row }">
134 <t-tag v-if="row.has_docker" size="small" theme="success" variant="light">支持</t-tag>
135 <span v-else class="td-text-mute">—</span>
136 </template>
137 <template #has_home="{ row }">
138 <t-tag v-if="row.has_home" size="small" theme="success" variant="light">支持</t-tag>
139 <span v-else class="td-text-mute">—</span>
140 </template>
141 <template #active="{ row }">
142 <div class="active-tags">
143 <t-tag v-if="row.name === curUserTheme" size="small" theme="warning" variant="light">用户端</t-tag>
144 <t-tag v-if="row.name === curAdminTheme" size="small" theme="warning" variant="light">管理端</t-tag>
145 <t-tag v-if="row.name === curDockerTheme" size="small" theme="warning" variant="light">Docker</t-tag>
146 <t-tag v-if="row.name === curHomeTheme" size="small" theme="warning" variant="light">主页</t-tag>
147 <span v-if="row.name !== curUserTheme && row.name !== curAdminTheme && row.name !== curDockerTheme && row.name !== curHomeTheme" class="td-text-mute">—</span>
148 </div>
149 </template>
150 </t-table>
151 </div>
152 </div>
153
154 <div class="td-set-card">
155 <div class="td-set-card-hd">
156 <div class="td-set-icon"><i class="mdi mdi-home-city-outline"></i></div>
157 <div>
158 <h4>主页内容</h4>
159 <p>内置主页落地页配置,模板跟随上方所选主页主题(templates/主题/home/)</p>
160 </div>
161 </div>
162 <div class="td-set-card-bd">
163 <t-loading :loading="homeLoading" text="保存中…" size="small">
164 <div class="td-form">
165 <div class="td-form-switch">
166 <div class="td-form-switch-txt">
167 <strong>启用内置主页</strong>
168 <span>关闭后恢复旧行为:插件接管或跳转用户面板</span>
169 </div>
170 <t-switch v-model="homeForm.home_enable" />
171 </div>
172
173 <div class="td-form-row">
174 <label>站点标题</label>
175 <t-input v-model="homeForm.home_title" placeholder="留空使用系统名称" clearable />
176 </div>
177
178 <div class="td-form-row">
179 <label>Hero 标语</label>
180 <t-input v-model="homeForm.home_hero" placeholder="高性能虚拟主机,即买即用" clearable />
181 <div class="td-form-hint">主页首屏大标题</div>
182 </div>
183
184 <div class="td-form-row">
185 <label>主色调</label>
186 <div class="home-color-row">
187 <input type="color" class="home-color-picker" v-model="homeForm.home_primary" />
188 <t-input v-model="homeForm.home_primary" style="max-width: 140px" />
189 </div>
190 <div class="td-form-hint">十六进制色值(#rrggbb),应用到主页按钮与强调元素</div>
191 </div>
192
193 <div class="td-form-row">
194 <label>站点 Logo</label>
195 <div class="home-upload-row">
196 <img v-if="logoPreview" :src="logoPreview" alt="logo" class="home-logo-preview" />
197 <span v-else class="home-logo-empty">未设置</span>
198 <input
199 ref="logoInput"
200 type="file"
201 accept=".png,.jpg,.jpeg,.gif,.ico"
202 style="display: none"
203 @change="onUpload('logo')"
204 />
205 <t-button variant="outline" @click="logoInput.click()"><i class="mdi mdi-upload"></i> 上传</t-button>
206 <t-button variant="outline" theme="danger" @click="homeForm.home_logo = ''">清除</t-button>
207 </div>
208 <t-input v-model="homeForm.home_logo" placeholder="上传后自动填入,或手动填写 URL" clearable />
209 <div class="td-form-hint">留空使用系统控制面板 Logo(imsetes/upload_logo/logo.index.png)</div>
210 </div>
211
212 <div class="td-form-row">
213 <label>Favicon</label>
214 <div class="home-upload-row">
215 <input
216 ref="faviconInput"
217 type="file"
218 accept=".png,.jpg,.jpeg,.gif,.ico"
219 style="display: none"
220 @change="onUpload('favicon')"
221 />
222 <t-button variant="outline" @click="faviconInput.click()"><i class="mdi mdi-upload"></i> 上传</t-button>
223 <t-button variant="outline" theme="danger" @click="homeForm.home_favicon = ''">清除</t-button>
224 </div>
225 <t-input v-model="homeForm.home_favicon" placeholder="上传后自动填入,或手动填写 URL" clearable />
226 <div class="td-form-hint">留空使用系统默认图标</div>
227 </div>
228
229 <div class="td-form-row">
230 <label>底部版权</label>
231 <t-input v-model="homeForm.home_footer" placeholder="留空使用系统版权(hxp)" clearable />
232 </div>
233
234 <div class="td-form-switch">
235 <div class="td-form-switch-txt">
236 <strong>显示公告区</strong>
237 <span>展示系统网站公告(MN_config.gg)</span>
238 </div>
239 <t-switch v-model="homeForm.home_show_notice" />
240 </div>
241
242 <div class="td-form-switch">
243 <div class="td-form-switch-txt">
244 <strong>显示套餐区</strong>
245 <span>hosting_shop 启用且存在有效套餐时展示</span>
246 </div>
247 <t-switch v-model="homeForm.home_show_plans" />
248 </div>
249
250 <div v-if="themeFields.length" class="td-form-note" style="padding-top:8px;border-top:1px solid #e5e7eb;margin-bottom:8px;">
251 <b>主题自定义设置</b>(当前主页主题注册的扩展项)
252 </div>
253 <template v-for="f in themeFields" :key="f.key">
254 <!-- text / number -->
255 <div v-if="f.type === 'text' || f.type === 'number'" class="td-form-row">
256 <label>{{ f.label }}</label>
257 <t-input v-model="themeValues[f.key]" :type="f.type" :placeholder="f.placeholder || ''" clearable />
258 <div v-if="f.hint" class="td-form-hint">{{ f.hint }}</div>
259 </div>
260 <!-- color -->
261 <div v-else-if="f.type === 'color'" class="td-form-row">
262 <label>{{ f.label }}</label>
263 <div class="home-color-row">
264 <input type="color" class="home-color-picker" v-model="themeValues[f.key]" />
265 <t-input v-model="themeValues[f.key]" style="max-width: 140px" :placeholder="f.placeholder || ''" />
266 </div>
267 <div v-if="f.hint" class="td-form-hint">{{ f.hint }}</div>
268 </div>
269 <!-- switch -->
270 <div v-else-if="f.type === 'switch'" class="td-form-switch">
271 <div class="td-form-switch-txt">
272 <strong>{{ f.label }}</strong>
273 <span v-if="f.hint">{{ f.hint }}</span>
274 </div>
275 <t-switch v-model="themeValues[f.key]" />
276 </div>
277 <!-- select -->
278 <div v-else-if="f.type === 'select'" class="td-form-row">
279 <label>{{ f.label }}</label>
280 <t-select v-model="themeValues[f.key]" :placeholder="f.placeholder || ''" clearable>
281 <t-option v-for="opt in (f.options || [])" :key="opt.value" :value="opt.value" :label="opt.label" />
282 </t-select>
283 <div v-if="f.hint" class="td-form-hint">{{ f.hint }}</div>
284 </div>
285 <!-- textarea -->
286 <div v-else-if="f.type === 'textarea'" class="td-form-row">
287 <label>{{ f.label }}</label>
288 <t-textarea v-model="themeValues[f.key]" :autosize="{ minRows: 3, maxRows: 8 }" :placeholder="f.placeholder || ''" />
289 <div v-if="f.hint" class="td-form-hint">{{ f.hint }}</div>
290 </div>
291 <!-- image -->
292 <div v-else-if="f.type === 'image'" class="td-form-row">
293 <label>{{ f.label }}</label>
294 <div class="home-upload-row">
295 <img v-if="themeImagePreview(f.key)" :src="themeImagePreview(f.key)" alt="" class="home-image-preview" />
296 <span v-else class="home-logo-empty">未设置</span>
297 <input
298 :ref="(el) => setImageInput(f.key, el)"
299 type="file"
300 accept=".png,.jpg,.jpeg,.gif,.webp,.ico"
301 style="display: none"
302 @change="onUploadThemeImage(f.key)"
303 />
304 <t-button variant="outline" @click="triggerImageUpload(f.key)"><i class="mdi mdi-upload"></i> 上传</t-button>
305 <t-button variant="outline" theme="danger" @click="themeValues[f.key] = ''">清除</t-button>
306 </div>
307 <t-input v-model="themeValues[f.key]" placeholder="上传后自动填入,或手动填写 URL" clearable />
308 <div v-if="f.hint" class="td-form-hint">{{ f.hint }}</div>
309 </div>
310 </template>
311
312 <div class="td-form-actions">
313 <t-button theme="primary" :loading="homeLoading" @click="saveHome">
314 <i class="mdi mdi-content-save-outline"></i> 保存主页内容
315 </t-button>
316 </div>
317
318 <div class="td-form-note">
319 <b>提示:</b> 主页模板位于 <code>templates/当前主页主题/home/index.php</code>,缺页回退
320 <code>templates/default/home/index.php</code>。插件可通过 <code>home.blocks</code> 过滤器注入扩展区块;
321 启用 shop_frontend 等插件时,插件主页优先接管。
322 </div>
323 </div>
324 </t-loading>
325 </div>
326 </div>
327 </div>
328</template>
329
330<script setup>
331import { reactive, ref, computed } from 'vue'
332import { MessagePlugin } from 'tdesign-vue-next'
333import { setTheme, setHome, uploadHomeIcon, uploadHomeImage } from '@/admin/api/settings'
334
335const boot = window.__TD_BOOT__ || {}
336// 防御:boot.themeList 可能是对象(关联数组 json_encode 后)或数组,统一转成数组
337const rawThemeList = Array.isArray(boot.themeList)
338 ? boot.themeList
339 : boot.themeList
340 ? Object.values(boot.themeList)
341 : []
342const themeList = rawThemeList
343const curUserTheme = boot.curUserTheme || ''
344const curAdminTheme = boot.curAdminTheme || ''
345const curDockerTheme = boot.curDockerTheme || ''
346const curHomeTheme = boot.curHomeTheme || ''
347const loading = ref(false)
348
349const userThemes = computed(() => themeList.filter((t) => t.has_user))
350const adminThemes = computed(() => themeList.filter((t) => t.has_admin))
351const dockerThemes = computed(() => themeList.filter((t) => t.has_docker))
352const homeThemes = computed(() => themeList.filter((t) => t.has_home))
353
354const form = reactive({
355 usertheme: curUserTheme || (userThemes.value[0] && userThemes.value[0].name) || '',
356 admintheme: curAdminTheme || (adminThemes.value[0] && adminThemes.value[0].name) || '',
357 dockertheme: curDockerTheme || (dockerThemes.value[0] && dockerThemes.value[0].name) || '',
358 hometheme: curHomeTheme || (homeThemes.value[0] && homeThemes.value[0].name) || '',
359})
360
361const columns = [
362 { colKey: 'name', title: '目录', width: 160, ellipsis: true },
363 { colKey: 'title', title: '名称', minWidth: 140, ellipsis: true },
364 { colKey: 'version', title: '版本', width: 100 },
365 { colKey: 'has_user', title: '用户端', width: 90, align: 'center' },
366 { colKey: 'has_admin', title: '管理端', width: 90, align: 'center' },
367 { colKey: 'has_docker', title: 'Docker', width: 85, align: 'center' },
368 { colKey: 'has_home', title: '主页', width: 75, align: 'center' },
369 { colKey: 'active', title: '当前启用', width: 200, align: 'center' },
370 { colKey: 'description', title: '说明', minWidth: 200, ellipsis: true },
371]
372
373async function save() {
374 if (!form.usertheme || !form.admintheme) {
375 MessagePlugin.warning('请选择用户端和管理端主题')
376 return
377 }
378 loading.value = true
379 const r = await setTheme(form.usertheme, form.admintheme, form.dockertheme || '', form.hometheme || '')
380 loading.value = false
381 if (r.ok) {
382 MessagePlugin.success('保存成功,建议刷新页面查看效果')
383 }
384}
385
386/* ===== 主页内容(V1.84 独立主页系统) ===== */
387const conf = boot.conf || {}
388const homeLoading = ref(false)
389
390// 主题注册字段定义
391const themeFields = (boot.homeThemeSettingsFields && Array.isArray(boot.homeThemeSettingsFields))
392 ? boot.homeThemeSettingsFields
393 : []
394
395// 响应式值映射
396const themeValues = reactive(
397 themeFields.reduce((acc, f) => {
398 acc[f.key] = f.value !== undefined ? f.value : f.default
399 return acc
400 }, {})
401)
402
403const logoInput = ref(null)
404const faviconInput = ref(null)
405
406/** 相对资源转可预览 URL(admin 目录下 ../imsetes/...) */
407function resolveAsset(v) {
408 if (!v) return ''
409 if (/^https?:\/\//i.test(v) || v.startsWith('/')) return v
410 if (v.startsWith('imsetes/')) return '../' + v
411 return v
412}
413
414const homeForm = reactive({
415 home_enable: conf.home_enable !== 'false',
416 home_title: conf.home_title || '',
417 home_hero: conf.home_hero || '',
418 home_primary: /^#[0-9a-fA-F]{6}$/.test(conf.home_primary || '')
419 ? conf.home_primary
420 : '#4f46e5',
421 home_logo: conf.home_logo || '',
422 home_favicon: conf.home_favicon || '',
423 home_footer: conf.home_footer || '',
424 home_show_notice: conf.home_show_notice !== 'false',
425 home_show_plans: conf.home_show_plans !== 'false',
426})
427
428const logoPreview = computed(() => resolveAsset(homeForm.home_logo))
429
430/* ===== 主题 image 类型字段上传 ===== */
431const imageInputs = {}
432function setImageInput(key, el) {
433 if (el) imageInputs[key] = el
434}
435function triggerImageUpload(key) {
436 imageInputs[key]?.click()
437}
438function themeImagePreview(key) {
439 return resolveAsset(themeValues[key] || '')
440}
441async function onUploadThemeImage(key) {
442 const input = imageInputs[key]
443 if (!input?.files?.length) return
444 const file = input.files[0]
445 homeLoading.value = true
446 const r = await uploadHomeImage(key, file)
447 input.value = ''
448 if (r.ok) {
449 themeValues[key] = 'imsetes/upload_logo/home_' + key + '.png'
450 MessagePlugin.success('上传成功,请保存设置')
451 }
452 homeLoading.value = false
453}
454
455async function onUpload(target) {
456 const input = target === 'logo' ? logoInput.value : faviconInput.value
457 if (!input?.files?.length) return
458 const file = input.files[0]
459 homeLoading.value = true
460 const r = await uploadHomeIcon(target, file)
461 input.value = ''
462 if (r.ok) {
463 const rel = target === 'logo' ? 'imsetes/upload_logo/home_logo.png' : 'imsetes/upload_logo/home_favicon.ico'
464 if (target === 'logo') homeForm.home_logo = rel
465 else homeForm.home_favicon = rel
466 MessagePlugin.success('上传成功,请保存设置')
467 }
468 homeLoading.value = false
469}
470
471async function saveHome() {
472 if (!/^#[0-9a-fA-F]{6}$/.test(homeForm.home_primary)) {
473 MessagePlugin.warning('主色调必须是 #rrggbb 格式')
474 return
475 }
476 homeLoading.value = true
477 const data = {
478 home_enable: homeForm.home_enable ? 'true' : 'false',
479 home_title: homeForm.home_title,
480 home_hero: homeForm.home_hero,
481 home_primary: homeForm.home_primary,
482 home_logo: homeForm.home_logo,
483 home_favicon: homeForm.home_favicon,
484 home_footer: homeForm.home_footer,
485 home_show_notice: homeForm.home_show_notice ? 'true' : 'false',
486 home_show_plans: homeForm.home_show_plans ? 'true' : 'false',
487 }
488 // 主题自定义字段
489 themeFields.forEach(f => {
490 data['home_ts_' + f.key] = f.type === 'switch' ? (themeValues[f.key] ? 'true' : 'false') : String(themeValues[f.key] || '')
491 })
492 const r = await setHome(data)
493 homeLoading.value = false
494 if (r.ok) MessagePlugin.success('保存成功,刷新前台页面查看效果')
495}
496</script>
497
498<style scoped>
499.td-theme-page code,
500.theme-code {
501 background: #f3f3f3;
502 padding: 1px 6px;
503 border-radius: 4px;
504 font-family: Consolas, Monaco, monospace;
505 font-size: 12px;
506 color: #d63384;
507 word-break: break-all;
508}
509.td-set-card-bd-table {
510 padding: 0;
511}
512.active-tags {
513 display: inline-flex;
514 gap: 4px;
515 justify-content: center;
516 flex-wrap: wrap;
517}
518.home-color-row {
519 display: flex;
520 align-items: center;
521 gap: 10px;
522}
523.home-color-picker {
524 width: 46px;
525 height: 34px;
526 padding: 2px;
527 border: 1px solid #d9d9d9;
528 border-radius: 6px;
529 background: #fff;
530 cursor: pointer;
531}
532.home-upload-row {
533 display: flex;
534 align-items: center;
535 gap: 10px;
536 margin-bottom: 8px;
537}
538.home-logo-preview {
539 width: 36px;
540 height: 36px;
541 object-fit: contain;
542 border: 1px solid #e5e7eb;
543 border-radius: 8px;
544 background: #fff;
545}
546.home-logo-empty {
547 color: #9ca3af;
548 font-size: 13px;
549 border: 1px dashed #e5e7eb;
550 border-radius: 8px;
551 padding: 6px 12px;
552}
553.home-image-preview {
554 width: 140px;
555 height: 88px;
556 object-fit: cover;
557 border: 1px solid #e5e7eb;
558 border-radius: 8px;
559 background: #f8f9fa;
560}
561</style>