show images after upload
This commit is contained in:
parent
6d43e3b8c7
commit
0a92835c30
3 changed files with 20 additions and 45 deletions
|
|
@ -11,5 +11,7 @@ fields:
|
|||
buttons: false
|
||||
size: small
|
||||
width: 1/2
|
||||
tags:
|
||||
type: tags
|
||||
# tags:
|
||||
# type: tags
|
||||
# type: tags
|
||||
|
|
|
|||
|
|
@ -10,11 +10,12 @@ return [
|
|||
|
||||
$alerts = [];
|
||||
$success = '';
|
||||
$newFiles = [];
|
||||
|
||||
foreach ($uploads->get('images') as $upload) {
|
||||
// check for duplicate
|
||||
$files = $page->files();
|
||||
$duplicates = $files->filter(function ($file) use ($upload) {
|
||||
// get original safename without prefix
|
||||
$pos = strpos($file->filename(), '_');
|
||||
$originalSafename = substr($file->filename(), $pos + 1);
|
||||
|
||||
|
|
@ -30,7 +31,7 @@ return [
|
|||
|
||||
try {
|
||||
$name = crc32($upload['name'].microtime()). '_' . $upload['name'];
|
||||
$file = $page->createFile([
|
||||
$newFiles[] = $page->createFile([
|
||||
'source' => $upload['tmp_name'],
|
||||
'filename' => $name,
|
||||
'template' => 'default',
|
||||
|
|
@ -43,7 +44,12 @@ return [
|
|||
$alerts[$upload['name']] = $e->getMessage();
|
||||
}
|
||||
}
|
||||
return compact('alerts', 'success');
|
||||
|
||||
$images = array_map(function ($file) {
|
||||
return $file->url();
|
||||
}, $newFiles);
|
||||
|
||||
return compact('images', 'alerts', 'success');
|
||||
}
|
||||
|
||||
return [
|
||||
|
|
|
|||
|
|
@ -68,48 +68,10 @@
|
|||
</button>
|
||||
<Toast />
|
||||
</div>
|
||||
<!-- <figure class="image">
|
||||
<figure v-for="image in images" class="image">
|
||||
<span class="tag | btn btn--sm">Tag</span>
|
||||
<img
|
||||
src="http://localhost:8888/media/pages/inspirations/shape-of-the-nature/6ed93d6950-1725442486/d82f18573c439d6edd434ffca62471a7.png"
|
||||
alt=""
|
||||
/>
|
||||
<img :src="image" alt="" />
|
||||
</figure>
|
||||
<figure class="image">
|
||||
<span class="tag | btn btn--sm">Tag</span>
|
||||
<img
|
||||
src="http://localhost:8888/media/pages/inspirations/shape-of-the-nature/7b0fcc5012-1725442486/37a038883c87973036232aa0e43f6da2.png"
|
||||
alt=""
|
||||
/>
|
||||
</figure>
|
||||
<figure class="image">
|
||||
<span class="tag | btn btn--sm">Tag</span>
|
||||
<img
|
||||
src="http://localhost:8888/media/pages/inspirations/shape-of-the-nature/1bbe051c5a-1725442486/0c41d3266e9ce2872f30608cceb28239.png"
|
||||
alt=""
|
||||
/>
|
||||
</figure>
|
||||
<figure class="image">
|
||||
<span class="tag | btn btn--sm">Tag</span>
|
||||
<img
|
||||
src="http://localhost:8888/media/pages/inspirations/shape-of-the-nature/6ed93d6950-1725442486/d82f18573c439d6edd434ffca62471a7.png"
|
||||
alt=""
|
||||
/>
|
||||
</figure>
|
||||
<figure class="image">
|
||||
<span class="tag | btn btn--sm">Tag</span>
|
||||
<img
|
||||
src="http://localhost:8888/media/pages/inspirations/shape-of-the-nature/7b0fcc5012-1725442486/37a038883c87973036232aa0e43f6da2.png"
|
||||
alt=""
|
||||
/>
|
||||
</figure>
|
||||
<figure class="image">
|
||||
<span class="tag | btn btn--sm">Tag</span>
|
||||
<img
|
||||
src="http://localhost:8888/media/pages/inspirations/shape-of-the-nature/1bbe051c5a-1725442486/0c41d3266e9ce2872f30608cceb28239.png"
|
||||
alt=""
|
||||
/>
|
||||
</figure> -->
|
||||
</section>
|
||||
</template>
|
||||
|
||||
|
|
@ -118,6 +80,7 @@ import Toast from "primevue/toast";
|
|||
import FileUpload from "primevue/fileupload";
|
||||
import { useToast } from "primevue/usetoast";
|
||||
import { usePageStore } from "../../../stores/page";
|
||||
import { ref } from "vue";
|
||||
|
||||
const { page } = usePageStore();
|
||||
const toast = useToast();
|
||||
|
|
@ -130,6 +93,8 @@ const beforeSend = (event) => {
|
|||
);
|
||||
};
|
||||
|
||||
const images = ref([]);
|
||||
|
||||
const onAdvancedUpload = (event) => {
|
||||
if (event.xhr.status === 200) {
|
||||
toast.add({
|
||||
|
|
@ -138,7 +103,9 @@ const onAdvancedUpload = (event) => {
|
|||
detail: event.xhr.response.success,
|
||||
life: 3000,
|
||||
});
|
||||
console.log(JSON.parse(event.xhr.response));
|
||||
const response = JSON.parse(event.xhr.response);
|
||||
console.log(response);
|
||||
images.value = response.images;
|
||||
} else {
|
||||
toast.add({
|
||||
severity: "error",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue