better-staridc-MNBT
1<?php
2if (!defined('IN_CRONLITE')) { exit; }
3mnbt_admin_include('head');
4$fields = ['site_title','site_logo','site_primary','site_accent','site_hero','site_footer','site_favicon'];
5$values = [];
6foreach ($fields as $f) {
7 $values[$f] = shop_frontend_option($f, '');
8}
9// 颜色只接受 #rrggbb;未设置时给默认值(主色默认蓝色)
10$primary = preg_match('/^#[0-9a-fA-F]{6}$/', (string)$values['site_primary']) ? strtolower($values['site_primary']) : '#4f46e5';
11$accent = preg_match('/^#[0-9a-fA-F]{6}$/', (string)$values['site_accent']) ? strtolower($values['site_accent']) : '#ff5722';
12?>
13<div class="container-fluid" style="padding:20px;">
14 <div style="margin-bottom:16px;border-radius:10px;overflow:hidden;border:1px solid #e6e8f0;line-height:0;">
15 <img src="<?= shop_frontend_asset_url('ad3.webp') ?>" alt="广告" style="display:block;width:100%;height:auto;">
16 </div>
17<div class="card">
18 <div class="card-header bg-info"><h4>售卖前端设置</h4></div>
19 <div class="card-body">
20 <div class="alert alert-info">配置售卖网站首页与用户端页面的显示内容。保存后刷新前台页面即可生效。</div>
21 <form id="settingsForm">
22 <div class="form-group">
23 <label>站点标题</label>
24 <input class="form-control" name="site_title" value="<?=htmlspecialchars($values['site_title'])?>" placeholder="MNBT 主机售卖">
25 </div>
26 <div class="form-group">
27 <label>站点 Logo(ICO,可上传)</label>
28 <div style="display:flex;align-items:center;gap:12px;flex-wrap:wrap;">
29 <img id="logo_preview" src="<?=htmlspecialchars($values['site_logo'])?>" alt="logo" style="width:32px;height:32px;object-fit:contain;border:1px solid #e5e7eb;border-radius:6px;background:#fff;<?= $values['site_logo'] ? '' : 'display:none;' ?>">
30 <input type="file" id="logo_file" accept=".ico,image/vnd.microsoft.icon,image/x-icon">
31 <button type="button" class="btn btn-primary" id="logo_upload_btn">上传 ICO</button>
32 <button type="button" class="btn btn-default" id="logo_clear_btn">移除 Logo</button>
33 </div>
34 <div style="margin-top:8px;">
35 <input type="text" class="form-control" name="site_logo" id="logo_value" value="<?=htmlspecialchars($values['site_logo'])?>" placeholder="上传后自动填入,或手动填写 Logo URL">
36 </div>
37 <small class="text-muted">仅支持 .ico 文件(2MB 内);上传后应用到首页顶栏与全部用户端页面</small>
38 </div>
39 <div class="form-group">
40 <label>站点 Favicon(ICO,可上传)</label>
41 <div style="display:flex;align-items:center;gap:12px;flex-wrap:wrap;">
42 <img id="favicon_preview" src="<?=htmlspecialchars($values['site_favicon'])?>" alt="favicon" style="width:24px;height:24px;object-fit:contain;border:1px solid #e5e7eb;border-radius:4px;background:#fff;<?= $values['site_favicon'] ? '' : 'display:none;' ?>">
43 <input type="file" id="favicon_file" accept=".ico,image/vnd.microsoft.icon,image/x-icon">
44 <button type="button" class="btn btn-primary" id="favicon_upload_btn">上传 ICO</button>
45 <button type="button" class="btn btn-default" id="favicon_clear_btn">移除 Favicon</button>
46 </div>
47 <div style="margin-top:8px;">
48 <input type="text" class="form-control" name="site_favicon" id="favicon_value" value="<?=htmlspecialchars($values['site_favicon'])?>" placeholder="上传后自动填入,或手动填写 Favicon URL">
49 </div>
50 <small class="text-muted">仅支持 .ico 文件(2MB 内);应用到浏览器标签页图标</small>
51 </div>
52 <div class="row">
53 <div class="col-md-6">
54 <div class="form-group">
55 <label>主色调 <small class="text-muted">(默认蓝色)</small></label>
56 <div style="display:flex;align-items:center;gap:10px;">
57 <input type="color" name="site_primary" id="site_primary" value="<?=htmlspecialchars($primary)?>" style="width:46px;height:34px;padding:2px;border:1px solid #ced4da;border-radius:4px;background:#fff;cursor:pointer;">
58 <input type="text" class="form-control" id="site_primary_hex" value="<?=htmlspecialchars($primary)?>" readonly style="max-width:110px;">
59 </div>
60 <small class="text-muted">点击色盘选择,应用到首页与全部用户端页面</small>
61 </div>
62 </div>
63 <div class="col-md-6">
64 <div class="form-group">
65 <label>强调色</label>
66 <div style="display:flex;align-items:center;gap:10px;">
67 <input type="color" name="site_accent" id="site_accent" value="<?=htmlspecialchars($accent)?>" style="width:46px;height:34px;padding:2px;border:1px solid #ced4da;border-radius:4px;background:#fff;cursor:pointer;">
68 <input type="text" class="form-control" id="site_accent_hex" value="<?=htmlspecialchars($accent)?>" readonly style="max-width:110px;">
69 </div>
70 <small class="text-muted">首页强调元素使用</small>
71 </div>
72 </div>
73 </div>
74 <div class="form-group">
75 <label>首页 Hero 标语</label>
76 <input class="form-control" name="site_hero" value="<?=htmlspecialchars($values['site_hero'])?>" placeholder="高性能虚拟主机,即买即用">
77 </div>
78 <div class="form-group">
79 <label>底部版权</label>
80 <input class="form-control" name="site_footer" value="<?=htmlspecialchars($values['site_footer'])?>" placeholder="© 2026 MNBT. All rights reserved.">
81 </div>
82 <button type="button" class="btn btn-primary" onclick="saveSettings()">保存设置</button>
83 </form>
84 </div>
85</div>
86</div>
87
88<script>
89document.getElementById('site_primary').addEventListener('input', function () { document.getElementById('site_primary_hex').value = this.value; });
90document.getElementById('site_accent').addEventListener('input', function () { document.getElementById('site_accent_hex').value = this.value; });
91
92function uploadIcon(target) {
93 var input = document.getElementById(target + '_file');
94 if (!input.files || !input.files.length) { alert('请先选择 .ico 文件'); return; }
95 var file = input.files[0];
96 if (!/\.ico$/i.test(file.name)) { alert('仅支持 ICO 格式'); return; }
97 var fd = new FormData();
98 fd.append('gn', 'shop_frontend_upload_icon');
99 fd.append('target', target);
100 fd.append('icon', file);
101 $.ajax({
102 url: './ajax.php',
103 type: 'POST',
104 data: fd,
105 processData: false,
106 contentType: false,
107 success: function (r) {
108 var j;
109 try { j = typeof r === 'string' ? JSON.parse(r) : r; } catch (e) { j = { code: '响应解析失败' }; }
110 if (j.url) {
111 $('#' + target + '_value').val(j.url);
112 $('#' + target + '_preview').attr('src', j.url).show();
113 msalert(1, j.code || '上传成功', 2000);
114 } else {
115 msalert(4, j.code || '上传失败', 2000);
116 }
117 },
118 error: function () { msalert(4, '网络错误,请重试', 2000); }
119 });
120}
121
122$('#logo_upload_btn').on('click', function () { uploadIcon('logo'); });
123$('#favicon_upload_btn').on('click', function () { uploadIcon('favicon'); });
124$('#logo_clear_btn').on('click', function () { $('#logo_value').val(''); $('#logo_preview').hide(); });
125$('#favicon_clear_btn').on('click', function () { $('#favicon_value').val(''); $('#favicon_preview').hide(); });
126
127function saveSettings() {
128 var data = {};
129 $('#settingsForm input').each(function(){ if ($(this).attr('name')) data[$(this).attr('name')] = $(this).val(); });
130 data.gn = 'shop_frontend_save_settings';
131 $.post('./ajax.php', data, function(r){
132 var j = JSON.parse(r);
133 msalert(j.code === '保存成功' ? 1 : 4, j.code || '保存失败', 2000);
134 });
135}
136</script>
137</body>
138</html>