广丰卷烟厂数采质量分析系统
zhuguifei
2026-03-02 80ff784bf60637cd348ae665fc907f7b1e527dd8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import type { AlovaGenerics, AlovaOptions, AlovaRequestAdapter, Method, ResponseCompleteHandler } from 'alova';
 
export type CustomAlovaConfig<AG extends AlovaGenerics> = Omit<
  AlovaOptions<AG>,
  'statesHook' | 'beforeRequest' | 'responded' | 'requestAdapter'
> & {
  /** request adapter. all request of alova will be sent by it. */
  requestAdapter?: AlovaRequestAdapter<AG['RequestConfig'], AG['Response'], AG['ResponseHeader']>;
};
 
export interface RequestOptions<AG extends AlovaGenerics> {
  /**
   * The hook before request
   *
   * For example: You can add header token in this hook
   *
   * @param method alova Method Instance
   */
  onRequest?: AlovaOptions<AG>['beforeRequest'];
  /**
   * The hook to check backend response is success or not
   *
   * @param response alova response
   */
  isBackendSuccess: (response: AG['Response']) => Promise<boolean>;
 
  /** The config to refresh token */
  tokenRefresher?: {
    /** detect the token is expired */
    isExpired(response: AG['Response'], Method: Method<AG>): Promise<boolean> | boolean;
    /** refresh token handler */
    handler(response: AG['Response'], Method: Method<AG>): Promise<void>;
  };
 
  /** The hook after backend request complete */
  onComplete?: ResponseCompleteHandler<AG>;
 
  /**
   * The hook to handle error
   *
   * For example: You can show error message in this hook
   *
   * @param error
   */
  onError?: (error: any, response: AG['Response'] | null, methodInstance: Method<AG>) => any | Promise<any>;
  /**
   * transform backend response when the responseType is json
   *
   * @param response alova response
   */
  transformBackendResponse: (response: AG['Response']) => any;
}