uniapp.ts
709 Bytes
import type { Adapter } from '../types';
import { BaseAdapter } from './base';
/**
* UniApp环境适配器实现
*/
class UniAppAdapter extends BaseAdapter {
// 复用基类的 createRequestOptions / executeRequest / transformResponse
protected getPlatformRequester(): (options: any) => { abort: () => void } {
return (opts: any) =>
typeof uni !== 'undefined' && typeof uni.request === 'function'
? uni.request(opts)
: ({ abort: () => {} } as { abort: () => void });
}
}
// 创建适配器实例
const uniAppAdapterInstance = new UniAppAdapter();
// 导出适配器函数
const uniappAdapter: Adapter = uniAppAdapterInstance.createAdapter();
export default uniappAdapter;