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