对amap封装

This commit is contained in:
Wang Kejun 2022-05-19 17:54:12 +08:00
parent dbdad78008
commit 2bbe67f8af
3 changed files with 19 additions and 0 deletions

View File

@ -28,6 +28,7 @@
"mocha": "^8.2.1",
"oak-domain": "file:../oak-domain",
"oak-memory-tree-store": "file:../oak-memory-tree-store",
"oak-wechat-sdk": "file:../oak-wechat-sdk",
"ts-node": "^9.1.1",
"typescript": "^4.5.2"
},

16
src/aspects/amap.ts Normal file
View File

@ -0,0 +1,16 @@
import { AmapSDK, AmapInstance } from 'oak-wechat-sdk';
export async function amap<T extends 'getDrivingPath' | 'regeo' | 'ipLoc' | 'getDistrict' | 'geocode'>(options: {
key: string;
method: T;
data: Parameters<AmapInstance[T]>[0];
}) {
const { key, method, data } = options;
const instance = AmapSDK.getInstance(key);
const fn = instance[method];
if (!fn) {
throw new Error('method not implemented');
}
// data any后面再改
return fn(data as any);
}

View File

@ -1,7 +1,9 @@
import { operate, select } from './crud';
import { amap } from './amap';
const aspectDict = {
operate,
select,
amap,
};
export default aspectDict;