global.d.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /// <reference types="@tarojs/taro" />
  2. declare module '*.png';
  3. declare module '*.gif';
  4. declare module '*.jpg';
  5. declare module '*.jpeg';
  6. declare module '*.svg';
  7. declare module '*.css';
  8. declare module '*.less';
  9. declare module '*.scss';
  10. declare module '*.sass';
  11. declare module '*.styl';
  12. declare namespace NodeJS {
  13. interface ProcessEnv {
  14. /** NODE 内置环境变量, 会影响到最终构建生成产物 */
  15. NODE_ENV: 'development' | 'production';
  16. /** 当前构建的平台 */
  17. TARO_ENV:
  18. | 'weapp'
  19. | 'swan'
  20. | 'alipay'
  21. | 'h5'
  22. | 'rn'
  23. | 'tt'
  24. | 'qq'
  25. | 'jd'
  26. | 'harmony'
  27. | 'jdrn';
  28. /**
  29. * 当前构建的小程序 appid
  30. * @description 若不同环境有不同的小程序,可通过在 env 文件中配置环境变量`TARO_APP_ID`来方便快速切换 appid, 而不必手动去修改 dist/project.config.json 文件
  31. * @see https://taro-docs.jd.com/docs/next/env-mode-config#特殊环境变量-taro_app_id
  32. */
  33. TARO_APP_ID: string;
  34. USE_MSW?: string;
  35. }
  36. }
  37. // Webpack 注入的全局常量
  38. declare const API_BASE_URL_FROM_WEBPACK: string;
  39. declare const MQTT_BROKER_URL_FROM_WEBPACK: string;
  40. // Electron API 类型定义
  41. declare global {
  42. interface Window {
  43. // Electron 主要 API
  44. electronAPI?: {
  45. // 系统操作
  46. exitApp: () => Promise<{ success: boolean }>;
  47. shutdownSystem: () => Promise<{
  48. success: boolean;
  49. error?: string;
  50. requiresAdmin?: boolean;
  51. }>;
  52. // 摄像头权限
  53. checkCameraPermission?: () => Promise<boolean>;
  54. requestCameraPermission?: () => Promise<boolean>;
  55. // 文件保存
  56. saveFile: (options: {
  57. data: ArrayBuffer;
  58. defaultFilename: string;
  59. filters?: Array<{ name: string; extensions: string[] }>;
  60. title?: string;
  61. }) => Promise<{
  62. success: boolean;
  63. filePath?: string;
  64. canceled?: boolean;
  65. error?: string;
  66. }>;
  67. };
  68. // Electron 存储 API
  69. electronStorage?: {
  70. getItem: (key: string) => Promise<string | null>;
  71. setItem: (key: string, value: string) => Promise<void>;
  72. removeItem: (key: string) => Promise<void>;
  73. };
  74. }
  75. }
  76. // Cordova API 类型定义
  77. declare global {
  78. interface Window {
  79. cordova?: any;
  80. // Cordova 文件系统 API
  81. resolveLocalFileSystemURL?: (
  82. path: string,
  83. successCallback: (entry: any) => void,
  84. errorCallback?: (error: any) => void
  85. ) => void;
  86. }
  87. interface Navigator {
  88. camera?: {
  89. getPicture: (
  90. successCallback: (imageData: string) => void,
  91. errorCallback: (error: string) => void,
  92. options: any
  93. ) => void;
  94. };
  95. }
  96. // Cordova Device 插件类型定义
  97. interface CordovaDevice {
  98. cordova: string;
  99. model: string;
  100. platform: string;
  101. uuid: string;
  102. version: string;
  103. manufacturer: string;
  104. isVirtual: boolean;
  105. serial: string;
  106. }
  107. const device: CordovaDevice;
  108. // Cordova Camera 插件类型定义
  109. const Camera: {
  110. DestinationType: {
  111. DATA_URL: number;
  112. FILE_URI: number;
  113. NATIVE_URI: number;
  114. };
  115. PictureSourceType: {
  116. PHOTOLIBRARY: number;
  117. CAMERA: number;
  118. SAVEDPHOTOALBUM: number;
  119. };
  120. EncodingType: {
  121. JPEG: number;
  122. PNG: number;
  123. };
  124. MediaType: {
  125. PICTURE: number;
  126. VIDEO: number;
  127. ALLMEDIA: number;
  128. };
  129. };
  130. }
  131. export {};