多维表格
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

41 lines
1.2 KiB

import dayjs from 'dayjs'
import { defineNuxtPlugin, useGlobal, useNuxtApp } from '#imports'
const handleFeedbackForm = async () => {
let { feedbackForm: currentFeedbackForm } = $(useGlobal())
if (!currentFeedbackForm) return
const { $api } = useNuxtApp()
const isFirstTimePolling = !currentFeedbackForm.lastFormPollDate
const now = dayjs()
const lastFormPolledDate = dayjs(currentFeedbackForm.lastFormPollDate)
if (isFirstTimePolling || dayjs.duration(now.diff(lastFormPolledDate)).days() > 0) {
$api.instance
.get('/api/v1/feedback_form')
.then((response) => {
try {
const { data: feedbackForm } = response
if (!feedbackForm.error) {
const isFetchedFormDuplicate = currentFeedbackForm.url === feedbackForm.url
currentFeedbackForm = {
url: feedbackForm.url,
lastFormPollDate: now.toISOString(),
createdAt: feedbackForm.created_at,
isHidden: isFetchedFormDuplicate ? currentFeedbackForm.isHidden : false,
}
}
} catch (e) {}
})
.catch(() => {})
}
}
export default defineNuxtPlugin(() => {
handleFeedbackForm()
})