@tmsfe/tms-core 0.0.120 → 0.0.121
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/config.js +2 -4
- package/src/location/index.ts +26 -26
- package/src/mpInfo.js +2 -2
- package/src/request.js +9 -0
package/package.json
CHANGED
package/src/config.js
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
import Request from './request';
|
|
5
5
|
import { getEnvInfo } from './env';
|
|
6
6
|
|
|
7
|
-
const api = new Request();
|
|
8
7
|
const parseAllCfgs = (configPaths, resData, defaultCfgs) => configPaths.map((path, index) => {
|
|
9
8
|
const found = resData.find(cfg => cfg.configPath === path);
|
|
10
9
|
if (found) {
|
|
@@ -61,7 +60,7 @@ function getConfig(configPath, extendAttr = {}, defaultCfg) {
|
|
|
61
60
|
const configPaths = formatConfigPaths(configPath);
|
|
62
61
|
const defaultCfgs = (defaultCfg && (Array.isArray(defaultCfg) ? defaultCfg : [defaultCfg])) || null;
|
|
63
62
|
const extendAttrs = typeof extendAttr === 'string' ? extendAttr : JSON.stringify(extendAttr);
|
|
64
|
-
return
|
|
63
|
+
return Request.getInstance().post('marketing/config', {
|
|
65
64
|
extendAttrs,
|
|
66
65
|
configPaths,
|
|
67
66
|
})
|
|
@@ -104,8 +103,7 @@ function getApolloConfig(configPath, extendAttr = {}, defaultCfg) {
|
|
|
104
103
|
const configPaths = formatConfigPaths(configPath);
|
|
105
104
|
const defaultCfgs = (defaultCfg && (Array.isArray(defaultCfg) ? defaultCfg : [defaultCfg])) || null;
|
|
106
105
|
const { businessKey, moduleKey, ...extendAttrs } = extendAttr;
|
|
107
|
-
|
|
108
|
-
return api.post('marketing/apollo/config', {
|
|
106
|
+
return Request.getInstance().post('marketing/apollo/config', {
|
|
109
107
|
businessKey,
|
|
110
108
|
moduleKey,
|
|
111
109
|
configPaths,
|
package/src/location/index.ts
CHANGED
|
@@ -37,7 +37,6 @@ interface IpLocationType {
|
|
|
37
37
|
},
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
const request = new Request();
|
|
41
40
|
const event = new EventDispatcher();
|
|
42
41
|
|
|
43
42
|
const userLocationCache: UserLocationType = {}; // 获取位置缓存
|
|
@@ -104,35 +103,36 @@ class Location extends LocationBase {
|
|
|
104
103
|
return userLocationCache[cacheName];
|
|
105
104
|
}
|
|
106
105
|
|
|
107
|
-
userLocationCache[cacheName] =
|
|
108
|
-
|
|
106
|
+
userLocationCache[cacheName] = Request.getInstance().post('basic/lbs/decode', { lat, lng, getPoi })
|
|
107
|
+
.then((res) => {
|
|
108
|
+
const { errCode, resData = {} } = res;
|
|
109
109
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
if (errCode === 0) {
|
|
111
|
+
const { result = {} } = resData;
|
|
112
|
+
const { ad_info: adInfo = {} } = result;
|
|
113
113
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
114
|
+
const loc = {
|
|
115
|
+
nationCode: adInfo.nation_code,
|
|
116
|
+
province: adInfo.province,
|
|
117
|
+
cityName: adInfo.city,
|
|
118
|
+
district: adInfo.district,
|
|
119
|
+
adCode: adInfo.adcode,
|
|
120
|
+
cityCode: formatCityCode(adInfo.city_code, adInfo.nation_code),
|
|
121
|
+
latitude: lat,
|
|
122
|
+
longitude: lng,
|
|
123
|
+
};
|
|
124
124
|
|
|
125
|
-
|
|
125
|
+
if (getPoi === 0) {
|
|
126
|
+
return loc;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
loc.adCode = adInfo.adcode;
|
|
130
|
+
(loc as typeof loc & { poi: object }).poi = formatPoi(result);
|
|
126
131
|
return loc;
|
|
127
132
|
}
|
|
128
133
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
return loc;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return Promise.reject(res);
|
|
135
|
-
})
|
|
134
|
+
return Promise.reject(res);
|
|
135
|
+
})
|
|
136
136
|
.catch(err => Promise.reject(err));
|
|
137
137
|
|
|
138
138
|
return userLocationCache[cacheName];
|
|
@@ -324,7 +324,7 @@ class Location extends LocationBase {
|
|
|
324
324
|
const { latitude, longitude } = (await this.getMergedLocation() as PostionType);
|
|
325
325
|
from = `${latitude},${longitude}`;
|
|
326
326
|
}
|
|
327
|
-
return
|
|
327
|
+
return Request.getInstance().post('basic/lbs/direction', { from, to, mode });
|
|
328
328
|
}
|
|
329
329
|
|
|
330
330
|
/**
|
|
@@ -336,7 +336,7 @@ class Location extends LocationBase {
|
|
|
336
336
|
getIpLocation(force = false): Promise<IpLocationType> {
|
|
337
337
|
if (ipLocationPromise === null || force) {
|
|
338
338
|
ipLocationPromise = new Promise((resolve, reject) => {
|
|
339
|
-
|
|
339
|
+
Request.getInstance().post('basic/lbs/decodeip')
|
|
340
340
|
.then((res) => {
|
|
341
341
|
if (res.errCode === 0) {
|
|
342
342
|
resolve(res.resData as IpLocationType);
|
package/src/mpInfo.js
CHANGED
|
@@ -16,7 +16,7 @@ import Request from './request';
|
|
|
16
16
|
* tms.getMpOpenId('xxx', '111')
|
|
17
17
|
*/
|
|
18
18
|
async function getMpOpenId(mpId, userId) {
|
|
19
|
-
const { resData } = await
|
|
19
|
+
const { resData } = await Request.getInstance().post('user/mpinfo', { userId, mpId });
|
|
20
20
|
const { openId = '' } = resData || {};
|
|
21
21
|
return openId;
|
|
22
22
|
}
|
|
@@ -33,7 +33,7 @@ async function getMpOpenId(mpId, userId) {
|
|
|
33
33
|
* tms.getMpOpenId('xxx', '111')
|
|
34
34
|
*/
|
|
35
35
|
async function getOuterOpenId(apiKey) {
|
|
36
|
-
const { resData } = await
|
|
36
|
+
const { resData } = await Request.getInstance().post('user/mpinfo', { mpId: apiKey });
|
|
37
37
|
const { openId = '' } = resData || {};
|
|
38
38
|
return openId;
|
|
39
39
|
}
|
package/src/request.js
CHANGED
|
@@ -110,6 +110,8 @@ const modifyAuthParam = async (param, withAuth) => {
|
|
|
110
110
|
return requestParam;
|
|
111
111
|
};
|
|
112
112
|
|
|
113
|
+
let reqInstance = null;
|
|
114
|
+
|
|
113
115
|
/**
|
|
114
116
|
* @public
|
|
115
117
|
* @class Request
|
|
@@ -129,6 +131,13 @@ export default class Request {
|
|
|
129
131
|
*/
|
|
130
132
|
static defaultSecretKey = '';
|
|
131
133
|
|
|
134
|
+
static getInstance() {
|
|
135
|
+
if (reqInstance === null) {
|
|
136
|
+
reqInstance = new Request();
|
|
137
|
+
}
|
|
138
|
+
return reqInstance;
|
|
139
|
+
}
|
|
140
|
+
|
|
132
141
|
host = '';
|
|
133
142
|
secretKey = '';
|
|
134
143
|
withAuth = true;
|