refactor(client): extract interval logic to a composable function

あと`onUnmounted`を`onMounted`内で呼んでいたりしたのを修正したりとか
This commit is contained in:
syuilo 2022-06-26 03:12:58 +09:00
parent 6a4574b612
commit 5e95a1f7af
18 changed files with 207 additions and 183 deletions

View file

@ -13,9 +13,10 @@
<script lang="ts" setup>
import { nextTick, onMounted, onUnmounted, reactive, ref } from 'vue';
import { GetFormResultType } from '@/scripts/form';
import { useWidgetPropsManager, Widget, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget';
import { GetFormResultType } from '@/scripts/form';
import * as os from '@/os';
import { useInterval } from '@/scripts/use-interval';
const name = 'slideshow';
@ -75,7 +76,7 @@ const fetch = () => {
os.api('drive/files', {
folderId: widgetProps.folderId,
type: 'image/*',
limit: 100
limit: 100,
}).then(res => {
images.value = res;
fetching.value = false;
@ -96,15 +97,15 @@ const choose = () => {
});
};
useInterval(change, 10000, {
immediate: false,
afterMounted: true,
});
onMounted(() => {
if (widgetProps.folderId != null) {
fetch();
}
const intervalId = window.setInterval(change, 10000);
onUnmounted(() => {
window.clearInterval(intervalId);
});
});
defineExpose<WidgetComponentExpose>({