2026-08-20 06:20:16 +07:00
|
|
|
<script setup lang="ts">
|
|
|
|
|
/** FR-10 UI — หน้าหลัก: card รายการ template ที่ active ให้เลือกสร้างเอกสาร */
|
|
|
|
|
import type { TemplateListItem } from '~/types/api'
|
|
|
|
|
|
|
|
|
|
const { apiJson } = useApi()
|
|
|
|
|
|
|
|
|
|
const templates = ref<TemplateListItem[]>([])
|
|
|
|
|
const loading = ref(true)
|
|
|
|
|
const error = ref<string | null>(null)
|
|
|
|
|
|
|
|
|
|
onMounted(async () => {
|
|
|
|
|
try {
|
|
|
|
|
templates.value = (await apiJson<TemplateListItem[]>('/api/templates')) ?? []
|
|
|
|
|
} catch (err) {
|
|
|
|
|
error.value = err instanceof Error ? err.message : 'โหลดรายการ template ไม่สำเร็จ'
|
|
|
|
|
} finally {
|
|
|
|
|
loading.value = false
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
</script>
|
|
|
|
|
|
2026-08-18 12:52:40 +07:00
|
|
|
<template>
|
2026-08-20 06:20:16 +07:00
|
|
|
<AuthGate>
|
2026-08-20 21:34:45 +07:00
|
|
|
<section class="space-y-6 sm:space-y-8">
|
2026-08-20 06:20:16 +07:00
|
|
|
<div>
|
2026-08-20 21:34:45 +07:00
|
|
|
<div class="h-1 w-10 rounded-pill bg-accent" aria-hidden="true" />
|
|
|
|
|
<h1 class="mt-3 text-display">สร้างเอกสารจาก template</h1>
|
|
|
|
|
<p class="mt-2 text-body-lg text-muted">
|
2026-08-20 06:20:16 +07:00
|
|
|
เลือก template กรอกค่า fields แล้วดาวน์โหลด .docx ที่เป็น <strong>version 1</strong> พร้อม metadata
|
|
|
|
|
ไว้เปิดต่อใน Word พร้อม add-in
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-08-20 21:34:45 +07:00
|
|
|
<div v-if="loading" class="flex items-center gap-3 py-10 text-sm text-muted">
|
|
|
|
|
<span class="spinner" />
|
2026-08-20 06:20:16 +07:00
|
|
|
กำลังโหลดรายการ template…
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<AlertBox v-else-if="error" type="error">{{ error }}</AlertBox>
|
|
|
|
|
|
2026-08-20 21:34:45 +07:00
|
|
|
<div v-else-if="templates.length === 0" class="empty-state">
|
2026-08-20 06:20:16 +07:00
|
|
|
ยังไม่มี template — ไปที่
|
2026-08-20 21:34:45 +07:00
|
|
|
<NuxtLink to="/templates/new" class="link">สร้าง template ตัวแรก</NuxtLink>
|
2026-08-20 06:20:16 +07:00
|
|
|
</div>
|
|
|
|
|
|
2026-08-20 21:34:45 +07:00
|
|
|
<div v-else class="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
|
2026-08-20 11:15:04 +07:00
|
|
|
<div
|
2026-08-20 06:20:16 +07:00
|
|
|
v-for="t in templates"
|
|
|
|
|
:key="t.id"
|
2026-08-20 21:34:45 +07:00
|
|
|
class="card flex flex-col p-5 transition hover:border-primary/50 hover:shadow-soft-lg"
|
2026-08-20 06:20:16 +07:00
|
|
|
>
|
2026-08-20 11:15:04 +07:00
|
|
|
<NuxtLink :to="`/documents/create/${t.id}`" class="flex-1">
|
|
|
|
|
<h2 class="font-semibold">{{ t.name }}</h2>
|
2026-08-20 21:34:45 +07:00
|
|
|
<p class="mt-1 line-clamp-2 min-h-10 text-sm text-muted">
|
2026-08-20 11:15:04 +07:00
|
|
|
{{ t.description ?? '—' }}
|
|
|
|
|
</p>
|
2026-08-20 21:34:45 +07:00
|
|
|
<p class="mt-3 text-xs text-muted">
|
2026-08-20 11:15:04 +07:00
|
|
|
{{ t.fieldCount }} fields · อัปเดต {{ formatDateTime(t.updatedAt) }}
|
|
|
|
|
</p>
|
|
|
|
|
</NuxtLink>
|
2026-08-20 21:34:45 +07:00
|
|
|
<div class="mt-auto flex gap-4 border-t border-line pt-3 text-xs">
|
|
|
|
|
<NuxtLink :to="`/documents/create/${t.id}`" class="link">สร้างเอกสาร →</NuxtLink>
|
|
|
|
|
<NuxtLink :to="`/templates/${t.id}/documents`" class="text-muted hover:text-primary hover:underline">
|
2026-08-20 11:15:04 +07:00
|
|
|
ดูเอกสารที่สร้างแล้ว
|
|
|
|
|
</NuxtLink>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-08-20 06:20:16 +07:00
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
</AuthGate>
|
2026-08-18 12:52:40 +07:00
|
|
|
</template>
|