80 lines
1.9 KiB
TypeScript
80 lines
1.9 KiB
TypeScript
/// <reference types='@dcloudio/types' />
|
|
import 'vue';
|
|
|
|
// ---- globalData 类型定义 ----
|
|
|
|
interface AppRequestTool {
|
|
request: (method: string, url: string, data?: any, options?: any) => Promise<any>;
|
|
get: (url: string, params?: any, options?: any) => Promise<any>;
|
|
post: (url: string, data?: any, options?: any) => Promise<any>;
|
|
put: (url: string, data?: any, options?: any) => Promise<any>;
|
|
del: (url: string, params?: any, options?: any) => Promise<any>;
|
|
}
|
|
|
|
interface AppWebviewTool {
|
|
getUrl: () => string;
|
|
setUrl: (url: string) => string;
|
|
}
|
|
|
|
interface AppTool {
|
|
Request: AppRequestTool;
|
|
Api: Record<string, any>;
|
|
Env: {
|
|
API_BASE_URL: string;
|
|
WEBVIEW_BASE_URL: string;
|
|
REQUEST_TIMEOUT: number;
|
|
APP_NAME: string;
|
|
APP_SUBTITLE: string;
|
|
PROJECT_CODE: string;
|
|
SECURITY_ENABLE: boolean;
|
|
SECURITY_SECRET_KEY: string;
|
|
};
|
|
Webview: AppWebviewTool;
|
|
}
|
|
|
|
interface UserInfo {
|
|
[key: string]: any;
|
|
}
|
|
|
|
interface UserStorage {
|
|
getUserInfo: () => UserInfo | null;
|
|
setUserInfo: (userInfo: UserInfo) => UserInfo | null;
|
|
clearUserInfo: () => void;
|
|
getUserField: (field: string) => any;
|
|
setUserField: (field: string, value: any) => any;
|
|
removeUserField: (field: string) => void;
|
|
}
|
|
|
|
interface AppGlobalData {
|
|
Tool: AppTool;
|
|
ENV: {
|
|
API_BASE_URL: string;
|
|
WEBVIEW_BASE_URL: string;
|
|
REQUEST_TIMEOUT: number;
|
|
APP_NAME: string;
|
|
APP_SUBTITLE: string;
|
|
PROJECT_CODE: string;
|
|
SECURITY_ENABLE: boolean;
|
|
SECURITY_SECRET_KEY: string;
|
|
};
|
|
UserStorage: UserStorage;
|
|
appConfigReady: Promise<any>;
|
|
[key: string]: any;
|
|
}
|
|
|
|
interface AppInstance {
|
|
Tool: AppTool;
|
|
globalData: AppGlobalData;
|
|
}
|
|
|
|
// 扩展 getApp() 返回类型
|
|
declare function getApp(): AppInstance;
|
|
|
|
// ---- Vue 组件选项扩展 ----
|
|
|
|
declare module '@vue/runtime-core' {
|
|
type Hooks = App.AppInstance & Page.PageInstance;
|
|
|
|
interface ComponentCustomOptions extends Hooks {}
|
|
}
|