diff --git a/src/views/dashboard/components/AlumniNews.vue b/src/views/dashboard/components/AlumniNews.vue index 24c85d4..9502e70 100644 --- a/src/views/dashboard/components/AlumniNews.vue +++ b/src/views/dashboard/components/AlumniNews.vue @@ -23,13 +23,19 @@ import { alumniNews } from '@/api/home/index' export default { name: 'AlumniNews', props: { - displayMode: { type: Boolean, default: false } + displayMode: { type: Boolean, default: false }, + rotationPaused: { type: Boolean, default: false } }, data() { return { rows: [], page: 1, lastPage: 1, total: 0, loading: false, error: false, sequence: 0, rotationTimer: null } }, created() { this.load(1) }, mounted() { if (this.displayMode) this.startRotation() }, + watch: { + rotationPaused() { + if (this.displayMode) this.startRotation() + } + }, beforeDestroy() { clearInterval(this.rotationTimer) this.sequence++ @@ -38,11 +44,16 @@ export default { startRotation() { clearInterval(this.rotationTimer) this.rotationTimer = setInterval(() => { - if (!this.loading) this.load(this.page % this.lastPage + 1) + if (this.loading) return + if (this.rotationPaused) { + this.load(this.page) + } else { + this.load(this.page % this.lastPage + 1, true) + } }, 15000) }, changePage(direction) { - if (this.loading) return + if (this.loading && !this.displayMode) return const target = this.page + direction if (this.displayMode) { if (this.lastPage <= 1) return @@ -56,14 +67,14 @@ export default { if (typeof value !== 'string' || !/^https?:\/\//i.test(value.trim())) return '' try { const url = new URL(value.trim()); return ['http:', 'https:'].includes(url.protocol) ? url.href : '' } catch (_) { return '' } }, - async load(page) { + async load(page, automatic = false) { const sequence = ++this.sequence this.loading = true this.error = false try { const result = await alumniNews({ page }, this.displayMode) - if (sequence !== this.sequence) return - if (page > result.last_page && result.last_page >= 1) return this.load(result.last_page) + if (sequence !== this.sequence || (automatic && this.rotationPaused)) return + if (page > result.last_page && result.last_page >= 1) return this.load(result.last_page, automatic) this.rows = result.data this.page = result.current_page this.lastPage = Math.max(1, result.last_page) diff --git a/src/views/dashboard/index.vue b/src/views/dashboard/index.vue index af5fe22..4e7693c 100644 --- a/src/views/dashboard/index.vue +++ b/src/views/dashboard/index.vue @@ -1,5 +1,5 @@