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