From c17c54d6cea9cf34f413e0b92bf75d58e762118e Mon Sep 17 00:00:00 2001 From: Irwan Cahyono Date: Sun, 29 Jun 2025 23:17:13 +0700 Subject: [PATCH] update tema dan topik --- pages/content/themes/[id].vue | 7 +- pages/content/themes/add.vue | 7 +- pages/content/themes/list.vue | 10 +-- pages/content/topics/[id].vue | 121 ++++++++++++++++++++++++++++------ pages/content/topics/add.vue | 67 +++++++++++++++---- pages/content/topics/list.vue | 6 +- 6 files changed, 171 insertions(+), 47 deletions(-) diff --git a/pages/content/themes/[id].vue b/pages/content/themes/[id].vue index 2748c4c..b190e9c 100644 --- a/pages/content/themes/[id].vue +++ b/pages/content/themes/[id].vue @@ -2,20 +2,20 @@
-
Tambah Tema Konten
+
Edit Tema Konten
Daftar @@ -71,7 +71,6 @@ \ No newline at end of file diff --git a/pages/content/topics/add.vue b/pages/content/topics/add.vue index a6f603a..e82d8d4 100644 --- a/pages/content/topics/add.vue +++ b/pages/content/topics/add.vue @@ -59,13 +59,22 @@
-
-
- - +
+
+
+ × +
+ +
@@ -85,6 +94,7 @@ import { required } from '@vuelidate/validators'; import Multiselect from '@suadelabs/vue3-multiselect'; import '@suadelabs/vue3-multiselect/dist/vue3-multiselect.css'; + import '@/assets/css/file-upload-preview.css'; useHead({ title: 'Daftar Topik Konten' }); @@ -106,6 +116,8 @@ const $validate = useVuelidate(rules, { form }); const router = useRouter(); + const config = useRuntimeConfig(); + const params = reactive({ current_page: 1, pagesize: 10, @@ -114,7 +126,7 @@ }); const { data: themes } = await useAsyncData('themes', - () => $fetch('http://localhost:8000/content/themes/', { + () => $fetch(`${config.public.apiBase}content/themes/`, { params: { page: params.current_page, page_size: 50 @@ -124,6 +136,19 @@ } ); + onMounted(async () => { + const fileupload = await import('file-upload-with-preview'); + let FileUploadWithPreview = fileupload.default; + + // single image upload + new FileUploadWithPreview('featuredImage', { + images: { + baseImage: '/assets/images/file-preview.svg', + backgroundImage: '', + }, + }); + }); + const submitForm = async () => { isSubmitted.value = true; $validate.value.form.$touch(); @@ -131,14 +156,18 @@ return false; } - await $fetch('http://localhost:8000/content/topics/', { + const formData = new FormData(); + formData.append('topic', form.value.topic); + formData.append('theme', form.value.theme.id); + formData.append('description', form.value.description); + + if (form.value.featured_image) { + formData.append('featured_image', form.value.featured_image); + } + + await $fetch(`${config.public.apiBase}content/topics/`, { method: 'POST', - body: { - "theme": form.value.theme.id, - "topic": form.value.topic, - "description": form.value.description, - "featured_image": form.value.featured_image - } + body: formData }).then(() => { //redirect router.push({ path: "/content/topics/list" }); @@ -149,4 +178,18 @@ console.log(error); }); } + + function handleImageChange(event: { target: { files: any[]; }; }) { + const file = event.target.files[0] + + if (!file) return + + const allowed = ['image/png'] + if (!allowed.includes(file.type)) { + alert('Hanya PNG yang diizinkan') + return + } + + form.value.featured_image = file + } \ No newline at end of file diff --git a/pages/content/topics/list.vue b/pages/content/topics/list.vue index efaf029..fbfd494 100644 --- a/pages/content/topics/list.vue +++ b/pages/content/topics/list.vue @@ -67,6 +67,8 @@ const router = useRouter(); + const config = useRuntimeConfig(); + const cols = ref([ { field: 'topic', title: 'Topik' }, @@ -87,7 +89,7 @@ () => { console.log('asyncData'); console.log(params); - return $fetch('http://localhost:8000/content/topics/', { + return $fetch(`${config.public.apiBase}/content/topics/`, { params: { page: params.current_page, page_size: params.pagesize, @@ -119,7 +121,7 @@ const deleteData = async (data: any) => { //delete data with API - await $fetch(`http://localhost:8000/content/topics/${data.id}/`, { + await $fetch(`${config.public.apiBase}content/topics/${data.id}/`, { method: 'DELETE' });