feat: 自动保存条常驻显示——打开页面即可见(原 idle 态整条隐藏导致看不到)+ idle 提示「自动保存已开启」+ 立即保存按钮全程可点(idle/未保存/已保存均可点,保存中隐藏)
Release new versions / docker-release (push) Canceled after 0s
Release new versions / github-release (push) Canceled after 0s

This commit is contained in:
jinghui committed 2026-11-15 11:13:18 +08:00
1 parent 80a12ffbe1
commit 958e9039db
1 file changed
+54 -32
+54 -32
View File
@@ -27,43 +27,65 @@ async function onSave() {
saving.value = false;
}
}
/** 当前状态文案 —— 打开页面即常驻可见(idle = 自动保存已开启) */
const textLabel = computed(() => {
if (restored.value) return '已恢复上次未保存的内容';
switch (status.value) {
case 'dirty':
return '未保存';
case 'saving':
return '保存中…';
case 'error':
return '保存失败';
case 'saved':
return `已保存 ${timeLabel.value}`;
default:
return '自动保存已开启';
}
});
const chipClass = computed(() => ({
'as-restore': restored.value,
'as-dirty': !restored.value && status.value === 'dirty',
'as-saving': status.value === 'saving',
'as-error': status.value === 'error',
'as-saved': status.value === 'saved',
'as-idle': !restored.value && status.value === 'idle',
}));
const dotClass = computed(() => {
if (restored.value) return 'green';
switch (status.value) {
case 'dirty':
return 'orange';
case 'saving':
return 'gray blink';
case 'error':
return 'red';
default:
return 'green';
}
});
const btnLabel = computed(() => (status.value === 'error' ? '重试' : '立即保存'));
</script>
<template>
<div class="autosave-bar" :class="{ show: status !== 'idle' || restored }">
<!-- 已恢复上次内容 -->
<div v-if="restored" class="as-chip as-restore">
<span class="as-dot green" />
已恢复上次未保存的内容
</div>
<!-- 有未保存修改 -->
<div v-else-if="status === 'dirty'" class="as-chip as-dirty">
<span class="as-dot orange" />
<span class="as-text">未保存</span>
<button class="as-btn" :disabled="saving" @click="onSave">
{{ saving || status === 'saving' ? '保存中…' : '立即保存' }}
<!-- 常驻右下角:任何工具页打开即可见 -->
<div class="autosave-bar show">
<div class="as-chip" :class="chipClass">
<span class="as-dot" :class="dotClass" />
<span class="as-text">{{ textLabel }}</span>
<button
v-if="status !== 'saving'"
class="as-btn"
:disabled="saving"
@click="onSave"
>
{{ saving ? '保存中…' : btnLabel }}
</button>
</div>
<!-- 保存中 -->
<div v-else-if="status === 'saving'" class="as-chip as-saving">
<span class="as-dot gray blink" />
<span class="as-text">保存中…</span>
</div>
<!-- 保存失败 -->
<div v-else-if="status === 'error'" class="as-chip as-error">
<span class="as-dot red" />
<span class="as-text">保存失败</span>
<button class="as-btn" @click="onSave">重试</button>
</div>
<!-- 已保存 -->
<div v-else-if="status === 'saved'" class="as-chip as-saved">
<span class="as-dot green" />
<span class="as-text">已保存 {{ timeLabel }}</span>
</div>
</div>
</template>