功能:为编辑表单增加前端暂存

This commit is contained in:
xiaowang
2026-03-26 12:04:02 +08:00
parent b4042b3560
commit 35c605d871
14 changed files with 867 additions and 92 deletions
+62
View File
@@ -0,0 +1,62 @@
<template>
<div class="draft-actions">
<a-space wrap>
<a-button size="small" @click="$emit('save')" :disabled="disabled">
暂存
</a-button>
<a-button v-if="showClear" size="small" type="link" @click="$emit('clear')" :disabled="disabled">
清除暂存
</a-button>
<span v-if="savedAt" class="draft-saved-at">
上次暂存:{{ formattedSavedAt }}
</span>
<span v-else class="draft-saved-at">
暂存仅保存在当前浏览器中
</span>
</a-space>
</div>
</template>
<script setup lang="ts">
import { computed } from 'vue'
const props = withDefaults(defineProps<{
savedAt?: number | null
disabled?: boolean
showClear?: boolean
}>(), {
savedAt: null,
disabled: false,
showClear: true
})
defineEmits<{
(event: 'save'): void
(event: 'clear'): void
}>()
const formattedSavedAt = computed(() => {
if (!props.savedAt) {
return ''
}
const date = new Date(props.savedAt)
const year = date.getFullYear()
const month = `${date.getMonth() + 1}`.padStart(2, '0')
const day = `${date.getDate()}`.padStart(2, '0')
const hour = `${date.getHours()}`.padStart(2, '0')
const minute = `${date.getMinutes()}`.padStart(2, '0')
return `${year}-${month}-${day} ${hour}:${minute}`
})
</script>
<style scoped>
.draft-actions {
margin-bottom: 12px;
}
.draft-saved-at {
color: #8c8c8c;
font-size: 12px;
line-height: 24px;
}
</style>