Skip to content

Commit da6d6be

Browse files
fix 兼容iserver服务构造函数传递 eventlisteners 的写法 review by luox
1 parent d719f9c commit da6d6be

15 files changed

+219
-52
lines changed

src/common/iServer/AddressMatchService.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,13 @@ export class AddressMatchService extends CommonServiceBase {
7979
});
8080
}
8181
/**
82-
* @function AddressMatchService.prototype.serviceProcessCompleted
82+
* @function AddressMatchService.prototype.transformResult
8383
* @param {Object} result - 服务器返回的结果对象。
84-
* @description 服务流程是否完成
84+
* @param {Object} options - 请求参数。
85+
* @return {Object} 转换结果。
86+
* @description 状态完成时转换结果。
8587
*/
86-
serviceProcessCompleted(result, options) {
88+
transformResult(result, options) {
8789
if (result.succeed) {
8890
delete result.succeed;
8991
}

src/common/iServer/ChartQueryService.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,13 @@ export class ChartQueryService extends CommonServiceBase {
125125

126126

127127
/**
128-
* @function ChartQueryService.prototype.serviceProcessCompleted
129-
* @description 查询完成,执行此方法
128+
* @function ChartQueryService.prototype.transformResult
129+
* @description 状态完成时转换结果
130130
* @param {Object} result - 服务器返回的结果对象。
131+
* @param {Object} options - 请求参数。
132+
* @return {Object} 转换结果。
131133
*/
132-
serviceProcessCompleted(result, options) {
134+
transformResult(result, options) {
133135
var me = this;
134136
result = Util.transformResult(result);
135137
if (result && result.recordsets && me.format === DataFormat.GEOJSON) {

src/common/iServer/CommonServiceBase.js

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { SecurityManager } from '../security/SecurityManager';
77
import { Util } from '../commontypes/Util';
88
import { JSONFormat } from '../format/JSON';
99
import {DataFormat} from '../REST';
10+
import { FunctionExt } from '../commontypes/BaseTypes';
1011

1112
/**
1213
* @class CommonServiceBase
@@ -25,7 +26,7 @@ export class CommonServiceBase {
2526
constructor(url, options) {
2627
let me = this;
2728

28-
this.EVENT_TYPES = [];
29+
this.EVENT_TYPES = ['processCompleted', 'processFailed'];
2930

3031
this.events = null;
3132

@@ -219,28 +220,63 @@ export class CommonServiceBase {
219220
}
220221

221222
/**
222-
* @function CommonServiceBase.prototype.serviceProcessCompleted
223-
* @description 状态完成,执行此方法
223+
* @function CommonServiceBase.prototype.transformResult
224+
* @description 状态完成时转换结果
224225
* @param {Object} result - 服务器返回的结果对象。
226+
* @param {Object} options - 请求参数。
227+
* @return {Object} 转换结果。
225228
* @private
226229
*/
227-
serviceProcessCompleted(result, options) {
230+
transformResult(result, options) {
228231
result = Util.transformResult(result);
229232
return { result, options };
230233
}
231234

232235
/**
233-
* @function CommonServiceBase.prototype.serviceProcessFailed
234-
* @description 状态失败,执行此方法
236+
* @function CommonServiceBase.prototype.transformErrorResult
237+
* @description 状态失败时转换结果
235238
* @param {Object} result - 服务器返回的结果对象。
239+
* @param {Object} options - 请求参数。
240+
* @return {Object} 转换结果。
236241
* @private
237242
*/
238-
serviceProcessFailed(result, options) {
243+
transformErrorResult(result, options) {
239244
result = Util.transformResult(result);
240245
let error = result.error || result;
241246
return { error, options };
242247
}
243248

249+
/**
250+
* @function CommonServiceBase.prototype.serviceProcessCompleted
251+
* @description 状态完成,执行此方法。
252+
* @param {Object} result - 服务器返回的结果对象。
253+
* @param {Object} options - 请求参数对象。
254+
* @private
255+
*/
256+
serviceProcessCompleted(result, options) {
257+
result = Util.transformResult(result);
258+
this.events.triggerEvent('processCompleted', {
259+
result: result,
260+
options: options
261+
});
262+
}
263+
264+
/**
265+
* @function CommonServiceBase.prototype.serviceProcessFailed
266+
* @description 状态失败,执行此方法。
267+
* @param {Object} result - 服务器返回的结果对象。
268+
* @param {Object} options - 请求参数对象。对象
269+
* @private
270+
*/
271+
serviceProcessFailed(result, options) {
272+
result = Util.transformResult(result);
273+
let error = result.error || result;
274+
this.events.triggerEvent('processFailed', {
275+
error: error,
276+
options: options
277+
});
278+
}
279+
244280
_returnContent(options) {
245281
if (options.scope.format === DataFormat.FGB) {
246282
return false;
@@ -324,14 +360,25 @@ export class CommonServiceBase {
324360
object: this
325361
};
326362
if (requestResult.error) {
327-
response = {...response, ...this.serviceProcessFailed(requestResult, options)};
363+
// 兼容服务在构造函数中使用 eventListeners 的老用法
364+
if (options.failure === this.serviceProcessFailed) {
365+
var failure = options.scope ? FunctionExt.bind(options.failure, options.scope) : options.failure;
366+
failure(requestResult, options);
367+
} else {
368+
response = {...response, ...this.transformErrorResult(requestResult, options)};
328369
response.type = 'processFailed';
329370
options.failure && options.failure(response);
371+
}
330372
} else {
373+
if (options.success === this.serviceProcessCompleted) {
374+
var success = options.scope ? FunctionExt.bind(options.success, options.scope) : options.success;
375+
success(requestResult, options);
376+
} else {
331377
requestResult.succeed = requestResult.succeed == undefined ? true : requestResult.succeed;
332-
response = {...response, ...this.serviceProcessCompleted(requestResult, options)};
378+
response = {...response, ...this.transformResult(requestResult, options)};
333379
response.type = 'processCompleted';
334380
options.success && options.success(response);
381+
}
335382
}
336383
return response;
337384
});

src/common/iServer/GeoprocessingService.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export class GeoprocessingService extends CommonServiceBase {
8282
waitForJobCompletion(jobId, identifier, options, callback) {
8383
const me = this;
8484
const timer = setInterval(function () {
85-
const serviceProcessCompleted = function (serverResult) {
85+
const transformResult = function (serverResult) {
8686
const state = serverResult.result.state.runState;
8787
if (serverResult.options.statusCallback) {
8888
serverResult.options.statusCallback(state);
@@ -92,7 +92,7 @@ export class GeoprocessingService extends CommonServiceBase {
9292
callback(serverResult);
9393
}
9494
};
95-
me._processAsync({ url: `${me.url}/${identifier}/jobs/${jobId}`, callback: serviceProcessCompleted });
95+
me._processAsync({ url: `${me.url}/${identifier}/jobs/${jobId}`, callback: transformResult });
9696
}, options.interval);
9797
}
9898

src/common/iServer/GetFeaturesServiceBase.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,13 @@ export class GetFeaturesServiceBase extends CommonServiceBase {
132132
}
133133

134134
/**
135-
* @function GetFeaturesServiceBase.prototype.getFeatureComplete
136-
* @description 查询完成,执行此方法
135+
* @function GetFeaturesServiceBase.prototype.transformResult
136+
* @description 状态完成时转换结果
137137
* @param {Object} result - 服务器返回的结果对象。
138+
* @param {Object} options - 请求参数。
139+
* @return {Object} 转换结果。
138140
*/
139-
serviceProcessCompleted(result, options) {
141+
transformResult(result, options) {
140142
var me = this;
141143
result = Util.transformResult(result);
142144
if (me.format === DataFormat.GEOJSON && result.features) {

src/common/iServer/GetLayersInfoService.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,13 @@ export class GetLayersInfoService extends CommonServiceBase {
7272
}
7373

7474
/**
75-
* @function GetLayersInfoService.prototype.serviceProcessCompleted
76-
* @description 编辑完成,执行此方法
75+
* @function GetLayersInfoService.prototype.transformResult
76+
* @description 状态完成时转换结果
7777
* @param {Object} result - 服务器返回的结果对象。
78+
* @param {Object} options - 请求参数。
79+
* @return {Object} 转换结果。
7880
*/
79-
serviceProcessCompleted(result, options) {
81+
transformResult(result, options) {
8082
var me = this, existRes, layers, len;
8183
result = Util.transformResult(result);
8284
existRes = !!result && result.length > 0;

src/common/iServer/MapService.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ export class MapService extends CommonServiceBase {
7474
});
7575
}
7676

77-
/*
78-
* Method: getMapStatusCompleted
79-
* 获取地图状态完成,执行此方法
80-
*
81-
* Parameters:
82-
* {Object} result - 服务器返回的结果对象
77+
/**
78+
* @function MapService.prototype.transformResult
79+
* @description 状态完成时转换结果
80+
* @param {Object} result - 服务器返回的结果对象。
81+
* @param {Object} options - 请求参数。
82+
* @return {Object} 转换结果
8383
*/
84-
serviceProcessCompleted(result, options) {
84+
transformResult(result, options) {
8585
result = Util.transformResult(result);
8686
var codeStatus = (result.code >= 200 && result.code < 300) || result.code == 0 || result.code === 304;
8787
var isCodeValid = result.code && codeStatus;

src/common/iServer/NetworkAnalystServiceBase.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ export class NetworkAnalystServiceBase extends CommonServiceBase {
4040
}
4141

4242
/**
43-
* @function NetworkAnalystServiceBase.prototype.serviceProcessCompleted
44-
* @description 分析完成,执行此方法
43+
* @function NetworkAnalystServiceBase.prototype.transformResult
44+
* @description 状态完成时转换结果
4545
* @param {Object} result - 服务器返回的结果对象。
46+
* @param {Object} options - 请求参数。
47+
* @return {Object} 转换结果。
4648
*/
47-
serviceProcessCompleted(result, options) {
49+
transformResult(result, options) {
4850
var me = this, analystResult;
4951
result = Util.transformResult(result);
5052
if (result && me.format === DataFormat.GEOJSON && typeof me.toGeoJSONResult === 'function') {

src/common/iServer/ProcessingServiceBase.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,24 +102,24 @@ export class ProcessingServiceBase extends CommonServiceBase {
102102
return response.json();
103103
}).then(function (result) {
104104
if (result.succeed) {
105-
return me.serviceProcessCompleted(result, seconds, callback, processRunningCallback);
105+
return me.transformResult(result, seconds, callback, processRunningCallback);
106106
} else {
107-
result = me.serviceProcessFailed(result);
107+
result = me.transformErrorResult(result);
108108
result.options = me;
109109
result.type = 'processFailed';
110110
callback(result);
111111
return result;
112112
}
113113
}).catch(function (e) {
114-
e = me.serviceProcessFailed({ error: e });
114+
e = me.transformErrorResult({ error: e });
115115
e.options = me;
116116
e.type = 'processFailed';
117117
callback(e);
118118
return e;
119119
});
120120
}
121121

122-
serviceProcessCompleted(result, seconds, callback, processRunningCallback) {
122+
transformResult(result, seconds, callback, processRunningCallback) {
123123
result = Util.transformResult(result);
124124
seconds = seconds || 1000;
125125
var me = this;

src/common/iServer/QueryServiceBase.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,22 @@ export class QueryServiceBase extends CommonServiceBase {
102102
}
103103
me.returnFeatureWithFieldCaption = params.returnFeatureWithFieldCaption;
104104
return me.request({
105-
method: "POST",
106-
data: jsonParameters,
107-
scope: me,
108-
success: callback,
109-
failure: callback
105+
method: "POST",
106+
data: jsonParameters,
107+
scope: me,
108+
success: callback,
109+
failure: callback
110110
});
111111
}
112112

113113
/**
114-
* @function QueryService.prototype.serviceProcessCompleted
115-
* @description 查询完成,执行此方法
114+
* @function QueryService.prototype.transformResult
115+
* @description 状态完成时转换结果
116116
* @param {Object} result - 服务器返回的结果对象。
117+
* @param {Object} options - 请求参数。
118+
* @return {Object} 转换结果。
117119
*/
118-
serviceProcessCompleted(result, options) {
120+
transformResult(result, options) {
119121
var me = this;
120122
result = Util.transformResult(result);
121123
var geoJSONFormat = new GeoJSON();

0 commit comments

Comments
 (0)