diff --git a/components/calculator/parenting.vue b/components/calculator/parenting.vue index addc5ab..ec541f5 100644 --- a/components/calculator/parenting.vue +++ b/components/calculator/parenting.vue @@ -474,7 +474,7 @@ function showChildExpense(tooltipItems) { } const debounceId = ref() -function debounce(func, delay = 100) { +function debounce(func, delay = 150) { return (immediate) => { clearTimeout(debounceId.value) if (immediate) { diff --git a/components/calculator/profile.vue b/components/calculator/profile.vue index 4c4665f..d41437e 100644 --- a/components/calculator/profile.vue +++ b/components/calculator/profile.vue @@ -244,9 +244,7 @@ function openSignInDialog() { async function calculateProfile(options: any = { propagate: true }) { const { propagate = true } = options - customDebounce(() => { - drawProfileChart(propagate) - })(propagate) + drawProfileChart(propagate) } async function drawProfileChart(propagate = false) { @@ -276,21 +274,6 @@ async function drawProfileChart(propagate = false) { } } -const debounceId = ref() -function customDebounce(func, delay = 100) { - return (immediate) => { - clearTimeout(debounceId.value) - if (immediate) { - func() - } else { - debounceId.value = setTimeout(() => { - debounceId.value = undefined - func() - }, delay) - } - } -} - defineExpose({ calculateProfile, toggleSignInDialog diff --git a/components/calculator/retirement.vue b/components/calculator/retirement.vue index 50ec3bc..2649b66 100644 --- a/components/calculator/retirement.vue +++ b/components/calculator/retirement.vue @@ -334,17 +334,11 @@ async function calculateRetirement(options: any = { propagate: true }) { } calculateRetirementExpense() const { propagate = true } = options - const pensionLumpSumDataPromise = new Promise((resolve) => { - customDebounce(async () => { - const pensionLumpSumData = await drawRetirementAssetChart(propagate) - resolve(pensionLumpSumData) - })(false) - // 儲存參數 - if (propagate) { - emits('update:modelValue', retirement.value) - } - }) - return pensionLumpSumDataPromise + const pensionLumpSumData = await drawRetirementAssetChart() + if (propagate) { + emits('update:modelValue', retirement.value) + } + return pensionLumpSumData } function resetData() { retirement.value.insurance.annuity = 0 @@ -549,6 +543,8 @@ function calculateRetirementExpense() { const selectedItem: IOptionItem = props.config.retirementQuartile[qualityLevel - 1] retirement.value.annualExpense = Number(selectedItem.value) } + +const debounceId = ref() async function drawRetirementAssetChart() { if (unableToDraw.value) { return @@ -590,8 +586,6 @@ async function drawRetirementAssetChart() { const retirementAnnualExpenseData: number[] = [] const estateData: number[] = [] - const { careerInsuranceType } = props.profile - // if (['employee', 'entrepreneur'].includes(careerInsuranceType)) { pv = employerContribution + employeeContrubution + employerContributionIncome + employeeContrubutionIncome // 退休前資產累積 for (let i = 1; i <= n; i++) { @@ -611,7 +605,6 @@ async function drawRetirementAssetChart() { } calculatePensionLumpsumTax(fv) - pv += insurance.lumpsum // 退休後退休支出 let insuranceAnnuityInflationModifier = 1 @@ -690,8 +683,11 @@ async function drawRetirementAssetChart() { } // 繪圖 if (pensionChartInstance.value) { - pensionChartInstance.value.data = chartData - pensionChartInstance.value.update() + clearTimeout(debounceId.value) + debounceId.value = setTimeout(() => { + pensionChartInstance.value.data = chartData + pensionChartInstance.value.update() + }, 150) } else { const ctx: any = document.getElementById('pensionChart') const chartInstance = new Chart(ctx, { @@ -734,21 +730,6 @@ const errorMssage = throttle(() => { // ElMessage.error('退休:晚節不保!') }, 4000) -const debounceId = ref() -function customDebounce(func, delay = 100) { - return (immediate) => { - clearTimeout(debounceId.value) - if (immediate) { - func() - } else { - debounceId.value = setTimeout(() => { - debounceId.value = undefined - func() - }, delay) - } - } -} - defineExpose({ calculateRetirement, }); diff --git a/components/calculator/security.vue b/components/calculator/security.vue index 0ea9fce..e858207 100644 --- a/components/calculator/security.vue +++ b/components/calculator/security.vue @@ -374,15 +374,12 @@ function drawLifeAssetChart() { labels: labels.slice(0, yearsToRetirement) } if (securityChartInstance.value) { - const promise = new Promise(async (resolve) => { - clearTimeout(debounceId.value) - debounceId.value = setTimeout(async () => { - debounceId.value = undefined - securityChartInstance.value.data = chartData - // resolve(principleData) - securityChartInstance.value.update() - }, 150) - }) + clearTimeout(debounceId.value) + debounceId.value = setTimeout(async () => { + debounceId.value = undefined + securityChartInstance.value.data = chartData + securityChartInstance.value.update() + }, 150) } else { const ctx: any = document.getElementById('securityChart') const chartInstance = new Chart(ctx, { diff --git a/components/calculator/spouse.vue b/components/calculator/spouse.vue index 0c5b480..ddd1351 100644 --- a/components/calculator/spouse.vue +++ b/components/calculator/spouse.vue @@ -210,7 +210,7 @@ function drawMarriageChart(propagate = true) { } const debounceId = ref() -function debounce(func, delay = 100) { +function debounce(func, delay = 150) { return (immediate) => { clearTimeout(debounceId.value) if (immediate) {