mirror of
https://github.com/skyle1995/NetworkAuth.git
synced 2026-05-25 02:24:05 +08:00
The development mode supports hot reloading of templates
This commit is contained in:
@@ -65,3 +65,9 @@ func GetStaticFS() (fs.FS, error) { // Go 顶级函数不支持箭头写法
|
||||
}
|
||||
return staticFS, nil
|
||||
}
|
||||
|
||||
// IsDevMode 检查是否为开发模式
|
||||
// 注意:这个函数保留用于向后兼容,建议使用 middleware.IsDevMode()
|
||||
func IsDevMode() bool {
|
||||
return viper.GetBool("server.dev_mode")
|
||||
}
|
||||
|
||||
@@ -226,10 +226,10 @@
|
||||
{
|
||||
field: 'status_name',
|
||||
title: '状态',
|
||||
width: 80,
|
||||
width: 100,
|
||||
templet: (d) => {
|
||||
if (d.status === 1) return '<span style="color: #5FB878;">启用</span>';
|
||||
return '<span style="color: #FF5722;">禁用</span>';
|
||||
const checked = d.status === 1 ? 'checked' : '';
|
||||
return `<input type="checkbox" ${checked} lay-skin="switch" lay-text="启用|禁用" lay-filter="api-status-switch" data-id="${d.id}">`;
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -626,6 +626,35 @@
|
||||
}
|
||||
});
|
||||
|
||||
// 接口状态switch开关事件监听
|
||||
form.on('switch(api-status-switch)', function(data) {
|
||||
const apiId = data.elem.getAttribute('data-id');
|
||||
const status = data.elem.checked ? 1 : 0;
|
||||
|
||||
$.ajax({
|
||||
url: '/admin/api/apis/update_status',
|
||||
type: 'POST',
|
||||
data: JSON.stringify({ id: parseInt(apiId), status: status }),
|
||||
contentType: 'application/json',
|
||||
success: function (res) {
|
||||
if (res.code === 0) {
|
||||
layer.msg(res.msg || '状态更新成功', { icon: 1 });
|
||||
} else {
|
||||
layer.msg(res.msg || '状态更新失败', { icon: 2 });
|
||||
// 如果更新失败,恢复开关状态
|
||||
data.elem.checked = !data.elem.checked;
|
||||
form.render('checkbox');
|
||||
}
|
||||
},
|
||||
error: function (xhr) {
|
||||
layer.msg(xhr.responseText || '状态更新失败', { icon: 2 });
|
||||
// 如果更新失败,恢复开关状态
|
||||
data.elem.checked = !data.elem.checked;
|
||||
form.render('checkbox');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
@@ -374,8 +374,8 @@
|
||||
title: '应用状态',
|
||||
width: 100,
|
||||
templet: (d) => {
|
||||
if (d.status === 1) return '<span style="color: #5FB878;">启用</span>';
|
||||
return '<span style="color: #FF5722;">禁用</span>';
|
||||
const checked = d.status === 1 ? 'checked' : '';
|
||||
return `<input type="checkbox" name="app-status-${d.id}" lay-skin="switch" lay-text="启用|禁用" ${checked} lay-filter="app-status-switch" data-id="${d.id}">`;
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -1195,6 +1195,35 @@
|
||||
});
|
||||
});
|
||||
|
||||
// 应用状态switch开关事件监听
|
||||
form.on('switch(app-status-switch)', function(data) {
|
||||
const appId = data.elem.getAttribute('data-id');
|
||||
const status = data.elem.checked ? 1 : 0;
|
||||
|
||||
$.ajax({
|
||||
url: '/admin/api/apps/update_status',
|
||||
type: 'POST',
|
||||
data: JSON.stringify({ id: parseInt(appId), status: status }),
|
||||
contentType: 'application/json',
|
||||
success: function (res) {
|
||||
if (res.code === 0) {
|
||||
layer.msg(res.msg || '状态更新成功', { icon: 1 });
|
||||
} else {
|
||||
layer.msg(res.msg || '状态更新失败', { icon: 2 });
|
||||
// 如果更新失败,恢复开关状态
|
||||
data.elem.checked = !data.elem.checked;
|
||||
form.render('checkbox');
|
||||
}
|
||||
},
|
||||
error: function (xhr) {
|
||||
layer.msg(xhr.responseText || '状态更新失败', { icon: 2 });
|
||||
// 如果更新失败,恢复开关状态
|
||||
data.elem.checked = !data.elem.checked;
|
||||
form.render('checkbox');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Tips提示功能已移至admin.js统一管理
|
||||
});
|
||||
});
|
||||
|
||||
@@ -11,25 +11,31 @@
|
||||
<tbody>
|
||||
<tr>
|
||||
<td style="width: 120px; font-weight: bold;">程序版本</td>
|
||||
<td><span style="font-size: 18px; font-weight: bold; color: var(--lay-color-normal);">{{ .Version }}</span></td>
|
||||
<td style="height: 20px; vertical-align: middle;">
|
||||
<span class="layui-badge layui-bg-blue" style="font-size: 14px; padding: 2px 8px; line-height: 1.2;">v{{ .Version }}</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="font-weight: bold;">存储方案</td>
|
||||
<td><span style="font-size: 18px; font-weight: bold; color: var(--lay-color-info);">{{ .DBType }}</span></td>
|
||||
<td style="height: 20px; vertical-align: middle;">
|
||||
<span class="layui-badge layui-bg-cyan" style="font-size: 14px; padding: 2px 8px; line-height: 1.2;">{{ .DBType }}</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="font-weight: bold;">开发模式</td>
|
||||
<td>
|
||||
<td style="height: 20px; vertical-align: middle;">
|
||||
{{ if .Mode }}
|
||||
<span style="font-size: 18px; font-weight: bold; color: var(--lay-color-danger);">开启</span>
|
||||
<span class="layui-badge layui-bg-orange" style="font-size: 14px; padding: 2px 8px; line-height: 1.2;">开启</span>
|
||||
{{ else }}
|
||||
<span style="font-size: 18px; font-weight: bold; color: var(--lay-color-success);">关闭</span>
|
||||
<span class="layui-badge layui-bg-green" style="font-size: 14px; padding: 2px 8px; line-height: 1.2;">关闭</span>
|
||||
{{ end }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="font-weight: bold;">运行时长</td>
|
||||
<td><span id="uptime-display" style="font-size: 18px; font-weight: bold; color: var(--lay-color-normal);">{{ .Uptime }}</span></td>
|
||||
<td style="height: 20px; vertical-align: middle;">
|
||||
<span id="uptime-display" class="layui-badge layui-bg-gray" style="font-size: 14px; padding: 2px 8px; line-height: 1.2;">{{ .Uptime }}</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -46,19 +52,27 @@
|
||||
<tbody>
|
||||
<tr>
|
||||
<td style="width: 120px; font-weight: bold;">全部应用</td>
|
||||
<td><span id="total-apps" style="font-size: 18px; font-weight: bold;">0</span></td>
|
||||
<td style="height: 20px; vertical-align: middle;">
|
||||
<span id="total-apps" class="layui-badge" style="font-size: 14px; padding: 2px 8px; min-width: 30px; text-align: center; line-height: 1.2;">0</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="font-weight: bold;">启用应用</td>
|
||||
<td><span id="enabled-apps" style="font-size: 18px; font-weight: bold; color: var(--lay-color-success);">0</span></td>
|
||||
<td style="height: 20px; vertical-align: middle;">
|
||||
<span id="enabled-apps" class="layui-badge layui-bg-green" style="font-size: 14px; padding: 2px 8px; min-width: 30px; text-align: center; line-height: 1.2;">0</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="font-weight: bold;">禁用应用</td>
|
||||
<td><span id="disabled-apps" style="font-size: 18px; font-weight: bold; color: var(--lay-color-danger);">0</span></td>
|
||||
<td style="height: 20px; vertical-align: middle;">
|
||||
<span id="disabled-apps" class="layui-badge layui-bg-orange" style="font-size: 14px; padding: 2px 8px; min-width: 30px; text-align: center; line-height: 1.2;">0</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="font-weight: bold;">变量数量</td>
|
||||
<td><span id="total-variables" style="font-size: 18px; font-weight: bold; color: var(--lay-color-info);">0</span></td>
|
||||
<td style="height: 20px; vertical-align: middle;">
|
||||
<span id="total-variables" class="layui-badge layui-bg-blue" style="font-size: 14px; padding: 2px 8px; min-width: 30px; text-align: center; line-height: 1.2;">0</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -98,9 +112,19 @@
|
||||
$.get('/admin/api/system/info', (res) => {
|
||||
if (res && res.code === 0 && res.data) {
|
||||
const data = res.data;
|
||||
// 更新运行时长
|
||||
// 更新运行时长,保持徽章样式
|
||||
if (data.uptime) {
|
||||
$('#uptime-display').text(data.uptime);
|
||||
const uptimeElement = $('#uptime-display');
|
||||
uptimeElement.text(data.uptime);
|
||||
// 确保徽章样式保持一致
|
||||
if (!uptimeElement.hasClass('layui-badge')) {
|
||||
uptimeElement.addClass('layui-badge layui-bg-gray');
|
||||
uptimeElement.css({
|
||||
'font-size': '14px',
|
||||
'padding': '2px 8px',
|
||||
'line-height': '1.2'
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}).fail(() => {
|
||||
|
||||
Reference in New Issue
Block a user