2020-02-18 19:47:30 +09:00
|
|
|
<template>
|
2020-10-17 20:12:00 +09:00
|
|
|
<MkContainer :show-header="props.showHeader" :naked="props.transparent" :class="$style.root" :data-transparent="props.transparent ? true : null">
|
2021-04-20 23:22:59 +09:00
|
|
|
<template #header><i class="fas fa-camera"></i>{{ $ts._widgets.photos }}</template>
|
2020-02-18 19:47:30 +09:00
|
|
|
|
2020-07-11 10:13:11 +09:00
|
|
|
<div class="">
|
2020-10-17 20:12:00 +09:00
|
|
|
<MkLoading v-if="fetching"/>
|
2020-07-11 10:13:11 +09:00
|
|
|
<div v-else :class="$style.stream">
|
|
|
|
<div v-for="(image, i) in images" :key="i"
|
|
|
|
:class="$style.img"
|
|
|
|
:style="`background-image: url(${thumbnail(image)})`"
|
|
|
|
></div>
|
2020-02-18 19:47:30 +09:00
|
|
|
</div>
|
2020-07-11 10:13:11 +09:00
|
|
|
</div>
|
2020-10-17 20:12:00 +09:00
|
|
|
</MkContainer>
|
2020-02-18 19:47:30 +09:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2021-07-26 11:12:06 +09:00
|
|
|
import { defineComponent, markRaw } from 'vue';
|
2021-11-12 02:02:25 +09:00
|
|
|
import MkContainer from '@/components/ui/container.vue';
|
2020-02-18 19:47:30 +09:00
|
|
|
import define from './define';
|
2021-11-12 02:02:25 +09:00
|
|
|
import { getStaticImageUrl } from '@/scripts/get-static-image-url';
|
|
|
|
import * as os from '@/os';
|
2020-02-18 19:47:30 +09:00
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
const widget = define({
|
2020-02-18 19:47:30 +09:00
|
|
|
name: 'photos',
|
|
|
|
props: () => ({
|
2020-07-11 10:13:11 +09:00
|
|
|
showHeader: {
|
|
|
|
type: 'boolean',
|
|
|
|
default: true,
|
|
|
|
},
|
|
|
|
transparent: {
|
|
|
|
type: 'boolean',
|
|
|
|
default: false,
|
|
|
|
},
|
2020-02-18 19:47:30 +09:00
|
|
|
})
|
2020-10-17 20:12:00 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
export default defineComponent({
|
2020-02-18 19:47:30 +09:00
|
|
|
components: {
|
|
|
|
MkContainer,
|
|
|
|
},
|
2021-11-19 19:36:12 +09:00
|
|
|
extends: widget,
|
2020-02-18 19:47:30 +09:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
images: [],
|
|
|
|
fetching: true,
|
|
|
|
connection: null,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
2021-07-26 11:12:06 +09:00
|
|
|
this.connection = markRaw(os.stream.useChannel('main'));
|
2020-02-18 19:47:30 +09:00
|
|
|
|
|
|
|
this.connection.on('driveFileCreated', this.onDriveFileCreated);
|
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
os.api('drive/stream', {
|
2020-02-18 19:47:30 +09:00
|
|
|
type: 'image/*',
|
|
|
|
limit: 9
|
|
|
|
}).then(images => {
|
|
|
|
this.images = images;
|
|
|
|
this.fetching = false;
|
|
|
|
});
|
|
|
|
},
|
2020-10-17 20:12:00 +09:00
|
|
|
beforeUnmount() {
|
2020-02-18 19:47:30 +09:00
|
|
|
this.connection.dispose();
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onDriveFileCreated(file) {
|
|
|
|
if (/^image\/.+$/.test(file.type)) {
|
|
|
|
this.images.unshift(file);
|
|
|
|
if (this.images.length > 9) this.images.pop();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
thumbnail(image: any): string {
|
2020-12-19 10:55:52 +09:00
|
|
|
return this.$store.state.disableShowingAnimatedImages
|
2020-02-18 19:47:30 +09:00
|
|
|
? getStaticImageUrl(image.thumbnailUrl)
|
|
|
|
: image.thumbnailUrl;
|
|
|
|
},
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" module>
|
2020-07-11 10:13:11 +09:00
|
|
|
.root[data-transparent] {
|
2020-02-18 19:47:30 +09:00
|
|
|
.stream {
|
|
|
|
padding: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.img {
|
|
|
|
border: solid 4px transparent;
|
|
|
|
border-radius: 8px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.stream {
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
flex-wrap: wrap;
|
|
|
|
padding: 8px;
|
|
|
|
|
|
|
|
.img {
|
|
|
|
flex: 1 1 33%;
|
|
|
|
width: 33%;
|
|
|
|
height: 80px;
|
|
|
|
box-sizing: border-box;
|
|
|
|
background-position: center center;
|
|
|
|
background-size: cover;
|
|
|
|
background-clip: content-box;
|
|
|
|
border: solid 2px transparent;
|
|
|
|
border-radius: 4px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|