2020-02-18 11:47:30 +01:00
|
|
|
<template>
|
2022-05-28 07:28:12 +02:00
|
|
|
<MkContainer :show-header="widgetProps.showHeader" :naked="widgetProps.transparent" :class="$style.root" :data-transparent="widgetProps.transparent ? true : null" class="mkw-photos">
|
2022-07-20 15:24:26 +02:00
|
|
|
<template #header><i class="fas fa-camera"></i>{{ i18n.ts._widgets.photos }}</template>
|
2020-02-18 11:47:30 +01:00
|
|
|
|
2020-07-11 03:13:11 +02:00
|
|
|
<div class="">
|
2020-10-17 13:12:00 +02:00
|
|
|
<MkLoading v-if="fetching"/>
|
2020-07-11 03:13:11 +02:00
|
|
|
<div v-else :class="$style.stream">
|
2022-07-20 15:24:26 +02:00
|
|
|
<div
|
|
|
|
v-for="(image, i) in images" :key="i"
|
2020-07-11 03:13:11 +02:00
|
|
|
:class="$style.img"
|
|
|
|
:style="`background-image: url(${thumbnail(image)})`"
|
|
|
|
></div>
|
2020-02-18 11:47:30 +01:00
|
|
|
</div>
|
2020-07-11 03:13:11 +02:00
|
|
|
</div>
|
2020-10-17 13:12:00 +02:00
|
|
|
</MkContainer>
|
2020-02-18 11:47:30 +01:00
|
|
|
</template>
|
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { onMounted, onUnmounted, reactive, ref } from 'vue';
|
|
|
|
import { useWidgetPropsManager, Widget, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget';
|
2022-07-20 15:24:26 +02:00
|
|
|
import { GetFormResultType } from '@/scripts/form';
|
2022-01-08 12:30:01 +01:00
|
|
|
import { stream } from '@/stream';
|
2021-11-11 18:02:25 +01:00
|
|
|
import { getStaticImageUrl } from '@/scripts/get-static-image-url';
|
|
|
|
import * as os from '@/os';
|
2022-01-08 12:30:01 +01:00
|
|
|
import MkContainer from '@/components/ui/container.vue';
|
|
|
|
import { defaultStore } from '@/store';
|
2022-07-20 15:24:26 +02:00
|
|
|
import { i18n } from '@/i18n';
|
2020-02-18 11:47:30 +01:00
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
const name = 'photos';
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
const widgetPropsDef = {
|
|
|
|
showHeader: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: true,
|
2020-02-18 11:47:30 +01:00
|
|
|
},
|
2022-01-08 12:30:01 +01:00
|
|
|
transparent: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: false,
|
2020-02-18 11:47:30 +01:00
|
|
|
},
|
2022-01-08 12:30:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
|
|
|
|
|
|
|
|
// 現時点ではvueの制限によりimportしたtypeをジェネリックに渡せない
|
|
|
|
//const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
|
|
|
//const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
|
|
|
const props = defineProps<{ widget?: Widget<WidgetProps>; }>();
|
2022-05-25 09:43:12 +02:00
|
|
|
const emit = defineEmits<{ (ev: 'updateProps', props: WidgetProps); }>();
|
2022-01-08 12:30:01 +01:00
|
|
|
|
|
|
|
const { widgetProps, configure } = useWidgetPropsManager(name,
|
|
|
|
widgetPropsDef,
|
|
|
|
props,
|
|
|
|
emit,
|
|
|
|
);
|
|
|
|
|
|
|
|
const connection = stream.useChannel('main');
|
|
|
|
const images = ref([]);
|
|
|
|
const fetching = ref(true);
|
|
|
|
|
|
|
|
const onDriveFileCreated = (file) => {
|
|
|
|
if (/^image\/.+$/.test(file.type)) {
|
|
|
|
images.value.unshift(file);
|
|
|
|
if (images.value.length > 9) images.value.pop();
|
2020-02-18 11:47:30 +01:00
|
|
|
}
|
2022-01-08 12:30:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const thumbnail = (image: any): string => {
|
|
|
|
return defaultStore.state.disableShowingAnimatedImages
|
|
|
|
? getStaticImageUrl(image.thumbnailUrl)
|
|
|
|
: image.thumbnailUrl;
|
|
|
|
};
|
|
|
|
|
|
|
|
os.api('drive/stream', {
|
|
|
|
type: 'image/*',
|
2022-07-20 15:24:26 +02:00
|
|
|
limit: 9,
|
2022-01-08 12:30:01 +01:00
|
|
|
}).then(res => {
|
|
|
|
images.value = res;
|
|
|
|
fetching.value = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
connection.on('driveFileCreated', onDriveFileCreated);
|
|
|
|
onUnmounted(() => {
|
|
|
|
connection.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
defineExpose<WidgetComponentExpose>({
|
|
|
|
name,
|
|
|
|
configure,
|
|
|
|
id: props.widget ? props.widget.id : null,
|
2020-02-18 11:47:30 +01:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" module>
|
2020-07-11 03:13:11 +02:00
|
|
|
.root[data-transparent] {
|
2020-02-18 11:47:30 +01: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>
|