Add demo mode factory reset
- Align the backend seeded default surgery template with the report editor's default report content. - Add backend demo defaults for the default template, Kimi provider, and Xunfei speech proxy configuration. - Change system reset into a super-admin demo mode factory reset that clears reports, audit logs, files, custom templates, and non-default users. - Keep only the default admin, manager, doctor, and default surgery template after demo reset. - Replace the old local-only reset all data button with a two-confirmation backend reset flow. - Add tests covering demo default alignment and database-backed demo reset behavior. - Update docs to describe demo mode reset semantics and production credential cautions.
This commit is contained in:
@@ -204,44 +204,22 @@ export default function SystemSettings() {
|
||||
};
|
||||
|
||||
const resetToDefault = async () => {
|
||||
if (window.confirm('确定要恢复系统设置出厂设置吗?所有自定义配置将被清除。')) {
|
||||
const defaultSettings: ISystemSettings & { frameMode?: 'uniform' | 'keep' } = {
|
||||
frameCount: 12,
|
||||
framePositions: [7.9, 9.3, 46.2, 49.1, 63.9, 64.8, 68.8, 73.7, 80.2, 85.0, 96.3, 98.6],
|
||||
defaultTemplate: templates[0]?.id || '',
|
||||
frameMode: 'keep',
|
||||
activeAiProvider: 'kimi',
|
||||
aiProviders: { ...DEFAULT_AI_PROVIDERS },
|
||||
autoInsertFrames: true,
|
||||
autoInsertDelay: 1,
|
||||
autoInsertFrameIndices: [0, 2, 4, 6, 8, 10],
|
||||
xfSpeechConfig: { appId: '', apiKey: '', apiSecret: '' }
|
||||
};
|
||||
try {
|
||||
const resetSettings = await resetSystemSettings();
|
||||
const normalized = normalizeSettings(resetSettings, templates);
|
||||
setSettings(normalized);
|
||||
storage.set('systemSettings', normalized);
|
||||
} catch (error) {
|
||||
if (!isLocalFallbackEnabled()) {
|
||||
alert(`重置失败: ${(error as Error).message}`);
|
||||
return;
|
||||
}
|
||||
console.warn('Reset settings API failed, keeping local compatibility path.', error);
|
||||
setSettings(defaultSettings);
|
||||
storage.set('systemSettings', defaultSettings);
|
||||
}
|
||||
}
|
||||
};
|
||||
const firstConfirm = window.confirm('确定要恢复演示出厂设置吗?这会清空报告、审计日志、自定义模板和非默认用户,并恢复默认演示账号、模板、AI/语音配置。');
|
||||
if (!firstConfirm) return;
|
||||
|
||||
const resetAllData = () => {
|
||||
if (!isLocalFallbackEnabled()) {
|
||||
alert('生产模式下仅允许清理当前浏览器缓存,请联系管理员执行后端数据维护。');
|
||||
return;
|
||||
}
|
||||
if (window.confirm('确定要重置全部数据吗?这将清除所有报告、模板和用户设置。')) {
|
||||
const secondConfirm = window.confirm('请再次确认:该操作会重置当前后端演示数据,且无法从页面撤销。是否继续?');
|
||||
if (!secondConfirm) return;
|
||||
|
||||
try {
|
||||
const resetSettings = await resetSystemSettings();
|
||||
const normalized = normalizeSettings(resetSettings, templates);
|
||||
setSettings(normalized);
|
||||
storage.set('systemSettings', normalized);
|
||||
localStorage.clear();
|
||||
sessionStorage.clear();
|
||||
window.location.reload();
|
||||
} catch (error) {
|
||||
alert(`恢复演示出厂设置失败: ${(error as Error).message}`);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -592,14 +570,7 @@ export default function SystemSettings() {
|
||||
onClick={resetToDefault}
|
||||
className="text-xs font-bold text-red-500 hover:text-red-600 transition-colors uppercase tracking-wider"
|
||||
>
|
||||
恢复系统设置出厂设置
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={resetAllData}
|
||||
className="text-xs font-bold text-red-500 hover:text-red-600 transition-colors uppercase tracking-wider"
|
||||
>
|
||||
重置全部数据
|
||||
恢复演示出厂设置
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user