typings.d.ts 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. declare module 'slash2';
  2. declare module '*.css';
  3. declare module '*.less';
  4. declare module '*.scss';
  5. declare module '*.sass';
  6. declare module '*.svg';
  7. declare module '*.png';
  8. declare module '*.jpg';
  9. declare module '*.jpeg';
  10. declare module '*.gif';
  11. declare module '*.bmp';
  12. declare module '*.webp';
  13. declare module '*.tiff';
  14. declare module 'omit.js';
  15. declare module 'numeral';
  16. declare module 'mockjs';
  17. declare module 'react-fittext';
  18. // CAP widget type declarations
  19. declare module '@cap.js/widget' {
  20. export interface CapWidgetElement extends HTMLElement {
  21. verify: () => Promise<{ token: string }>;
  22. reset: () => void;
  23. }
  24. }
  25. declare namespace JSX {
  26. interface IntrinsicElements {
  27. 'cap-widget': React.DetailedHTMLProps<
  28. React.HTMLAttributes<HTMLElement> & {
  29. id?: string;
  30. 'data-cap-api-endpoint'?: string;
  31. style?: React.CSSProperties;
  32. },
  33. HTMLElement
  34. >;
  35. }
  36. }
  37. declare const REACT_APP_ENV: 'test' | 'dev' | 'pre' | false;
  38. declare namespace NodeJS {
  39. interface ProcessEnv {
  40. /** 环境 */
  41. REACT_APP_ENV?: 'test' | 'dev' | 'pre' | 'prod' | false;
  42. /** 产品ID */
  43. REACT_APP_ID?: string;
  44. /** 产品名称 */
  45. REACT_APP_NAME?: string;
  46. /** 产品版本 */
  47. REACT_APP_VERSION?: string;
  48. /** 构建时间 */
  49. REACT_APP_BUILD_TIME?: number;
  50. /** 存储空间名称 */
  51. STORAGE_NAME_SPACE?: string;
  52. /** 是否启用请求加密 */
  53. ENABLE_REQUEST_ENCRYPTION?: boolean;
  54. /** 请求加密密钥 */
  55. REQUEST_ENCRYPTION_KEY?: string;
  56. /** 是否启用存储加密 */
  57. ENABLE_STORAGE_ENCRYPTION?: boolean;
  58. /** 存储加密密钥 */
  59. STORAGE_ENCRYPTION_KEY?: string;
  60. /** 管理后台登录密钥(对应服务端 Auth.ManagementKey,由前端透明传递,不在表单中展示) */
  61. REACT_APP_MANAGEMENT_KEY?: string;
  62. /** 请求数据压缩方式(nozip / br / gzip),默认 nozip */
  63. REQUEST_DATA_COMPRESSION?: string;
  64. /** 接口服务器地址,开发环境下通常与 proxy 配置配合,将请求代理到 REACT_APP_REAL_API_URL 指定的服务器。生产环境下若 接口服务器 与 web服务器 的地址不同,需配置为完整地址 */
  65. REACT_APP_API_URL?: string;
  66. }
  67. interface DevProcessEnv extends ProcessEnv {
  68. /** 接口服务器的实际地址,不要在项目代码中引用,该配置仅在开发环境中才能被 本地代理服务器 成功引用 */
  69. REACT_APP_REAL_API_URL?: string;
  70. }
  71. }
  72. /**
  73. * 将 T 中的 K 字段设置为可选,其他字段保持不变
  74. * @example
  75. * type User = { id: number; name: string; email?: string };
  76. * type PartialName = PartialFields<User, 'name'>;
  77. * // { id: number; name?: string; email?: string }
  78. */
  79. type PartialFields<T, K extends keyof T> = Partial<Pick<T, K>> & Omit<T, K>;
  80. /**
  81. * 将 T 中除了 K 字段外的其他字段设置为可选,K字段保持不变
  82. * @example
  83. * type User = { id: number; name: string; email?: string };
  84. * type PartialExceptId = PartialExcept<User, 'id'>;
  85. * // { id: number; name?: string; email?: string }
  86. */
  87. type PartialExcept<T, K extends keyof T> = Partial<Omit<T, K>> & Pick<T, K>;
  88. /**
  89. * 将 T 中的 K 字段设置为必需,其他字段保持不变
  90. * @example
  91. * type User = { id: number; name?: string; email?: string };
  92. * type RequiredEmail = RequiredFields<User, 'email'>;
  93. * // { id: number; name?: string; email: string }
  94. */
  95. type RequiredFields<T, K extends keyof T> = Required<Pick<T, K>> & Omit<T, K>;
  96. /**
  97. * 将 T 中除了 K 字段外的其他字段设置为必须,K字段保持不变
  98. * @example
  99. * type User = { id?: number; name?: string; email?: string };
  100. * type RequiredExceptId = RequiredExcept<User, 'id'>;
  101. * // { id?: number; name: string; email: string }
  102. */
  103. type RequiredExcept<T, K extends keyof T> = Required<Omit<T, K>> & Pick<T, K>;
  104. /**
  105. * 将 T 中的 K 字段设置为必选,其他字段可选
  106. * @example
  107. * type User = { id?: number; name?: string; email?: string };
  108. * type RequiredEmail = RequiredKOptionalOthers<User, 'id'>;
  109. * // { id: number; name?: string; email?: string }
  110. */
  111. type RequiredKOptionalOthers<T, K extends keyof T> = Partial<Omit<T, K>> & Required<Pick<T, K>>;
  112. /**
  113. * 将 T 中的 K 字段设置为可选,其他字段必须
  114. * @example
  115. * type User = { id: number; name?: string; email: string };
  116. * type OptionalEmail = OptionalKRequiredOthers<User, 'email'>;
  117. * // { id: number; name: string; email?: string }
  118. */
  119. type OptionalKRequiredOthers<T, K extends keyof T> = Required<Omit<T, K>> & Partial<Pick<T, K>>;
  120. // type Primitive = string | number | boolean | bigint | symbol | undefined | null;
  121. // type Builtin = Primitive | ((...args: any[]) => any) | Date | Error | RegExp;
  122. // type IsArray<T> = T extends any[] ? true : false;
  123. // type IsObject<T> = T extends Builtin
  124. // ? false
  125. // : T extends ReadonlyArray<any>
  126. // ? false
  127. // : T extends object
  128. // ? true
  129. // : false;
  130. // type FormFieldPath<T> = T extends object
  131. // ? {
  132. // [K in keyof T]-?: K extends string
  133. // ? // 单层路径:字符串形式
  134. // | K
  135. // // 嵌套路径:如果是对象且不是数组
  136. // | (IsObject<T[K]> extends true
  137. // ? IsArray<T[K]> extends true
  138. // ? never // 不深入数组内部
  139. // : FormFieldPath<T[K]> extends infer SubPaths
  140. // ? SubPaths extends string
  141. // ? [K, SubPaths] // 二级嵌套
  142. // : SubPaths extends any[]
  143. // ? [K, ...SubPaths] // 多级嵌套
  144. // : never
  145. // : never
  146. // : never)
  147. // : never;
  148. // }[keyof T]
  149. // : never;
  150. type FormFieldPath<T = any> = T extends object ? string | string[] : never;
  151. type ErrorShowType = import('@/defines').ErrorShowType;
  152. type EditorFormMode = 'edit' | 'add' | 'copy';
  153. declare namespace API {
  154. type OPT<T = number | string> = { label: string; value: T; [key: string]: any };
  155. type MenuKey<T = number | string> = { label: string; key: T; [key: string]: any };
  156. type TabKey<T = number | string> = { tab: string; key: T; [key: string]: any };
  157. type Empty = Record<string, never>;
  158. interface Result<T = any> {
  159. success?: boolean;
  160. data?: T;
  161. errorCode?: number;
  162. errorMessage?: string;
  163. showType?: ErrorShowType;
  164. traceId?: string;
  165. host?: string;
  166. }
  167. type ResultEmpty = Result<Empty>;
  168. type SvrResultList<T = any> = Result<{
  169. total: number;
  170. list: T[];
  171. }>;
  172. interface ResultList<T = any> extends Result<T[]> {
  173. total: number;
  174. }
  175. interface AntdPageParams {
  176. current?: number;
  177. pageSize?: number;
  178. keyword?: string;
  179. [key: string]: any;
  180. }
  181. interface CommonListReq {
  182. ids?: number[];
  183. excludeIds?: number[];
  184. }
  185. type ReqList<T> = T & CommonListReq & AntdPageParams;
  186. interface SortBy {
  187. column: string;
  188. asc: boolean;
  189. }
  190. type SvrReqList<T> = T & {
  191. page: number;
  192. pageSize: number;
  193. sortBy?: string | SortBy | SortBy[];
  194. };
  195. interface ReqDelete<T extends number | string = number> {
  196. ids: T[];
  197. }
  198. interface NumberRange {
  199. min?: number;
  200. max?: number;
  201. }
  202. }