Files
printerCentral/app/components/templates/TemplateCard.vue
josedario87 c7c32d8c54 feat: Variables programáticas en templates
Permite definir variables en templates con sintaxis {{nombre🏷️default}}
- Auto-detección de variables al guardar templates
- Drawer para completar valores al cargar template con variables
- Badge mostrando cantidad de variables en tarjeta de template
- Resolución de variables antes de cargar en cola
2025-11-25 01:57:24 -06:00

84 lines
2.2 KiB
Vue

<script setup lang="ts">
import type { PrintTemplate } from '~/composables/useTemplates'
const props = defineProps<{
template: PrintTemplate
}>()
const emit = defineEmits<{
load: [id: string]
duplicate: [id: string]
delete: [id: string]
}>()
const menuItems = computed(() => [
[
{
label: 'Duplicar',
icon: 'i-heroicons-document-duplicate',
click: () => emit('duplicate', props.template.id)
}
],
[
{
label: 'Eliminar',
icon: 'i-heroicons-trash',
color: 'error' as const,
click: () => emit('delete', props.template.id)
}
]
])
function formatDate(date: string | number) {
return new Date(date).toLocaleDateString('es-AR', {
day: '2-digit',
month: 'short',
year: 'numeric'
})
}
</script>
<template>
<UCard variant="outline" class="hover:border-primary-500 dark:hover:border-primary-400 transition-colors">
<div class="flex items-start justify-between gap-2">
<div class="min-w-0 flex-1">
<h3 class="font-medium text-gray-900 dark:text-white truncate">
{{ template.name }}
</h3>
<p
v-if="template.description"
class="text-sm text-gray-500 dark:text-gray-400 line-clamp-2 mt-1"
>
{{ template.description }}
</p>
<div class="flex items-center gap-2 mt-2 flex-wrap">
<UBadge variant="subtle" size="xs">
{{ template.operations.length }} comandos
</UBadge>
<UBadge v-if="template.variables?.length" variant="subtle" size="xs" color="primary">
{{ template.variables.length }} {{ template.variables.length === 1 ? 'variable' : 'variables' }}
</UBadge>
<span class="text-xs text-gray-400 dark:text-gray-500">
{{ formatDate(template.updatedAt) }}
</span>
</div>
</div>
<UDropdownMenu :items="menuItems">
<UButton icon="i-heroicons-ellipsis-vertical" variant="ghost" size="sm" />
</UDropdownMenu>
</div>
<template #footer>
<UButton
icon="i-heroicons-play"
color="primary"
block
@click="$emit('load', template.id)"
>
Cargar en cola
</UButton>
</template>
</UCard>
</template>