2022-06-30 17:45:11 +03:00
|
|
|
<template>
|
2022-07-03 10:50:51 +03:00
|
|
|
<MkContainer :naked="widgetProps.transparent" :show-header="widgetProps.showHeader" class="mkw-rss-ticker">
|
2022-12-19 12:01:30 +02:00
|
|
|
<template #header><i class="ti ti-rss"></i>RSS</template>
|
|
|
|
<template #func><button class="_button" @click="configure"><i class="ti ti-settings"></i></button></template>
|
2022-06-30 17:45:11 +03:00
|
|
|
|
|
|
|
<div class="ekmkgxbk">
|
|
|
|
<MkLoading v-if="fetching"/>
|
|
|
|
<div v-else class="feed">
|
2022-07-02 16:07:04 +03:00
|
|
|
<transition name="change" mode="default">
|
|
|
|
<MarqueeText :key="key" :duration="widgetProps.duration" :reverse="widgetProps.reverse">
|
|
|
|
<span v-for="item in items" class="item">
|
|
|
|
<a class="link" :href="item.link" rel="nofollow noopener" target="_blank" :title="item.title">{{ item.title }}</a><span class="divider"></span>
|
|
|
|
</span>
|
|
|
|
</MarqueeText>
|
|
|
|
</transition>
|
2022-06-30 17:45:11 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</MkContainer>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
import { onMounted, onUnmounted, ref, watch } from 'vue';
|
|
|
|
import { useWidgetPropsManager, Widget, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget';
|
2022-08-30 18:24:33 +03:00
|
|
|
import MarqueeText from '@/components/MkMarquee.vue';
|
2022-06-30 17:45:11 +03:00
|
|
|
import { GetFormResultType } from '@/scripts/form';
|
|
|
|
import * as os from '@/os';
|
2022-09-06 12:21:49 +03:00
|
|
|
import MkContainer from '@/components/MkContainer.vue';
|
2022-06-30 17:45:11 +03:00
|
|
|
import { useInterval } from '@/scripts/use-interval';
|
2022-07-15 11:12:08 +03:00
|
|
|
import { shuffle } from '@/scripts/shuffle';
|
2022-06-30 17:45:11 +03:00
|
|
|
|
2022-07-03 10:50:51 +03:00
|
|
|
const name = 'rssTicker';
|
2022-06-30 17:45:11 +03:00
|
|
|
|
|
|
|
const widgetPropsDef = {
|
|
|
|
url: {
|
|
|
|
type: 'string' as const,
|
|
|
|
default: 'http://feeds.afpbb.com/rss/afpbb/afpbbnews',
|
|
|
|
},
|
2022-07-15 11:12:08 +03:00
|
|
|
shuffle: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: true,
|
|
|
|
},
|
2022-07-02 16:07:04 +03:00
|
|
|
refreshIntervalSec: {
|
|
|
|
type: 'number' as const,
|
|
|
|
default: 60,
|
|
|
|
},
|
|
|
|
duration: {
|
|
|
|
type: 'range' as const,
|
|
|
|
default: 70,
|
|
|
|
step: 1,
|
|
|
|
min: 5,
|
|
|
|
max: 200,
|
|
|
|
},
|
|
|
|
reverse: {
|
2022-06-30 17:45:11 +03:00
|
|
|
type: 'boolean' as const,
|
|
|
|
default: false,
|
|
|
|
},
|
2022-07-02 16:07:04 +03:00
|
|
|
showHeader: {
|
2022-06-30 17:45:11 +03:00
|
|
|
type: 'boolean' as const,
|
|
|
|
default: false,
|
|
|
|
},
|
2022-07-02 16:07:04 +03:00
|
|
|
transparent: {
|
2022-06-30 17:45:11 +03:00
|
|
|
type: 'boolean' as const,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
|
|
|
|
|
|
|
|
// 現時点ではvueの制限によりimportしたtypeをジェネリックに渡せない
|
|
|
|
//const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
|
|
|
//const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
|
|
|
const props = defineProps<{ widget?: Widget<WidgetProps>; }>();
|
|
|
|
const emit = defineEmits<{ (ev: 'updateProps', props: WidgetProps); }>();
|
|
|
|
|
|
|
|
const { widgetProps, configure } = useWidgetPropsManager(name,
|
|
|
|
widgetPropsDef,
|
|
|
|
props,
|
|
|
|
emit,
|
|
|
|
);
|
|
|
|
|
|
|
|
const items = ref([]);
|
|
|
|
const fetching = ref(true);
|
2022-06-30 17:53:58 +03:00
|
|
|
let key = $ref(0);
|
2022-06-30 17:45:11 +03:00
|
|
|
|
|
|
|
const tick = () => {
|
2022-12-03 12:42:05 +02:00
|
|
|
window.fetch(`/api/fetch-rss?url=${widgetProps.url}`, {}).then(res => {
|
2022-06-30 17:45:11 +03:00
|
|
|
res.json().then(feed => {
|
2022-07-15 11:12:08 +03:00
|
|
|
if (widgetProps.shuffle) {
|
|
|
|
shuffle(feed.items);
|
|
|
|
}
|
2022-06-30 17:45:11 +03:00
|
|
|
items.value = feed.items;
|
|
|
|
fetching.value = false;
|
2022-06-30 17:53:58 +03:00
|
|
|
key++;
|
2022-06-30 17:45:11 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
watch(() => widgetProps.url, tick);
|
|
|
|
|
2022-07-02 16:07:04 +03:00
|
|
|
useInterval(tick, Math.max(10000, widgetProps.refreshIntervalSec * 1000), {
|
2022-06-30 17:45:11 +03:00
|
|
|
immediate: true,
|
|
|
|
afterMounted: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
defineExpose<WidgetComponentExpose>({
|
|
|
|
name,
|
|
|
|
configure,
|
|
|
|
id: props.widget ? props.widget.id : null,
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2022-07-02 16:07:04 +03:00
|
|
|
.change-enter-active, .change-leave-active {
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
transition: all 1s ease;
|
|
|
|
}
|
|
|
|
.change-enter-from {
|
|
|
|
opacity: 0;
|
|
|
|
transform: translateY(-100%);
|
|
|
|
}
|
|
|
|
.change-leave-to {
|
|
|
|
opacity: 0;
|
|
|
|
transform: translateY(100%);
|
|
|
|
}
|
|
|
|
|
2022-06-30 17:45:11 +03:00
|
|
|
.ekmkgxbk {
|
|
|
|
> .feed {
|
2022-07-03 10:36:13 +03:00
|
|
|
--height: 42px;
|
2022-06-30 17:45:11 +03:00
|
|
|
padding: 0;
|
|
|
|
font-size: 0.9em;
|
2022-07-03 10:36:13 +03:00
|
|
|
line-height: var(--height);
|
|
|
|
height: var(--height);
|
|
|
|
contain: strict;
|
2022-06-30 17:45:11 +03:00
|
|
|
|
|
|
|
::v-deep(.item) {
|
2022-07-01 09:23:49 +03:00
|
|
|
display: inline-flex;
|
|
|
|
align-items: center;
|
|
|
|
vertical-align: bottom;
|
2022-06-30 17:45:11 +03:00
|
|
|
color: var(--fg);
|
2022-07-01 09:23:49 +03:00
|
|
|
|
|
|
|
> .divider {
|
|
|
|
display: inline-block;
|
|
|
|
width: 0.5px;
|
|
|
|
height: 16px;
|
|
|
|
margin: 0 1em;
|
|
|
|
background: var(--divider);
|
|
|
|
}
|
2022-06-30 17:45:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|