2020-01-29 20:37:25 +01:00
|
|
|
<template>
|
2023-06-26 23:51:45 +02:00
|
|
|
<MkContainer
|
2023-06-26 00:33:13 +02:00
|
|
|
:show-header="widgetProps.showHeader"
|
2023-06-26 23:51:45 +02:00
|
|
|
class="mkw-rss"
|
2023-06-26 00:33:13 +02:00
|
|
|
:scrollable="true"
|
|
|
|
:style="`height: ${widgetProps.height}px;`"
|
|
|
|
>
|
2023-04-08 02:01:42 +02:00
|
|
|
<template #header><i class="ph-rss ph-bold ph-lg"></i>RSS</template>
|
|
|
|
<template #func
|
|
|
|
><button class="_button" @click="configure">
|
|
|
|
<i class="ph-gear-six ph-bold ph-lg"></i></button
|
|
|
|
></template>
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
<div class="ekmkgxbj">
|
|
|
|
<MkLoading v-if="fetching" />
|
|
|
|
<div v-else class="feed">
|
|
|
|
<a
|
|
|
|
v-for="item in items"
|
|
|
|
class="item"
|
|
|
|
:href="item.link"
|
|
|
|
rel="nofollow noopener"
|
|
|
|
target="_blank"
|
|
|
|
:title="item.title"
|
|
|
|
>{{ item.title }}</a
|
|
|
|
>
|
|
|
|
</div>
|
2020-01-29 20:37:25 +01:00
|
|
|
</div>
|
2023-04-08 02:01:42 +02:00
|
|
|
</MkContainer>
|
2020-01-29 20:37:25 +01:00
|
|
|
</template>
|
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
<script lang="ts" setup>
|
2023-04-08 02:01:42 +02:00
|
|
|
import { onMounted, onUnmounted, ref, watch } from "vue";
|
2023-07-17 00:32:32 +02:00
|
|
|
import type { Widget, WidgetComponentExpose } from "./widget";
|
2023-04-08 02:01:42 +02:00
|
|
|
import {
|
|
|
|
WidgetComponentEmits,
|
|
|
|
WidgetComponentProps,
|
2023-07-17 00:32:32 +02:00
|
|
|
useWidgetPropsManager,
|
2023-04-08 02:01:42 +02:00
|
|
|
} from "./widget";
|
2023-07-17 00:32:32 +02:00
|
|
|
import type { GetFormResultType } from "@/scripts/form";
|
2023-04-08 02:01:42 +02:00
|
|
|
import * as os from "@/os";
|
|
|
|
import MkContainer from "@/components/MkContainer.vue";
|
|
|
|
import { useInterval } from "@/scripts/use-interval";
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
const name = "rss";
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
const widgetPropsDef = {
|
|
|
|
url: {
|
2023-04-08 02:01:42 +02:00
|
|
|
type: "string" as const,
|
|
|
|
default: "http://feeds.afpbb.com/rss/afpbb/afpbbnews",
|
2020-01-29 20:37:25 +01:00
|
|
|
},
|
2023-06-26 00:33:13 +02:00
|
|
|
height: {
|
|
|
|
type: "number" as const,
|
|
|
|
default: 300,
|
|
|
|
},
|
2022-06-30 16:45:11 +02:00
|
|
|
showHeader: {
|
2023-04-08 02:01:42 +02:00
|
|
|
type: "boolean" as const,
|
2022-06-30 16:45:11 +02:00
|
|
|
default: true,
|
|
|
|
},
|
2022-01-08 12:30:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
|
|
|
|
|
|
|
|
// 現時点ではvueの制限によりimportしたtypeをジェネリックに渡せない
|
2023-07-17 00:32:32 +02:00
|
|
|
// const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
|
|
|
// const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
2023-04-08 02:01:42 +02:00
|
|
|
const props = defineProps<{ widget?: Widget<WidgetProps> }>();
|
|
|
|
const emit = defineEmits<{ (ev: "updateProps", props: WidgetProps) }>();
|
2022-01-08 12:30:01 +01:00
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
const { widgetProps, configure } = useWidgetPropsManager(
|
|
|
|
name,
|
2022-01-08 12:30:01 +01:00
|
|
|
widgetPropsDef,
|
|
|
|
props,
|
2023-07-06 03:28:27 +02:00
|
|
|
emit,
|
2022-01-08 12:30:01 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
const items = ref([]);
|
|
|
|
const fetching = ref(true);
|
|
|
|
|
|
|
|
const tick = () => {
|
2023-04-08 02:01:42 +02:00
|
|
|
fetch(`/api/fetch-rss?url=${widgetProps.url}`, {}).then((res) => {
|
|
|
|
res.json().then((feed) => {
|
2022-01-08 12:30:01 +01:00
|
|
|
items.value = feed.items;
|
|
|
|
fetching.value = false;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
watch(() => widgetProps.url, tick);
|
|
|
|
|
2022-06-25 20:12:58 +02:00
|
|
|
useInterval(tick, 60000, {
|
|
|
|
immediate: true,
|
|
|
|
afterMounted: true,
|
2022-01-08 12:30:01 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
defineExpose<WidgetComponentExpose>({
|
|
|
|
name,
|
|
|
|
configure,
|
|
|
|
id: props.widget ? props.widget.id : null,
|
2020-01-29 20:37:25 +01:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.ekmkgxbj {
|
|
|
|
> .feed {
|
|
|
|
padding: 0;
|
|
|
|
font-size: 0.9em;
|
|
|
|
|
2022-06-30 16:45:11 +02:00
|
|
|
> .item {
|
2020-01-29 20:37:25 +01:00
|
|
|
display: block;
|
|
|
|
padding: 8px 16px;
|
2020-10-27 10:11:41 +01:00
|
|
|
color: var(--fg);
|
2020-01-29 20:37:25 +01:00
|
|
|
white-space: nowrap;
|
|
|
|
text-overflow: ellipsis;
|
2021-03-02 14:57:16 +01:00
|
|
|
overflow: hidden;
|
2020-01-29 20:37:25 +01:00
|
|
|
|
|
|
|
&:nth-child(even) {
|
|
|
|
background: rgba(#000, 0.05);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|