2026-03-26 12:04:02 +08:00
|
|
|
|
<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">
|
2026-05-18 09:46:11 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 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.
|
|
|
|
|
|
*/
|
2026-03-26 12:04:02 +08:00
|
|
|
|
import { computed } from 'vue'
|
|
|
|
|
|
|
2026-05-23 18:44:57 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 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.
|
|
|
|
|
|
*/
|
2026-03-26 12:04:02 +08:00
|
|
|
|
const props = withDefaults(defineProps<{
|
|
|
|
|
|
savedAt?: number | null
|
|
|
|
|
|
disabled?: boolean
|
|
|
|
|
|
showClear?: boolean
|
|
|
|
|
|
}>(), {
|
|
|
|
|
|
savedAt: null,
|
|
|
|
|
|
disabled: false,
|
|
|
|
|
|
showClear: true
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
defineEmits<{
|
|
|
|
|
|
(event: 'save'): void
|
|
|
|
|
|
(event: 'clear'): void
|
|
|
|
|
|
}>()
|
|
|
|
|
|
|
2026-05-18 09:46:11 +08:00
|
|
|
|
/** formattedSavedAt is a reactive state variable used by the template and event handlers. */
|
2026-03-26 12:04:02 +08:00
|
|
|
|
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>
|