v0.3.27: 全局事件开关下展示自定义消息模板,支持编辑标题和内容

This commit is contained in:
2026-05-17 18:49:15 +08:00
parent 71990554c4
commit 4131ccece9
34 changed files with 107 additions and 63 deletions

View File

@@ -529,6 +529,20 @@
<el-switch v-model="globalNotifyForm.events.on_cleanup" active-text="清理完成" />
</div>
<div class="form-tip" style="margin-top:8px;">全局推送作为兜底通道设置了推送用户的网盘配置走用户推送未设置的走全局推送</div>
<el-divider content-position="left">自定义消息模板</el-divider>
<div class="form-tip" style="margin-bottom:12px;">可用变量<code>{'{cloud_type}'}</code> <code>{'{nickname}'}</code> <code>{'{file_name}'}</code> <code>{'{file_size}'}</code> <code>{'{duration}'}</code> <code>{'{share_url}'}</code> <code>{'{fail_count}'}</code> <code>{'{error_message}'}</code></div>
<div v-for="(tpl, tkey) in globalNotifyForm.eventTemplates" :key="tkey" style="border:1px solid var(--el-border-color-light); border-radius:6px; padding:10px 14px; margin-bottom:10px;">
<div style="display:flex; align-items:center; gap:8px; margin-bottom:8px;">
<el-tag size="small" :type="globalNotifyForm.events[tkey] ? 'success' : 'info'">{{ tkey === 'on_save_success' ? '转存成功' : tkey === 'on_save_fail' ? '转存失败' : tkey === 'on_cookie_expire' ? 'Cookie过期' : '清理完成' }}</el-tag>
<el-switch v-model="globalNotifyForm.events[tkey]" size="small" />
</div>
<el-form-item label="标题" style="margin-bottom:6px;">
<el-input v-model="tpl.title" placeholder="消息标题,支持变量" style="max-width:500px" />
</el-form-item>
<el-form-item label="内容" style="margin-bottom:0;">
<el-input v-model="tpl.content" type="textarea" :rows="3" placeholder="消息内容,支持变量和 Markdown" style="max-width:500px" />
</el-form-item>
</div>
</el-form>
</div>
</el-collapse-item>
@@ -868,9 +882,14 @@ const enabledNotifyProviders = computed(() => {
return result
})
const globalNotifyForm = reactive<{ channels: Record<string, any>; events: Record<string, boolean> }>({
const globalNotifyForm = reactive<{ channels: Record<string, any>; events: Record<string, boolean>; eventTemplates: Record<string, { title: string; content: string }> }>({
channels: {},
events: { on_save_success: true, on_save_fail: true, on_cookie_expire: true, on_cleanup: false },
eventTemplates: {
on_save_success: { title: '✅ 转存成功', content: '**{cloud_type}** · {nickname}\n文件: {file_name}\n大小: {file_size}\n耗时: {duration}s\n链接: {share_url}' },
on_save_fail: { title: '❌ 转存连续失败 {fail_count} 次', content: '**{cloud_type}** · {nickname}\n连续失败次数: {fail_count}\n最后失败: {error_message}\n请检查网盘状态' },
on_cookie_expire: { title: '⚠️ Cookie 已过期', content: '**{cloud_type}** · {nickname}\nCookie 已过期或失效,请重新登录\n最后操作: {share_url}' },
},
})
function initPushUserChannelForm() {
@@ -1049,6 +1068,13 @@ async function loadGlobalNotifyConfig() {
globalNotifyForm.events.on_cookie_expire = parsed.events.on_cookie_expire !== false
globalNotifyForm.events.on_cleanup = parsed.events.on_cleanup === true
}
if (parsed.eventTemplates) {
for (const [ek, et] of Object.entries(parsed.eventTemplates)) {
if (globalNotifyForm.eventTemplates[ek]) {
globalNotifyForm.eventTemplates[ek] = et as any
}
}
}
} catch {}
}
} catch {}
@@ -1457,7 +1483,7 @@ async function handleSave() {
// Add global_notify_config as JSON entry
entries.push({
key: 'global_notify_config',
value: JSON.stringify({ channels, events: globalNotifyForm.events }),
value: JSON.stringify({ channels, events: globalNotifyForm.events, eventTemplates: globalNotifyForm.eventTemplates }),
})
await updateSystemConfigs(entries)
ElMessage.success('配置已保存')