template
This commit is contained in:
parent
ed60c36fa1
commit
ac2b203f37
@ -2,4 +2,32 @@
|
|||||||
<div>
|
<div>
|
||||||
<NuxtPage />
|
<NuxtPage />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<!-- <script setup>
|
||||||
|
const props = defineProps({
|
||||||
|
category: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
id_category: {
|
||||||
|
type: Number,
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
}) -->
|
||||||
|
|
||||||
|
// const templates = ref([])
|
||||||
|
|
||||||
|
// const fetchTemplates = async () => {
|
||||||
|
// try {
|
||||||
|
// templates.value = await $fetch(`http://localhost:8000/api/templates/category/${props.id_category}`)
|
||||||
|
// } catch (error) {
|
||||||
|
// console.error('Gagal ambil template:', error)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// onMounted(() => {
|
||||||
|
// fetchTemplates()
|
||||||
|
// })
|
||||||
|
|
||||||
|
// defineEmits(['back']);
|
@ -1,50 +1,89 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<div class="mb-8">
|
<LandingPageHeader />
|
||||||
<NuxtLink
|
|
||||||
to="/"
|
|
||||||
class="text-blue-600 hover:text-blue-800 font-semibold inline-flex items-center"
|
|
||||||
>
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-2" viewBox="0 0 20 20" fill="currentColor">
|
|
||||||
<path fill-rule="evenodd" d="M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z" clip-rule="evenodd" />
|
|
||||||
</svg>
|
|
||||||
Kembali ke Beranda
|
|
||||||
</NuxtLink>
|
|
||||||
</div>
|
|
||||||
<h1 class="text-3xl md:text-4xl font-bold text-center text-gray-800">
|
|
||||||
Pilih Template Favoritmu
|
|
||||||
</h1>
|
|
||||||
<p class="mt-2 text-center text-gray-500">
|
|
||||||
"Tersedia berbagai desain undangan pernikahan, khitan, ulang tahun, dan lainnya."
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="mt-12 grid grid-cols-1 md:grid-cols-3 gap-8">
|
<main class="container mx-auto px-4 py-16 md:py-20">
|
||||||
<div
|
|
||||||
v-for="category in categories"
|
<div class="mb-8">
|
||||||
:key="category.id"
|
<NuxtLink
|
||||||
@click="onCategoryClick(category.nama)"
|
to="/"
|
||||||
class="group cursor-pointer overflow-hidden rounded-lg shadow-lg hover:shadow-2xl transition-all duration-300"
|
class="text-blue-600 hover:text-blue-800 font-semibold inline-flex items-center"
|
||||||
>
|
>
|
||||||
<img :src="category.foto" :alt="category.nama" class="w-full h-48 object-cover group-hover:scale-110 transition-transform duration-300">
|
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-2" viewBox="0 0 20 20" fill="currentColor">
|
||||||
<div class="p-6 bg-white">
|
<path fill-rule="evenodd" d="M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z" clip-rule="evenodd" />
|
||||||
<h3 class="text-xl font-semibold text-gray-800">{{ category.nama }}</h3>
|
</svg>
|
||||||
|
Kembali ke Beranda
|
||||||
|
</NuxtLink>
|
||||||
|
</div>
|
||||||
|
<h1 class="text-3xl md:text-4xl font-bold text-center text-gray-800">
|
||||||
|
Pilih Template Favoritmu
|
||||||
|
</h1>
|
||||||
|
<p class="mt-2 text-center text-gray-500">
|
||||||
|
"Tersedia berbagai desain undangan pernikahan, khitan, ulang tahun, dan lainnya."
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="mt-12">
|
||||||
|
<div v-if="isLoading" class="text-center text-gray-500">
|
||||||
|
<p>Memuat kategori...</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else-if="error" class="text-center text-red-500 bg-red-100 p-4 rounded-lg">
|
||||||
|
<p><strong>Oops, terjadi kesalahan:</strong></p>
|
||||||
|
<p>{{ error }}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else>
|
||||||
|
<div v-if="categories.length > 0" class="grid grid-cols-1 md:grid-cols-3 gap-8">
|
||||||
|
<div
|
||||||
|
v-for="category in categories"
|
||||||
|
:key="category.id"
|
||||||
|
@click="onCategoryClick(category.nama)"
|
||||||
|
class="group cursor-pointer overflow-hidden rounded-lg shadow-lg hover:shadow-2xl transition-all duration-300"
|
||||||
|
>
|
||||||
|
<img :src="category.foto" :alt="category.nama" class="w-full h-48 object-cover group-hover:scale-110 transition-transform duration-300">
|
||||||
|
<div class="p-6 bg-white">
|
||||||
|
<h3 class="text-xl font-semibold text-gray-800">{{ category.nama }}</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div v-else class="text-center text-gray-500">
|
||||||
|
<p>Saat ini belum ada kategori yang tersedia.</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<Footer />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
|
import LandingPageHeader from '~/components/landing-page/header.vue';
|
||||||
|
import Footer from '~/components/landing-page/footer.vue';
|
||||||
|
|
||||||
const emit = defineEmits(['category-selected']);
|
const emit = defineEmits(['category-selected']);
|
||||||
|
|
||||||
const categories = ref([])
|
const categories = ref([]);
|
||||||
|
// State baru untuk loading dan error
|
||||||
|
const isLoading = ref(true);
|
||||||
|
const error = ref(null);
|
||||||
|
|
||||||
// Ambil data kategori dari Laravel API pakai $fetch
|
|
||||||
const fetchCategories = async () => {
|
const fetchCategories = async () => {
|
||||||
|
// Reset state sebelum fetch
|
||||||
|
isLoading.value = true;
|
||||||
|
error.value = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
categories.value = await $fetch('http://localhost:8000/api/kategoris')
|
const data = await $fetch('http://localhost:8000/api/kategoris');
|
||||||
} catch (error) {
|
categories.value = data;
|
||||||
console.error('Gagal ambil kategori:', error)
|
} catch (err) {
|
||||||
|
console.error('Gagal ambil kategori:', err);
|
||||||
|
// Set pesan error yang akan ditampilkan ke pengguna
|
||||||
|
error.value = 'Tidak dapat terhubung ke server. Silakan coba lagi nanti.';
|
||||||
|
} finally {
|
||||||
|
// Set loading ke false setelah selesai (baik sukses maupun gagal)
|
||||||
|
isLoading.value = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,6 +92,8 @@ const onCategoryClick = (categoryName) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
fetchCategories()
|
fetchCategories();
|
||||||
})
|
});
|
||||||
</script>
|
// Cukup satu baris ini untuk mengambil data dan mengelola semua state!
|
||||||
|
// const { data: categories, pending: isLoading, error } = await useFetch('http://localhost:8000/api/kategoris');
|
||||||
|
</script>
|
@ -1,25 +1,80 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<div class="flex items-center mb-8">
|
<LandingPageHeader />
|
||||||
<button @click="$emit('back')" class="text-blue-600 hover:text-blue-800 font-semibold mr-4">
|
|
||||||
← Kembali ke Kategori
|
<main class="container mx-auto px-4 py-16 md:py-20">
|
||||||
</button>
|
<div class="flex items-center mb-8">
|
||||||
<h1 class="text-3xl md:text-4xl font-bold text-gray-800">
|
<button
|
||||||
Pilih Template {{ category }} Favoritmu
|
@click="$emit('back')"
|
||||||
</h1>
|
class="text-blue-600 hover:text-blue-800 font-semibold inline-flex items-center mr-4"
|
||||||
</div>
|
>
|
||||||
|
<svg
|
||||||
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-6">
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
<div v-for="tpl in templates" :key="tpl.id" class="border rounded-lg p-4 text-center">
|
class="h-5 w-5 mr-1"
|
||||||
<img :src="tpl.foto" :alt="tpl.nama" class="bg-gray-200 h-40 mb-4 rounded-md object-cover w-full" />
|
viewBox="0 0 20 20"
|
||||||
<h4 class="font-semibold">{{ tpl.nama }}</h4>
|
fill="currentColor"
|
||||||
<p class="text-gray-500">Rp {{ tpl.harga }}</p>
|
>
|
||||||
|
<path
|
||||||
|
fill-rule="evenodd"
|
||||||
|
d="M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z"
|
||||||
|
clip-rule="evenodd"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
Kembali
|
||||||
|
</button>
|
||||||
|
<h1 class="text-3xl md:text-4xl font-bold text-gray-800">
|
||||||
|
Template {{ category }}
|
||||||
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
<!-- Loading -->
|
||||||
|
<div v-if="isLoading" class="text-center py-10">
|
||||||
|
<p>Memuat template...</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Error -->
|
||||||
|
<div v-else-if="error" class="text-center py-10 text-red-600">
|
||||||
|
<p>Gagal memuat template. Silakan coba lagi.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Data Ada -->
|
||||||
|
<div
|
||||||
|
v-else-if="templates && templates.length > 0"
|
||||||
|
class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-6"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
v-for="tpl in templates"
|
||||||
|
:key="tpl.id"
|
||||||
|
class="border rounded-lg overflow-hidden shadow hover:shadow-lg transition-shadow"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
:src="`http://localhost:8000/storage/${tpl.foto}`"
|
||||||
|
:alt="tpl.nama_template"
|
||||||
|
class="bg-gray-200 h-48 w-full object-cover"
|
||||||
|
/>
|
||||||
|
<div class="p-4">
|
||||||
|
<h4 class="font-semibold truncate">{{ tpl.nama_template }}</h4>
|
||||||
|
<p class="text-gray-500">
|
||||||
|
Rp {{ Number(tpl.harga ?? 0).toLocaleString('id-ID') }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Data Kosong -->
|
||||||
|
<div v-else class="text-center py-10 text-gray-500">
|
||||||
|
<p>Belum ada template untuk kategori ini.</p>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<Footer />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
|
import LandingPageHeader from '~/components/landing-page/header.vue'
|
||||||
|
import Footer from '~/components/landing-page/footer.vue'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
category: {
|
category: {
|
||||||
type: String,
|
type: String,
|
||||||
@ -27,23 +82,21 @@ const props = defineProps({
|
|||||||
},
|
},
|
||||||
id_category: {
|
id_category: {
|
||||||
type: Number,
|
type: Number,
|
||||||
required: true
|
required: true,
|
||||||
}
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const templates = ref([])
|
defineEmits(['back'])
|
||||||
|
|
||||||
const fetchTemplates = async () => {
|
// Panggil API Laravel
|
||||||
try {
|
const {
|
||||||
templates.value = await $fetch(`http://localhost:8000/api/templates/category/${props.id_category}`)
|
data: templates,
|
||||||
} catch (error) {
|
pending: isLoading,
|
||||||
console.error('Gagal ambil template:', error)
|
error,
|
||||||
}
|
} =
|
||||||
}
|
useFetch(() => `/api/templates?kategori_id=${props.id_category}`, {
|
||||||
|
baseURL: 'http://localhost:8000',
|
||||||
onMounted(() => {
|
key: () => `templates-${props.id_category}`,
|
||||||
fetchTemplates()
|
transform: (res) => res ?? []
|
||||||
})
|
})
|
||||||
|
|
||||||
defineEmits(['back']);
|
|
||||||
</script>
|
</script>
|
||||||
|
@ -1,27 +1,33 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="container mx-auto px-4 py-16">
|
<div>
|
||||||
<TemplatePageCategorySelection
|
<main class="container mx-auto px-4 py-16">
|
||||||
v-if="!selectedCategory"
|
<TemplatePageCategorySelection
|
||||||
@category-selected="handleCategorySelect"
|
v-if="!selectedCategory"
|
||||||
/>
|
@category-selected="handleCategorySelect"
|
||||||
|
/>
|
||||||
|
|
||||||
<TemplatePageTemplateGrid
|
<TemplatePageTemplateGrid
|
||||||
v-else
|
v-else
|
||||||
:category="selectedCategory"
|
:id_category="selectedCategory.id"
|
||||||
@back="goBack"
|
:category="selectedCategory.nama"
|
||||||
/>
|
@back="goBack"
|
||||||
|
/>
|
||||||
|
</main>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
|
// 1. Impor komponen anak yang Anda gunakan
|
||||||
|
import TemplatePageCategorySelection from '~/components/template-page/CategorySelection.vue'; // Pastikan path ini benar
|
||||||
|
import TemplatePageTemplateGrid from '~/components/template-page/TemplateGrid.vue'; // Pastikan path ini benar
|
||||||
|
|
||||||
// State untuk menyimpan kategori yang sedang dipilih
|
// 2. State untuk menyimpan SELURUH OBJEK kategori yang dipilih
|
||||||
const selectedCategory = ref(null);
|
const selectedCategory = ref(null);
|
||||||
|
|
||||||
// Fungsi ini akan menangkap event dari CategorySelection
|
// Fungsi ini sekarang akan menerima seluruh objek { id, nama }
|
||||||
const handleCategorySelect = (categoryName) => {
|
const handleCategorySelect = (categoryObject) => {
|
||||||
selectedCategory.value = categoryName;
|
selectedCategory.value = categoryObject;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Fungsi ini akan menangkap event 'back' dari TemplateGrid
|
// Fungsi ini akan menangkap event 'back' dari TemplateGrid
|
||||||
|
Loading…
Reference in New Issue
Block a user