2018-02-14 20:36:42 -07:00
|
|
|
<template>
|
2018-06-06 04:22:45 -06:00
|
|
|
<div class="mkw-slideshow" :data-mobile="platform == 'mobile'">
|
2018-02-14 20:36:42 -07:00
|
|
|
<div @click="choose">
|
2018-02-25 06:50:26 -07:00
|
|
|
<p v-if="props.folder === undefined">
|
2018-11-08 11:44:35 -07:00
|
|
|
<template v-if="isCustomizeMode">{{ $t('folder-customize-mode') }}</template>
|
|
|
|
<template v-else>{{ $t('folder') }}</template>
|
2018-02-25 06:50:26 -07:00
|
|
|
</p>
|
2018-11-08 11:44:35 -07:00
|
|
|
<p v-if="props.folder !== undefined && images.length == 0 && !fetching">{{ $t('no-image') }}</p>
|
2018-02-14 20:36:42 -07:00
|
|
|
<div ref="slideA" class="slide a"></div>
|
|
|
|
<div ref="slideB" class="slide b"></div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2019-01-17 21:06:11 -07:00
|
|
|
import anime from 'animejs';
|
2018-02-24 08:18:09 -07:00
|
|
|
import define from '../../../common/define-widget';
|
2018-11-08 11:44:35 -07:00
|
|
|
import i18n from '../../../i18n';
|
|
|
|
|
2018-02-14 20:36:42 -07:00
|
|
|
export default define({
|
|
|
|
name: 'slideshow',
|
2018-02-20 23:30:03 -07:00
|
|
|
props: () => ({
|
2018-02-14 20:36:42 -07:00
|
|
|
folder: undefined,
|
|
|
|
size: 0
|
2018-02-20 23:30:03 -07:00
|
|
|
})
|
2018-02-14 20:36:42 -07:00
|
|
|
}).extend({
|
2018-11-08 11:44:35 -07:00
|
|
|
i18n: i18n('common/views/widgets/slideshow.vue'),
|
|
|
|
|
2018-02-14 20:36:42 -07:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
images: [],
|
|
|
|
fetching: true,
|
|
|
|
clock: null
|
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
2018-02-18 02:40:24 -07:00
|
|
|
this.$nextTick(() => {
|
2018-02-14 20:36:42 -07:00
|
|
|
this.applySize();
|
|
|
|
});
|
|
|
|
|
|
|
|
if (this.props.folder !== undefined) {
|
|
|
|
this.fetch();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.clock = setInterval(this.change, 10000);
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
clearInterval(this.clock);
|
|
|
|
},
|
|
|
|
methods: {
|
2018-02-25 06:50:26 -07:00
|
|
|
func() {
|
|
|
|
this.resize();
|
|
|
|
},
|
2018-02-14 20:36:42 -07:00
|
|
|
applySize() {
|
|
|
|
let h;
|
|
|
|
|
|
|
|
if (this.props.size == 1) {
|
|
|
|
h = 250;
|
|
|
|
} else {
|
|
|
|
h = 170;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$el.style.height = `${h}px`;
|
|
|
|
},
|
|
|
|
resize() {
|
|
|
|
if (this.props.size == 1) {
|
|
|
|
this.props.size = 0;
|
|
|
|
} else {
|
|
|
|
this.props.size++;
|
|
|
|
}
|
2018-04-29 02:17:15 -06:00
|
|
|
this.save();
|
2018-02-14 20:36:42 -07:00
|
|
|
|
|
|
|
this.applySize();
|
|
|
|
},
|
|
|
|
change() {
|
|
|
|
if (this.images.length == 0) return;
|
|
|
|
|
|
|
|
const index = Math.floor(Math.random() * this.images.length);
|
2018-07-24 08:43:14 -06:00
|
|
|
const img = `url(${ this.images[index].url })`;
|
2018-02-14 20:36:42 -07:00
|
|
|
|
|
|
|
(this.$refs.slideB as any).style.backgroundImage = img;
|
|
|
|
|
|
|
|
anime({
|
|
|
|
targets: this.$refs.slideB,
|
|
|
|
opacity: 1,
|
|
|
|
duration: 1000,
|
|
|
|
easing: 'linear',
|
|
|
|
complete: () => {
|
2018-03-04 02:14:13 -07:00
|
|
|
// 既にこのウィジェットがunmountされていたら要素がない
|
|
|
|
if ((this.$refs.slideA as any) == null) return;
|
|
|
|
|
2018-02-14 20:36:42 -07:00
|
|
|
(this.$refs.slideA as any).style.backgroundImage = img;
|
|
|
|
anime({
|
|
|
|
targets: this.$refs.slideB,
|
|
|
|
opacity: 0,
|
|
|
|
duration: 0
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
fetch() {
|
|
|
|
this.fetching = true;
|
|
|
|
|
2018-11-08 16:13:34 -07:00
|
|
|
this.$root.api('drive/files', {
|
2018-03-28 23:48:47 -06:00
|
|
|
folderId: this.props.folder,
|
2018-02-14 20:36:42 -07:00
|
|
|
type: 'image/*',
|
|
|
|
limit: 100
|
|
|
|
}).then(images => {
|
|
|
|
this.images = images;
|
2018-02-19 07:37:09 -07:00
|
|
|
this.fetching = false;
|
2018-02-14 20:36:42 -07:00
|
|
|
(this.$refs.slideA as any).style.backgroundImage = '';
|
|
|
|
(this.$refs.slideB as any).style.backgroundImage = '';
|
|
|
|
this.change();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
choose() {
|
2018-11-09 00:00:29 -07:00
|
|
|
this.$chooseDriveFolder().then(folder => {
|
2018-02-14 20:36:42 -07:00
|
|
|
this.props.folder = folder ? folder.id : null;
|
2018-04-29 02:17:15 -06:00
|
|
|
this.save();
|
2018-02-14 20:36:42 -07:00
|
|
|
this.fetch();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="stylus" scoped>
|
|
|
|
.mkw-slideshow
|
|
|
|
overflow hidden
|
|
|
|
background #fff
|
2018-04-28 17:51:17 -06:00
|
|
|
border solid 1px rgba(#000, 0.075)
|
2018-02-14 20:36:42 -07:00
|
|
|
border-radius 6px
|
|
|
|
|
2018-02-26 02:59:26 -07:00
|
|
|
&[data-mobile]
|
|
|
|
border none
|
|
|
|
border-radius 8px
|
2018-04-28 17:51:17 -06:00
|
|
|
box-shadow 0 0 0 1px rgba(#000, 0.2)
|
2018-02-26 02:59:26 -07:00
|
|
|
|
2018-02-14 20:36:42 -07:00
|
|
|
> div
|
|
|
|
width 100%
|
|
|
|
height 100%
|
|
|
|
cursor pointer
|
|
|
|
|
2018-02-25 06:50:26 -07:00
|
|
|
> p
|
|
|
|
display block
|
|
|
|
margin 1em
|
|
|
|
text-align center
|
|
|
|
color #888
|
|
|
|
|
2018-02-14 20:36:42 -07:00
|
|
|
> *
|
|
|
|
pointer-events none
|
|
|
|
|
|
|
|
> .slide
|
|
|
|
position absolute
|
|
|
|
top 0
|
|
|
|
left 0
|
|
|
|
width 100%
|
|
|
|
height 100%
|
|
|
|
background-size cover
|
|
|
|
background-position center
|
|
|
|
|
|
|
|
&.b
|
|
|
|
opacity 0
|
|
|
|
|
|
|
|
</style>
|