perf: 投放账号-同步数据

This commit is contained in:
rd
2025-07-07 10:33:42 +08:00
parent 5d237ec618
commit d054f67652
2 changed files with 47 additions and 12 deletions

View File

@ -16,9 +16,9 @@
<div class="flex items-center mb-20px">
<img :src="icon1" width="16" height="16" class="mr-16px" />
<p class="s2">
检测到该账户最后更新日期为{{ exactFormatTime(lastSyncedAt, 'MM-DD', 'YYYY-MM-DD') }}已有{{
dayjs().diff(dayjs(lastSyncedAt * 1000), 'day')
}}未同步最新数据
检测到该账户最后更新日期为{{ exactFormatTime(lastSyncedAt, 'MMDD日HH:mm', 'YYYYMMDD日 HH:mm') }}已有{{
getDaysDiffText(lastSyncedAt)
}}未同步最新数据
</p>
</div>
<a-radio-group v-model="syncType" class="ml-32px">
@ -65,14 +65,18 @@
import dayjs from 'dayjs';
import { defineExpose, ref, computed, defineEmits } from 'vue';
import { exactFormatTime } from '@/utils/tools';
import { putPlacementAccountsAuthorized, getPlacementAccountsAuthorizedStatus } from '@/api/all/propertyMarketing';
import {
putPlacementAccountsAuthorized,
getPlacementAccountsAuthorizedStatus,
postPlacementAccountsSync,
} from '@/api/all/propertyMarketing';
import icon1 from '@/assets/img/media-account/icon-warn-1.png';
import icon2 from '@/assets/img/media-account/icon-feedback-success.png';
import icon3 from '@/assets/img/media-account/icon-feedback-fail.png';
const emits = defineEmits(['update']);
const INITIAL_SYNC_TYPE = 'sync';
const visible = ref(false);
const isLoading = ref(false);
const isCompleted = ref(false);
@ -81,9 +85,10 @@ const formRef = ref(null);
const failReason = ref('');
const progress = ref(0);
const id = ref('');
const lastSyncedAt = ref(null);
const syncType = ref('sync'); // sync no_sync
const lastSyncedAt = ref(null); // 上次同步时间戳
const showSyncTip = ref(false);
const syncType = ref(INITIAL_SYNC_TYPE); // sync no_sync
const INITIAL_FORM = {
account: '',
@ -111,6 +116,15 @@ const confirmBtnText = computed(() => {
return isSuccess.value ? '继续添加' : '重试';
});
const getDaysDiffText = (lastSyncedAt) => {
if (!lastSyncedAt) return '0天';
const daysDiff = dayjs().diff(dayjs(lastSyncedAt * 1000), 'day');
if (daysDiff === 0) return '不到1天';
return `${daysDiff}`;
};
const open = (accountId, last_synced_at = null) => {
id.value = accountId;
lastSyncedAt.value = last_synced_at;
@ -129,7 +143,7 @@ const close = () => {
progress.value = 0;
id.value = '';
lastSyncedAt.value = null;
syncType.value = 'sync';
syncType.value = INITIAL_SYNC_TYPE;
showSyncTip.value = false;
clearFakeProgressTimer();
clearStatusPollingTimer();
@ -206,8 +220,8 @@ const clearFakeProgressTimer = () => {
}
};
const handleOk = () => {
if (lastSyncedAt.value) {
const handleSyncData = () => {
if (!showSyncTip.value) {
formRef.value.validate(async (errors) => {
if (!errors) {
showSyncTip.value = true;
@ -216,6 +230,23 @@ const handleOk = () => {
return;
}
if (syncType.value === INITIAL_SYNC_TYPE) {
postPlacementAccountsSync(id.value).then((res) => {
if (res.code === 200) {
close();
}
});
} else {
close();
}
};
const handleOk = () => {
if (lastSyncedAt.value && lastSyncedAt.value < dayjs().startOf('day').valueOf()) {
handleSyncData();
return;
}
if (isCompleted.value) {
if (isSuccess.value) {
emits('update');