global.d.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. // types/global.d.ts
  2. import { AxiosRequestConfig, AxiosResponse } from "axios";
  3. import { VueConstructor } from "vue";
  4. import { ElMessageBox, ElMessage, ElNotification, ElLoading } from "element-ui";
  5. // 声明全局类型
  6. declare global {
  7. // Vue 实例类型扩展
  8. interface Vue {
  9. $message: typeof ElMessage;
  10. $msgbox: typeof ElMessageBox;
  11. $alert: typeof ElMessageBox.alert;
  12. $confirm: typeof ElMessageBox.confirm;
  13. $prompt: typeof ElMessageBox.prompt;
  14. $notify: typeof ElNotification;
  15. $loading: typeof ElLoading.service;
  16. $refs: {
  17. [key: string]: Vue | Element | Vue[] | Element[] | {
  18. validate?: () => Promise<boolean>;
  19. resetFields?: () => void;
  20. clearValidate?: () => void;
  21. [key: string]: any;
  22. };
  23. };
  24. $set: (target: any, key: string | number, value: any) => any;
  25. $delete: (target: any, key: string | number) => void;
  26. $nextTick(
  27. callback?: (this: this) => any
  28. ): Promise<void> | void;
  29. $emit: (event: string, ...args: any[]) => void;
  30. $on: (event: string, callback: Function) => void;
  31. $off: (event?: string, callback?: Function) => void;
  32. $once: (event: string, callback: Function) => void;
  33. }
  34. // 导出Axios类型供全局使用
  35. type AxiosResponse<T = any> = import('axios').AxiosResponse<T>;
  36. type AxiosRequestConfig = import('axios').AxiosRequestConfig;
  37. // 通用API响应类型
  38. interface ApiResponse<T = any> {
  39. code: number;
  40. message: string;
  41. msg?: string;
  42. data: T;
  43. success?: boolean;
  44. timestamp?: number;
  45. }
  46. // 分页数据类型
  47. interface PageResult<T = any> {
  48. records: T[];
  49. total: number;
  50. size: number;
  51. current: number;
  52. pages: number;
  53. orders?: any[];
  54. optimizeCountSql?: boolean;
  55. hitCount?: boolean;
  56. countId?: string | null;
  57. maxLimit?: number | null;
  58. searchCount?: boolean;
  59. }
  60. // 基础查询参数
  61. interface BaseQueryParams {
  62. current?: number;
  63. size?: number;
  64. [key: string]: any;
  65. }
  66. // 基础实体类型
  67. interface BaseEntity {
  68. /** 创建用户ID */
  69. createUser?: string;
  70. /** 创建部门ID */
  71. createDept?: string;
  72. /** 创建时间 */
  73. createTime?: string;
  74. /** 更新用户ID */
  75. updateUser?: string;
  76. /** 更新时间 */
  77. updateTime?: string;
  78. /** 状态 */
  79. status?: number;
  80. /** 是否删除 0-未删除 1-已删除 */
  81. isDeleted?: number;
  82. }
  83. // 下拉选择器选项
  84. interface SelectOption<T = any> {
  85. label: string;
  86. value: T;
  87. disabled?: boolean;
  88. description?: string;
  89. }
  90. // 表单验证规则
  91. interface ValidationRule {
  92. required?: boolean;
  93. message?: string;
  94. trigger?: 'blur' | 'change' | 'submit';
  95. min?: number;
  96. max?: number;
  97. type?: 'string' | 'number' | 'boolean' | 'method' | 'regexp' | 'integer' | 'float' | 'array' | 'object' | 'enum' | 'date' | 'url' | 'hex' | 'email';
  98. minimum?: number;
  99. maximum?: number;
  100. pattern?: RegExp;
  101. validator?: (rule: ValidationRule, value: any, callback: (error?: Error) => void) => void;
  102. }
  103. // Avue 相关类型
  104. interface AvueFormColumn {
  105. prop: string;
  106. label: string;
  107. type?: string;
  108. dicData?: Array<SelectOption>;
  109. rules?: ValidationRule[];
  110. span?: number;
  111. disabled?: boolean;
  112. display?: boolean;
  113. [key: string]: any;
  114. }
  115. interface AvueFormOption {
  116. column: AvueFormColumn[];
  117. labelWidth?: number;
  118. gutter?: number;
  119. menuBtn?: boolean;
  120. submitBtn?: boolean;
  121. emptyBtn?: boolean;
  122. [key: string]: any;
  123. }
  124. interface AvueCrudColumn extends AvueFormColumn {
  125. width?: number;
  126. minWidth?: number;
  127. fixed?: boolean | 'left' | 'right';
  128. sortable?: boolean;
  129. search?: boolean;
  130. hide?: boolean;
  131. [key: string]: any;
  132. }
  133. interface AvueCrudOption {
  134. column: AvueCrudColumn[];
  135. border?: boolean;
  136. stripe?: boolean;
  137. menuAlign?: 'left' | 'center' | 'right';
  138. align?: 'left' | 'center' | 'right';
  139. addBtn?: boolean;
  140. editBtn?: boolean;
  141. delBtn?: boolean;
  142. viewBtn?: boolean;
  143. searchBtn?: boolean;
  144. refreshBtn?: boolean;
  145. columnBtn?: boolean;
  146. page?: boolean;
  147. [key: string]: any;
  148. }
  149. // 用户信息类型
  150. interface UserInfo {
  151. /** 访问令牌 */
  152. access_token?: string;
  153. /** 令牌类型 */
  154. token_type?: string;
  155. /** 刷新令牌 */
  156. refresh_token?: string;
  157. /** 过期时间(秒) */
  158. expires_in?: number;
  159. /** 权限范围 */
  160. scope?: string;
  161. /** 租户ID */
  162. tenant_id?: string;
  163. /** 用户名 */
  164. user_name?: string;
  165. /** 部门父级ID */
  166. dept_pid?: string;
  167. /** 真实姓名 */
  168. real_name?: string;
  169. /** 头像 */
  170. avatar?: string;
  171. /** 公司名称 */
  172. corp_name?: string;
  173. /** 客户端ID */
  174. client_id?: string;
  175. /** 角色名称 */
  176. role_name?: string;
  177. /** 许可证信息 */
  178. license?: string;
  179. /** 岗位ID(多个用逗号分隔) */
  180. post_id?: string;
  181. /** 用户ID */
  182. user_id?: string;
  183. /** 角色ID */
  184. role_id?: string;
  185. /** 昵称 */
  186. nick_name?: string;
  187. /** 公司地址 */
  188. corp_address?: string;
  189. /** OAuth ID */
  190. oauth_id?: string;
  191. /** 详细信息 */
  192. detail?: {
  193. /** 类型 */
  194. type?: string;
  195. [key: string]: any;
  196. };
  197. /** 部门ID */
  198. dept_id?: string;
  199. /** 公司ID */
  200. corp_id?: string | null;
  201. /** 账户名 */
  202. account?: string;
  203. /** JWT ID */
  204. jti?: string;
  205. }
  206. }
  207. export {};