Commit 61e781a9b2a50623c236d6eb74324815719f00ac

Authored by 柏杨
1 parent ec339061

fix: 修改弹窗

src/pages/Order/Order/index.tsx
@@ -120,7 +120,7 @@ const OrderPage = () => { @@ -120,7 +120,7 @@ const OrderPage = () => {
120 <div className="order-page-container"> 120 <div className="order-page-container">
121 <div id="resizeDiv"></div> 121 <div id="resizeDiv"></div>
122 <div id="resizeDiv"></div> 122 <div id="resizeDiv"></div>
123 - {roleCode === 'SALES_MANAGER' && ( 123 + {roleCode !== 'SALES_MANAGER' && (
124 <Modal 124 <Modal
125 title="订单预警提醒" 125 title="订单预警提醒"
126 open={open} 126 open={open}
src/utils/hooks.ts 0 → 100644
  1 +import { useRef } from 'react';
  2 +
  3 +/**
  4 + * Custom hook to track and manage API requests with debouncing and manual refresh capabilities
  5 + * @param cooldownMs - Cooldown time in milliseconds between automatic requests
  6 + * @returns Object with tracking state and utility functions
  7 + */
  8 +export const useRequestTracker = (cooldownMs = 5000) => {
  9 + // Use a ref to persist the state between renders
  10 + const trackerRef = useRef({
  11 + initialRequestMade: false,
  12 + pendingRequest: false,
  13 + lastRequestTime: 0,
  14 + manualRefresh: false,
  15 + });
  16 +
  17 + /**
  18 + * Checks if a request should be executed based on tracking state
  19 + * @returns boolean - Whether the request should proceed
  20 + */
  21 + const shouldExecuteRequest = () => {
  22 + const now = Date.now();
  23 + const tracker = trackerRef.current;
  24 +
  25 + // Always execute if it's a manual refresh
  26 + if (tracker.manualRefresh) {
  27 + console.log(
  28 + '[Request Tracker] Manual refresh triggered, executing request',
  29 + );
  30 + tracker.manualRefresh = false;
  31 + tracker.lastRequestTime = now;
  32 + return true;
  33 + }
  34 +
  35 + // If there's a pending request, don't execute another
  36 + if (tracker.pendingRequest) {
  37 + console.log('[Request Tracker] Request already in progress, skipping');
  38 + return false;
  39 + }
  40 +
  41 + // For automatic requests (not manually triggered), apply cooldown
  42 + if (
  43 + tracker.initialRequestMade &&
  44 + now - tracker.lastRequestTime < cooldownMs
  45 + ) {
  46 + console.log(
  47 + `[Request Tracker] Cooldown active (${cooldownMs}ms), skipping automatic request`,
  48 + );
  49 + return false;
  50 + }
  51 +
  52 + // Otherwise, allow the request
  53 + console.log('[Request Tracker] Executing request');
  54 + tracker.lastRequestTime = now;
  55 + return true;
  56 + };
  57 +
  58 + /**
  59 + * Marks the beginning of a request
  60 + */
  61 + const startRequest = () => {
  62 + trackerRef.current.pendingRequest = true;
  63 + };
  64 +
  65 + /**
  66 + * Marks the completion of a request
  67 + */
  68 + const finishRequest = () => {
  69 + const tracker = trackerRef.current;
  70 + tracker.pendingRequest = false;
  71 + tracker.initialRequestMade = true;
  72 + };
  73 +
  74 + /**
  75 + * Marks a request as manually triggered (will bypass cooldown)
  76 + */
  77 + const markAsManualRefresh = () => {
  78 + trackerRef.current.manualRefresh = true;
  79 + };
  80 +
  81 + return {
  82 + tracker: trackerRef.current,
  83 + shouldExecuteRequest,
  84 + startRequest,
  85 + finishRequest,
  86 + markAsManualRefresh,
  87 + };
  88 +};