#137 - create single image component and add download image function
This commit is contained in:
parent
1cd55b98d6
commit
1ed7aa9c5b
5 changed files with 63 additions and 33 deletions
|
|
@ -35,9 +35,7 @@
|
||||||
v-if="activeTrack.files.length > 1"
|
v-if="activeTrack.files.length > 1"
|
||||||
:activeTrack="activeTrack"
|
:activeTrack="activeTrack"
|
||||||
/>
|
/>
|
||||||
<figure v-else>
|
<SingleImage v-else :file="activeTrack.files[0]" />
|
||||||
<img :src="activeTrack.files[0].url" alt="" />
|
|
||||||
</figure>
|
|
||||||
</template>
|
</template>
|
||||||
<div
|
<div
|
||||||
v-if="isCompareModeEnabled && activeTracks.length < 2"
|
v-if="isCompareModeEnabled && activeTracks.length < 2"
|
||||||
|
|
@ -52,10 +50,11 @@
|
||||||
import { ref, computed, watch, onMounted, onBeforeMount } from 'vue';
|
import { ref, computed, watch, onMounted, onBeforeMount } from 'vue';
|
||||||
import { storeToRefs } from 'pinia';
|
import { storeToRefs } from 'pinia';
|
||||||
import { usePageStore } from '../../../stores/page';
|
import { usePageStore } from '../../../stores/page';
|
||||||
import Interactive360 from './Interactive360.vue';
|
|
||||||
import { useDialogStore } from '../../../stores/dialog';
|
import { useDialogStore } from '../../../stores/dialog';
|
||||||
import { useVirtualSampleStore } from '../../../stores/virtualSample';
|
import { useVirtualSampleStore } from '../../../stores/virtualSample';
|
||||||
import { useRoute } from 'vue-router';
|
import { useRoute } from 'vue-router';
|
||||||
|
import Interactive360 from './Interactive360.vue';
|
||||||
|
import SingleImage from './SingleImage.vue';
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,11 +30,11 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import throttle from "lodash/throttle";
|
import throttle from 'lodash/throttle';
|
||||||
import { ref, computed, watch } from "vue";
|
import { ref, computed, watch } from 'vue';
|
||||||
import { useVirtualSampleStore } from "../../../stores/virtualSample";
|
import { useVirtualSampleStore } from '../../../stores/virtualSample';
|
||||||
import { storeToRefs } from "pinia";
|
import { storeToRefs } from 'pinia';
|
||||||
import { useDialogStore } from "../../../stores/dialog";
|
import { useDialogStore } from '../../../stores/dialog';
|
||||||
|
|
||||||
const { activeTrack } = defineProps({
|
const { activeTrack } = defineProps({
|
||||||
activeTrack: Object,
|
activeTrack: Object,
|
||||||
|
|
@ -44,27 +44,27 @@ const { activeTrack } = defineProps({
|
||||||
const { openedFile } = storeToRefs(useDialogStore());
|
const { openedFile } = storeToRefs(useDialogStore());
|
||||||
const virtualSampleStore = useVirtualSampleStore();
|
const virtualSampleStore = useVirtualSampleStore();
|
||||||
const { isDownloadTriggered } = storeToRefs(useVirtualSampleStore());
|
const { isDownloadTriggered } = storeToRefs(useVirtualSampleStore());
|
||||||
const isHelperHidden = ref(localStorage.getItem("isHelperHidden"));
|
const isHelperHidden = ref(localStorage.getItem('isHelperHidden'));
|
||||||
localStorage.setItem("isHelperHidden", true);
|
localStorage.setItem('isHelperHidden', true);
|
||||||
|
|
||||||
// Grab interaction
|
// Grab interaction
|
||||||
const yMax = computed(() => {
|
const yMax = computed(() => {
|
||||||
return parseInt(
|
return parseInt(
|
||||||
activeTrack.files[activeTrack.files.length - 1].name.split("_")[0]
|
activeTrack.files[activeTrack.files.length - 1].name.split('_')[0]
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
const xMax = computed(() => {
|
const xMax = computed(() => {
|
||||||
return parseInt(
|
return parseInt(
|
||||||
activeTrack.files[activeTrack.files.length - 1].name
|
activeTrack.files[activeTrack.files.length - 1].name
|
||||||
.split("_")[1]
|
.split('_')[1]
|
||||||
.split(".")[0]
|
.split('.')[0]
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
const frontXView = (xMax.value + 1) / 2;
|
const frontXView = (xMax.value + 1) / 2;
|
||||||
const currentX = ref(frontXView);
|
const currentX = ref(frontXView);
|
||||||
const currentY = ref(0);
|
const currentY = ref(0);
|
||||||
const currentFileIndex = computed(() => currentY.value + "_" + currentX.value);
|
const currentFileIndex = computed(() => currentY.value + '_' + currentX.value);
|
||||||
const currentFile = computed(() =>
|
const currentFile = computed(() =>
|
||||||
activeTrack.files.find((file) => file.name.includes(currentFileIndex.value))
|
activeTrack.files.find((file) => file.name.includes(currentFileIndex.value))
|
||||||
);
|
);
|
||||||
|
|
@ -80,16 +80,16 @@ watch(
|
||||||
);
|
);
|
||||||
|
|
||||||
function rotateX(direction) {
|
function rotateX(direction) {
|
||||||
if (direction == "left") {
|
if (direction == 'left') {
|
||||||
currentX.value = currentX.value === 0 ? xMax.value : currentX.value - 1;
|
currentX.value = currentX.value === 0 ? xMax.value : currentX.value - 1;
|
||||||
}
|
}
|
||||||
if (direction == "right") {
|
if (direction == 'right') {
|
||||||
currentX.value = currentX.value === xMax.value ? 0 : currentX.value + 1;
|
currentX.value = currentX.value === xMax.value ? 0 : currentX.value + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const isDragToRotateEnabled = ref(false);
|
const isDragToRotateEnabled = ref(false);
|
||||||
window.addEventListener("mouseup", disableDragToRotate);
|
window.addEventListener('mouseup', disableDragToRotate);
|
||||||
function enableDragToRotate() {
|
function enableDragToRotate() {
|
||||||
isDragToRotateEnabled.value = true;
|
isDragToRotateEnabled.value = true;
|
||||||
}
|
}
|
||||||
|
|
@ -113,10 +113,10 @@ function handleHorizontalRotation(event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.clientX > previousMouseXPos + DRAG_STEP) {
|
if (event.clientX > previousMouseXPos + DRAG_STEP) {
|
||||||
rotateX("left");
|
rotateX('left');
|
||||||
previousMouseXPos = event.clientX;
|
previousMouseXPos = event.clientX;
|
||||||
} else if (event.clientX < previousMouseXPos - DRAG_STEP) {
|
} else if (event.clientX < previousMouseXPos - DRAG_STEP) {
|
||||||
rotateX("right");
|
rotateX('right');
|
||||||
previousMouseXPos = event.clientX;
|
previousMouseXPos = event.clientX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -149,9 +149,9 @@ const throttledDragToRotate = throttle(dragToRotate, 50);
|
||||||
|
|
||||||
watch(isDragToRotateEnabled, (newValue) => {
|
watch(isDragToRotateEnabled, (newValue) => {
|
||||||
if (newValue) {
|
if (newValue) {
|
||||||
window.addEventListener("mousemove", throttledDragToRotate);
|
window.addEventListener('mousemove', throttledDragToRotate);
|
||||||
} else {
|
} else {
|
||||||
window.removeEventListener("mousemove", throttledDragToRotate);
|
window.removeEventListener('mousemove', throttledDragToRotate);
|
||||||
previousMouseXPos = undefined;
|
previousMouseXPos = undefined;
|
||||||
previousMouseYPos = undefined;
|
previousMouseYPos = undefined;
|
||||||
}
|
}
|
||||||
|
|
@ -160,7 +160,7 @@ watch(isDragToRotateEnabled, (newValue) => {
|
||||||
const { isLoopAnimationEnabled } = storeToRefs(useVirtualSampleStore());
|
const { isLoopAnimationEnabled } = storeToRefs(useVirtualSampleStore());
|
||||||
|
|
||||||
function loopAnimation() {
|
function loopAnimation() {
|
||||||
rotateX("right");
|
rotateX('right');
|
||||||
}
|
}
|
||||||
|
|
||||||
let animationIntervalId;
|
let animationIntervalId;
|
||||||
|
|
@ -193,9 +193,9 @@ function preloadImages() {
|
||||||
watch(isDownloadTriggered, (newValue) => {
|
watch(isDownloadTriggered, (newValue) => {
|
||||||
if (!newValue) return;
|
if (!newValue) return;
|
||||||
|
|
||||||
const downloadNode = document.createElement("a");
|
const downloadNode = document.createElement('a');
|
||||||
downloadNode.setAttribute("href", currentFile.value.source);
|
downloadNode.setAttribute('href', currentFile.value.source);
|
||||||
downloadNode.setAttribute("download", "");
|
downloadNode.setAttribute('download', '');
|
||||||
document.body.appendChild(downloadNode);
|
document.body.appendChild(downloadNode);
|
||||||
downloadNode.click();
|
downloadNode.click();
|
||||||
document.body.removeChild(downloadNode);
|
document.body.removeChild(downloadNode);
|
||||||
|
|
|
||||||
29
src/components/project/virtual-sample/SingleImage.vue
Normal file
29
src/components/project/virtual-sample/SingleImage.vue
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
<template>
|
||||||
|
<figure>
|
||||||
|
<img :src="file.url" alt="" />
|
||||||
|
</figure>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { storeToRefs } from 'pinia';
|
||||||
|
import { useVirtualSampleStore } from '../../../stores/virtualSample';
|
||||||
|
import { watch } from 'vue';
|
||||||
|
|
||||||
|
const { file } = defineProps({
|
||||||
|
file: Object,
|
||||||
|
});
|
||||||
|
|
||||||
|
const { isDownloadTriggered } = storeToRefs(useVirtualSampleStore());
|
||||||
|
|
||||||
|
// Download image
|
||||||
|
watch(isDownloadTriggered, (newValue) => {
|
||||||
|
if (!newValue) return;
|
||||||
|
const downloadNode = document.createElement('a');
|
||||||
|
downloadNode.setAttribute('href', file.source);
|
||||||
|
downloadNode.setAttribute('download', '');
|
||||||
|
document.body.appendChild(downloadNode);
|
||||||
|
console.log(downloadNode);
|
||||||
|
downloadNode.click();
|
||||||
|
document.body.removeChild(downloadNode);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
@ -49,7 +49,7 @@
|
||||||
|
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<button
|
<button
|
||||||
v-if="currentFile"
|
v-if="openedFile"
|
||||||
id="download-image"
|
id="download-image"
|
||||||
class="btn btn--white-10"
|
class="btn btn--white-10"
|
||||||
data-icon="download"
|
data-icon="download"
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,15 @@
|
||||||
import { defineStore } from "pinia";
|
import { defineStore, storeToRefs } from 'pinia';
|
||||||
import { ref, watch } from "vue";
|
import { ref, watch } from 'vue';
|
||||||
import { usePageStore } from "./page";
|
import { usePageStore } from './page';
|
||||||
|
import { useDialogStore } from './dialog';
|
||||||
|
|
||||||
export const useVirtualSampleStore = defineStore("virtual-sample", () => {
|
export const useVirtualSampleStore = defineStore('virtual-sample', () => {
|
||||||
const { page } = usePageStore();
|
const { page } = usePageStore();
|
||||||
const step = page.steps.find((step) => step.id === "virtualSample");
|
const { openedFile } = storeToRefs(useDialogStore());
|
||||||
|
const step = page.steps.find((step) => step.id === 'virtualSample');
|
||||||
const isCompareModeEnabled = ref(false);
|
const isCompareModeEnabled = ref(false);
|
||||||
|
|
||||||
const activeTab = ref(step.files.dynamic ? "dynamic" : "static");
|
const activeTab = ref(step.files.dynamic ? 'dynamic' : 'static');
|
||||||
const currentFile = ref(null);
|
const currentFile = ref(null);
|
||||||
const isLoopAnimationEnabled = ref(false);
|
const isLoopAnimationEnabled = ref(false);
|
||||||
const isDownloadTriggered = ref(false);
|
const isDownloadTriggered = ref(false);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue