Files
JayuCloud/FD-Frontend/src/components/DraftActions.vue
T
2026-06-15 15:53:55 +08:00

72 lines
1.9 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<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">
/**
* DraftActions page script.
* Call guide: the template binds the reactive state below, and the methods are triggered by button clicks, lifecycle hooks, or router events.
*/
import { computed } from 'vue'
/**
* Purpose: props supports DraftActions.vue by holding or executing the props page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const props = withDefaults(defineProps<{
savedAt?: number | null
disabled?: boolean
showClear?: boolean
}>(), {
savedAt: null,
disabled: false,
showClear: true
})
defineEmits<{
(event: 'save'): void
(event: 'clear'): void
}>()
/** formattedSavedAt is a reactive state variable used by the template and event handlers. */
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: var(--text-secondary);
font-size: 12px;
line-height: 24px;
}
</style>