feat: 授权账户成功后更新数据

This commit is contained in:
rd
2025-07-22 18:24:24 +08:00
parent 39c1f5d3d0
commit 95fc8c7fc0

View File

@ -12,7 +12,7 @@
:footer="!isLoading" :footer="!isLoading"
@close="close" @close="close"
> >
<div v-if="showSyncTip"> <!-- <div v-if="showSyncTip">
<div class="flex items-center mb-20px"> <div class="flex items-center mb-20px">
<img :src="icon1" width="16" height="16" class="mr-16px" /> <img :src="icon1" width="16" height="16" class="mr-16px" />
<p class="s2"> <p class="s2">
@ -25,8 +25,8 @@
<a-radio value="sync" class="mb-16px">立即同步遗漏数据 - 获取完整的最新数据 推荐</a-radio> <a-radio value="sync" class="mb-16px">立即同步遗漏数据 - 获取完整的最新数据 推荐</a-radio>
<a-radio value="no_sync">仅授权不更新 - 继续使用当前不完全的数据</a-radio> <a-radio value="no_sync">仅授权不更新 - 继续使用当前不完全的数据</a-radio>
</a-radio-group> </a-radio-group>
</div> </div> -->
<div v-else class="flex flex-col items-center"> <div class="flex flex-col items-center">
<template v-if="isLoading"> <template v-if="isLoading">
<a-progress <a-progress
:percent="progress" :percent="progress"
@ -81,7 +81,7 @@ import icon2 from '@/assets/img/media-account/icon-feedback-success.png';
import icon3 from '@/assets/img/media-account/icon-feedback-fail.png'; import icon3 from '@/assets/img/media-account/icon-feedback-fail.png';
const update = inject('update'); const update = inject('update');
const INITIAL_SYNC_TYPE = 'sync'; // const INITIAL_SYNC_TYPE = 'sync';
const visible = ref(false); const visible = ref(false);
const isLoading = ref(false); const isLoading = ref(false);
const isCompleted = ref(false); const isCompleted = ref(false);
@ -92,10 +92,10 @@ const progress = ref(0);
const id = ref(''); const id = ref('');
const selectSubAccountModalRef = ref(null); const selectSubAccountModalRef = ref(null);
const lastSyncedAt = ref(null); // 上次同步时间戳 // const lastSyncedAt = ref(null); // 上次同步时间戳
const showSyncTip = ref(false); // const showSyncTip = ref(false);
const shouldSelectSubAccount = ref(false); const shouldSelectSubAccount = ref(false);
const syncType = ref(INITIAL_SYNC_TYPE); // sync no_sync // const syncType = ref(INITIAL_SYNC_TYPE); // sync no_sync
const addAccountFormData = ref(null); // 添加账户表单数据 const addAccountFormData = ref(null); // 添加账户表单数据
const INITIAL_FORM = { const INITIAL_FORM = {
@ -124,20 +124,20 @@ const confirmBtnText = computed(() => {
return isSuccess.value ? '继续添加' : '重试'; return isSuccess.value ? '继续添加' : '重试';
}); });
const getDaysDiffText = (lastSyncedAt) => { // const getDaysDiffText = (lastSyncedAt) => {
if (!lastSyncedAt) return '0天'; // if (!lastSyncedAt) return '0天';
const daysDiff = dayjs().diff(dayjs(lastSyncedAt * 1000), 'day'); // const daysDiff = dayjs().diff(dayjs(lastSyncedAt * 1000), 'day');
if (daysDiff === 0) return '不到1天'; // if (daysDiff === 0) return '不到1天';
return `${daysDiff}`; // return `${daysDiff}天`;
}; // };
const open = ({ accountId, last_synced_at = null, form = null, needSelectSubAccount = false }) => { const open = ({ accountId, last_synced_at = null, form = null, needSelectSubAccount = false }) => {
reset(); reset();
id.value = accountId; id.value = accountId;
lastSyncedAt.value = last_synced_at; // lastSyncedAt.value = last_synced_at;
addAccountFormData.value = form; addAccountFormData.value = form;
shouldSelectSubAccount.value = needSelectSubAccount; shouldSelectSubAccount.value = needSelectSubAccount;
visible.value = true; visible.value = true;
@ -154,9 +154,9 @@ const reset = () => {
failReason.value = ''; failReason.value = '';
progress.value = 0; progress.value = 0;
id.value = ''; id.value = '';
lastSyncedAt.value = null; // lastSyncedAt.value = null;
syncType.value = INITIAL_SYNC_TYPE; // syncType.value = INITIAL_SYNC_TYPE;
showSyncTip.value = false; // showSyncTip.value = false;
shouldSelectSubAccount.value = false; shouldSelectSubAccount.value = false;
addAccountFormData.value = null; addAccountFormData.value = null;
clearFakeProgressTimer(); clearFakeProgressTimer();
@ -191,6 +191,8 @@ const startStatusPolling = () => {
clearFakeProgressTimer(); clearFakeProgressTimer();
clearStatusPollingTimer(); clearStatusPollingTimer();
isLoading.value = false; isLoading.value = false;
isSuccess.value && postPlacementAccountsSync(id.value);
} }
} }
}, 2000); }, 2000);
@ -237,34 +239,34 @@ const clearFakeProgressTimer = () => {
} }
}; };
const handleSyncData = () => { // const handleSyncData = () => {
if (!showSyncTip.value) { // if (!showSyncTip.value) {
formRef.value.validate(async (errors) => { // formRef.value.validate(async (errors) => {
if (!errors) { // if (!errors) {
showSyncTip.value = true; // showSyncTip.value = true;
} // }
}); // });
return; // return;
} // }
if (syncType.value === INITIAL_SYNC_TYPE) { // if (syncType.value === INITIAL_SYNC_TYPE) {
postPlacementAccountsSync(id.value).then((res) => { // postPlacementAccountsSync(id.value).then((res) => {
if (res.code === 200) { // if (res.code === 200) {
update(); // update();
close(); // close();
} // }
}); // });
} else { // } else {
startLoading(); // close();
} // }
}; // };
const handleOk = () => { const handleOk = () => {
// n天未同步更新 // // n天未同步更新
if (lastSyncedAt.value && lastSyncedAt.value < dayjs().startOf('day').valueOf()) { // if (lastSyncedAt.value && lastSyncedAt.value < dayjs().startOf('day').valueOf()) {
handleSyncData(); // handleSyncData();
return; // return;
} // }
// 已完成 // 已完成
if (isCompleted.value) { if (isCompleted.value) {