diff --git a/resources/views/business/pages/financial-operations/process-details-content.blade.php b/resources/views/business/pages/financial-operations/process-details-content.blade.php
index 3a979d46..f31e7516 100644
--- a/resources/views/business/pages/financial-operations/process-details-content.blade.php
+++ b/resources/views/business/pages/financial-operations/process-details-content.blade.php
@@ -126,6 +126,65 @@
display: none;
}
+ .process-details-refresh-tools {
+ display: inline-flex;
+ align-items: center;
+ gap: .65rem;
+ margin-left: auto;
+ }
+
+ .process-details-refresh-button {
+ display: inline-flex;
+ height: 1.95rem;
+ align-items: center;
+ justify-content: center;
+ gap: .35rem;
+ padding: 0 .7rem;
+ border: 1px solid var(--vip-content-accent-dark, #856632);
+ border-radius: .45rem;
+ background: #fff;
+ color: var(--vip-content-accent-dark, #856632);
+ font: inherit;
+ font-size: .75rem;
+ font-weight: 600;
+ cursor: pointer;
+ white-space: nowrap;
+ }
+
+ .process-details-refresh-button:hover,
+ .process-details-refresh-button:focus-visible {
+ background: var(--vip-content-accent-soft, #F7F0DE);
+ color: #6A5129;
+ outline: none;
+ box-shadow: 0 0 0 3px rgba(133, 102, 50, .16);
+ }
+
+ .process-details-refresh-button:disabled {
+ border-color: var(--vip-border, #D8D2C7);
+ background: #faf9f6;
+ color: #a49d91;
+ cursor: not-allowed;
+ box-shadow: none;
+ }
+
+ .process-details-refresh-button .material-icons-outlined {
+ font-size: 1rem;
+ }
+
+ .process-details-refresh-button.is-loading .material-icons-outlined {
+ animation: process-details-spin .9s linear infinite;
+ }
+
+ @keyframes process-details-spin {
+ to { transform: rotate(360deg); }
+ }
+
+ @media (prefers-reduced-motion: reduce) {
+ .process-details-refresh-button.is-loading .material-icons-outlined {
+ animation: none;
+ }
+ }
+
.process-details-toolbar {
overflow: visible;
border: 1px solid var(--vip-border, #D8D2C7);
@@ -840,6 +899,12 @@
}
@media (max-width: 640px) {
+ .process-details-refresh-tools {
+ width: 100%;
+ justify-content: flex-end;
+ margin-left: 0;
+ }
+
.process-details-filter-heading {
align-items: flex-start;
flex-direction: column;
@@ -911,7 +976,19 @@
@if (! empty($mirrorSyncedAt))
最近同步:{{ \Modules\EcommerceFinance\Support\OaProcessTime::formatDateTime($mirrorSyncedAt) }}
@endif
-
+
+
+
+
@if ($error)
@@ -1438,6 +1515,9 @@
const refreshUrl = root.dataset.oaRefreshUrl || '';
const statusUrlTemplate = root.dataset.oaRefreshStatusUrl || '';
const statusElement = root.querySelector('[data-oa-refresh-state]');
+ const button = root.querySelector('[data-oa-refresh-button]');
+ const buttonLabel = root.querySelector('[data-oa-refresh-button-label]');
+ const buttonDefaultTitle = button?.title || '';
const refreshIntervalMs = 60 * 60 * 1000;
const pollIntervalMs = 2000;
const pollLimit = 90;
@@ -1450,6 +1530,7 @@
const attemptKey = `oa-refresh-attempt-at:${storageScope}`;
const completedKey = `oa-refresh-completed-at:${storageScope}`;
let nextReloadTimer = null;
+ let busy = false;
const setStatus = (message, isError = false) => {
if (! statusElement) return;
@@ -1457,6 +1538,17 @@
statusElement.classList.toggle('is-error', isError);
};
+ const setBusy = (isBusy) => {
+ busy = isBusy;
+ if (! button) return;
+ button.disabled = isBusy;
+ button.classList.toggle('is-loading', isBusy);
+ button.title = isBusy ? '正在刷新当前页审批中的流程' : buttonDefaultTitle;
+ if (buttonLabel) {
+ buttonLabel.textContent = isBusy ? '刷新中…' : '刷新当前页';
+ }
+ };
+
const statusUrl = (token) => statusUrlTemplate.replace(
'__TOKEN__',
encodeURIComponent(token),
@@ -1476,16 +1568,23 @@
);
};
- const fail = (message, token = null) => {
+ const fail = (message, token = null, manual = false) => {
if (token) storage.removeItem(tokenKey);
storage.setItem(attemptKey, String(Date.now()));
- setStatus(message, false);
+ setBusy(false);
+ setStatus(message, manual);
scheduleNextReload();
};
- const poll = (token, attempt = 0) => {
+ const poll = (token, attempt = 0, manual = false) => {
if (attempt >= pollLimit) {
- fail('本次自动刷新暂未完成,本页继续显示最近镜像;1小时后自动重试。');
+ fail(
+ manual
+ ? '手动刷新暂未完成,本页继续显示最近镜像,可稍后再次点击刷新。'
+ : '本次自动刷新暂未完成,本页继续显示最近镜像;1小时后自动重试。',
+ null,
+ manual,
+ );
return;
}
@@ -1505,28 +1604,106 @@
storage.setItem(attemptKey, completedAt);
storage.setItem(completedKey, completedAt);
storage.removeItem(tokenKey);
- setStatus('本小时审批状态已刷新,正在载入最新数据…');
+ setStatus(
+ manual
+ ? '手动刷新完成,正在载入最新数据…'
+ : '本小时审批状态已刷新,正在载入最新数据…',
+ );
window.setTimeout(() => window.location.reload(), 400);
return;
}
if (state === 'failed') {
fail(
- '本次自动刷新暂未完成,本页继续显示最近镜像;1小时后自动重试。',
+ manual
+ ? '手动刷新暂未完成,本页继续显示最近镜像,可稍后再次点击刷新。'
+ : '本次自动刷新暂未完成,本页继续显示最近镜像;1小时后自动重试。',
token,
+ manual,
);
return;
}
- setStatus('正在按小时刷新当前页审批中的流程…');
- window.setTimeout(() => poll(token, attempt + 1), pollIntervalMs);
+ setStatus(
+ manual
+ ? '正在手动刷新当前页审批中的流程…'
+ : '正在按小时刷新当前页审批中的流程…',
+ );
+ window.setTimeout(
+ () => poll(token, attempt + 1, manual),
+ pollIntervalMs,
+ );
})
.catch(() => fail(
- '本次自动刷新暂未完成,本页继续显示最近镜像;1小时后自动重试。',
+ manual
+ ? '手动刷新暂未完成,本页继续显示最近镜像,可稍后再次点击刷新。'
+ : '本次自动刷新暂未完成,本页继续显示最近镜像;1小时后自动重试。',
token,
+ manual,
));
};
+ const requestRefresh = (manual = false) => {
+ if (busy) return;
+ if (nextReloadTimer) {
+ window.clearTimeout(nextReloadTimer);
+ nextReloadTimer = null;
+ }
+ setBusy(true);
+ storage.setItem(attemptKey, String(Date.now()));
+ setStatus(
+ manual
+ ? '正在手动刷新当前页审批中的流程…'
+ : '正在按小时刷新当前页审批中的流程…',
+ );
+ const requestUrl = `${refreshUrl}&business_ids=${encodeURIComponent(businessIds.join(','))}`;
+ window.fetch(requestUrl, {
+ credentials: 'same-origin',
+ cache: 'no-store',
+ headers: { Accept: 'application/json' },
+ })
+ .then((response) => {
+ if (! response.ok) throw new Error('refresh request rejected');
+ return response.json();
+ })
+ .then((payload) => {
+ if (! payload.queued || ! payload.token) {
+ const completedAt = String(Date.now());
+ storage.setItem(completedKey, completedAt);
+ setBusy(false);
+ setStatus(payload.message || '当前页没有需要刷新的进行中流程。');
+ scheduleNextReload();
+ return;
+ }
+ storage.setItem(tokenKey, payload.token);
+ poll(payload.token, 0, manual);
+ })
+ .catch(() => fail(
+ manual
+ ? '手动刷新暂未完成,本页继续显示最近镜像,可稍后再次点击刷新。'
+ : '本次自动刷新暂未完成,本页继续显示最近镜像;1小时后自动重试。',
+ null,
+ manual,
+ ));
+ };
+
+ button?.addEventListener('click', () => {
+ if (busy) return;
+ const existingToken = storage.getItem(tokenKey);
+ if (existingToken) {
+ if (nextReloadTimer) {
+ window.clearTimeout(nextReloadTimer);
+ nextReloadTimer = null;
+ }
+ setBusy(true);
+ setStatus('正在手动刷新当前页审批中的流程…');
+ poll(existingToken, 0, true);
+ return;
+ }
+ requestRefresh(true);
+ });
+
const existingToken = storage.getItem(tokenKey);
if (existingToken) {
+ setBusy(true);
setStatus('正在按小时刷新当前页审批中的流程…');
poll(existingToken);
return;
@@ -1538,31 +1715,6 @@
return;
}
- storage.setItem(attemptKey, String(Date.now()));
- setStatus('正在按小时刷新当前页审批中的流程…');
- const requestUrl = `${refreshUrl}&business_ids=${encodeURIComponent(businessIds.join(','))}`;
- window.fetch(requestUrl, {
- credentials: 'same-origin',
- cache: 'no-store',
- headers: { Accept: 'application/json' },
- })
- .then((response) => {
- if (! response.ok) throw new Error('refresh request rejected');
- return response.json();
- })
- .then((payload) => {
- if (! payload.queued || ! payload.token) {
- const completedAt = String(Date.now());
- storage.setItem(completedKey, completedAt);
- setStatus(payload.message || '当前页没有需要刷新的进行中流程。');
- scheduleNextReload();
- return;
- }
- storage.setItem(tokenKey, payload.token);
- poll(payload.token);
- })
- .catch(() => fail(
- '本次自动刷新暂未完成,本页继续显示最近镜像;1小时后自动重试。',
- ));
+ requestRefresh(false);
})();
diff --git a/tests/Feature/Business/ProcessDetailsPageTest.php b/tests/Feature/Business/ProcessDetailsPageTest.php
index fe22e178..4b168b9b 100644
--- a/tests/Feature/Business/ProcessDetailsPageTest.php
+++ b/tests/Feature/Business/ProcessDetailsPageTest.php
@@ -126,6 +126,9 @@ class ProcessDetailsPageTest extends FeatureTestCase
->assertSee('data-oa-refresh-url', false)
->assertSee('data-oa-refresh-status-url', false)
->assertSee('data-oa-refresh-user-id', false)
+ ->assertSee('data-oa-refresh-button', false)
+ ->assertSee('刷新当前页')
+ ->assertSee('当前页没有审批中的流程可以刷新')
->assertSee('页面每小时最多定向刷新当前页审批中的流程一次', false)
->assertDontSee('当前节点')
->assertDontSee('出纳节点')
diff --git a/tests/Unit/EcommerceFinance/ProcessDetailsPageDataTest.php b/tests/Unit/EcommerceFinance/ProcessDetailsPageDataTest.php
index 2c8bbf85..19fcd556 100644
--- a/tests/Unit/EcommerceFinance/ProcessDetailsPageDataTest.php
+++ b/tests/Unit/EcommerceFinance/ProcessDetailsPageDataTest.php
@@ -39,6 +39,9 @@ class ProcessDetailsPageDataTest extends TestCase
$this->assertStringContainsString('oa-refresh-attempt-at:', $content);
$this->assertStringContainsString('window.localStorage', $content);
$this->assertStringContainsString('scheduleNextReload', $content);
+ $this->assertStringContainsString('data-oa-refresh-button', $content);
+ $this->assertStringContainsString('requestRefresh(true)', $content);
+ $this->assertStringContainsString('setBusy(true)', $content);
$this->assertStringNotContainsString(
'`oa-refresh-token:${window.location.pathname}${window.location.search}`',
$content,