2020-01-29 21:37:25 +02:00
|
|
|
<template>
|
2022-01-08 13:30:01 +02:00
|
|
|
<MkContainer :show-header="widgetProps.showHeader">
|
2021-04-20 17:22:59 +03:00
|
|
|
<template #header><i class="fas fa-rss-square"></i>RSS</template>
|
2022-01-08 13:30:01 +02:00
|
|
|
<template #func><button class="_button" @click="configure"><i class="fas fa-cog"></i></button></template>
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2020-07-11 04:13:11 +03:00
|
|
|
<div class="ekmkgxbj">
|
2020-10-17 14:12:00 +03:00
|
|
|
<MkLoading v-if="fetching"/>
|
2021-11-19 12:36:12 +02:00
|
|
|
<div v-else class="feed">
|
2020-07-11 04:13:11 +03:00
|
|
|
<a v-for="item in items" :href="item.link" rel="nofollow noopener" target="_blank" :title="item.title">{{ item.title }}</a>
|
2020-01-29 21:37:25 +02:00
|
|
|
</div>
|
2020-07-11 04:13:11 +03:00
|
|
|
</div>
|
2020-10-17 14:12:00 +03:00
|
|
|
</MkContainer>
|
2020-01-29 21:37:25 +02:00
|
|
|
</template>
|
|
|
|
|
2022-01-08 13:30:01 +02:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { onMounted, onUnmounted, ref, watch } from 'vue';
|
|
|
|
import { GetFormResultType } from '@/scripts/form';
|
|
|
|
import { useWidgetPropsManager, Widget, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget';
|
2021-11-11 19:02:25 +02:00
|
|
|
import * as os from '@/os';
|
2022-01-08 13:30:01 +02:00
|
|
|
import MkContainer from '@/components/ui/container.vue';
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2022-01-08 13:30:01 +02:00
|
|
|
const name = 'rss';
|
2020-10-17 14:12:00 +03:00
|
|
|
|
2022-01-08 13:30:01 +02:00
|
|
|
const widgetPropsDef = {
|
|
|
|
showHeader: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: true,
|
2020-01-29 21:37:25 +02:00
|
|
|
},
|
2022-01-08 13:30:01 +02:00
|
|
|
url: {
|
|
|
|
type: 'string' as const,
|
|
|
|
default: 'http://feeds.afpbb.com/rss/afpbb/afpbbnews',
|
2020-01-29 21:37:25 +02:00
|
|
|
},
|
2022-01-08 13:30:01 +02: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 10:43:12 +03:00
|
|
|
const emit = defineEmits<{ (ev: 'updateProps', props: WidgetProps); }>();
|
2022-01-08 13:30:01 +02:00
|
|
|
|
|
|
|
const { widgetProps, configure } = useWidgetPropsManager(name,
|
|
|
|
widgetPropsDef,
|
|
|
|
props,
|
|
|
|
emit,
|
|
|
|
);
|
|
|
|
|
|
|
|
const items = ref([]);
|
|
|
|
const fetching = ref(true);
|
|
|
|
|
|
|
|
const tick = () => {
|
2022-01-08 17:00:27 +02:00
|
|
|
fetch(`https://api.rss2json.com/v1/api.json?rss_url=${widgetProps.url}`, {}).then(res => {
|
2022-01-08 13:30:01 +02:00
|
|
|
res.json().then(feed => {
|
|
|
|
items.value = feed.items;
|
|
|
|
fetching.value = false;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
watch(() => widgetProps.url, tick);
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
tick();
|
2022-01-16 03:14:14 +02:00
|
|
|
const intervalId = window.setInterval(tick, 60000);
|
2022-01-08 13:30:01 +02:00
|
|
|
onUnmounted(() => {
|
2022-01-16 03:14:14 +02:00
|
|
|
window.clearInterval(intervalId);
|
2022-01-08 13:30:01 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
defineExpose<WidgetComponentExpose>({
|
|
|
|
name,
|
|
|
|
configure,
|
|
|
|
id: props.widget ? props.widget.id : null,
|
2020-01-29 21:37:25 +02:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.ekmkgxbj {
|
|
|
|
> .feed {
|
|
|
|
padding: 0;
|
|
|
|
font-size: 0.9em;
|
|
|
|
|
|
|
|
> a {
|
|
|
|
display: block;
|
|
|
|
padding: 8px 16px;
|
2020-10-27 11:11:41 +02:00
|
|
|
color: var(--fg);
|
2020-01-29 21:37:25 +02:00
|
|
|
white-space: nowrap;
|
|
|
|
text-overflow: ellipsis;
|
2021-03-02 15:57:16 +02:00
|
|
|
overflow: hidden;
|
2020-01-29 21:37:25 +02:00
|
|
|
|
|
|
|
&:nth-child(even) {
|
|
|
|
background: rgba(#000, 0.05);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|