Skip to content

Commit d6e50d9

Browse files
Merge branch 'optimize-common'
2 parents bef75c7 + 8a78b57 commit d6e50d9

File tree

62 files changed

+698
-366
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+698
-366
lines changed

src/common/iServer/AddressMatchService.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,16 @@ export class AddressMatchService extends CommonServiceBase {
8585
url,
8686
params,
8787
scope: this,
88-
success(result) {
88+
success(result, options) {
8989
result.eventId = eventId;
90-
this.serviceProcessCompleted(result);
90+
this.serviceProcessCompleted(result, options);
9191
},
92-
failure(result) {
92+
failure(result, options) {
9393
if (result.error) {
9494
result.error.eventId = eventId;
9595
}
9696
result.eventId = eventId;
97-
this.serviceProcessFailed(result);
97+
this.serviceProcessFailed(result, options);
9898
}
9999
});
100100
}
@@ -103,20 +103,20 @@ export class AddressMatchService extends CommonServiceBase {
103103
* @param {Object} result - 服务器返回的结果对象。
104104
* @description 服务流程是否完成
105105
*/
106-
serviceProcessCompleted(result) {
106+
serviceProcessCompleted(result, options) {
107107
if (result.succeed) {
108108
delete result.succeed;
109109
}
110-
super.serviceProcessCompleted(result);
110+
super.serviceProcessCompleted(result, options);
111111
}
112112

113113
/**
114114
* @function AddressMatchService.prototype.serviceProcessCompleted
115115
* @param {Object} result - 服务器返回的结果对象。
116116
* @description 服务流程是否失败
117117
*/
118-
serviceProcessFailed(result) {
119-
super.serviceProcessFailed(result);
118+
serviceProcessFailed(result, options) {
119+
super.serviceProcessFailed(result, options);
120120
}
121121
}
122122

src/common/iServer/ChartQueryService.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export class ChartQueryService extends CommonServiceBase {
128128
* @description 查询完成,执行此方法。
129129
* @param {Object} result - 服务器返回的结果对象。
130130
*/
131-
serviceProcessCompleted(result) {
131+
serviceProcessCompleted(result, options) {
132132
var me = this;
133133
result = Util.transformResult(result);
134134
if (result && result.recordsets && me.format === DataFormat.GEOJSON) {
@@ -140,7 +140,7 @@ export class ChartQueryService extends CommonServiceBase {
140140
}
141141

142142
}
143-
me.events.triggerEvent("processCompleted", {result: result});
143+
me.events.triggerEvent("processCompleted", {result: result, options});
144144
}
145145

146146
/**

src/common/iServer/CommonServiceBase.js

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,10 @@ export class CommonServiceBase {
4343

4444
this.length = null;
4545

46-
this.options = null;
47-
4846
this.totalTimes = null;
4947

5048
this.POLLING_TIMES = 3;
5149

52-
this._processSuccess = null;
53-
54-
this._processFailed = null;
55-
5650
this.isInTheSameDomain = null;
5751

5852
this.withCredentials = false;
@@ -105,7 +99,6 @@ export class CommonServiceBase {
10599
me.totalTimes = null;
106100
}
107101
me.url = null;
108-
me.options = null;
109102
me._processSuccess = null;
110103
me._processFailed = null;
111104
me.isInTheSameDomain = null;
@@ -157,55 +150,66 @@ export class CommonServiceBase {
157150
options.url = SecurityManager.appendCredential(options.url);
158151

159152
me.calculatePollingTimes();
160-
me._processSuccess = options.success;
161-
me._processFailed = options.failure;
162153
options.scope = me;
163-
options.success = me.getUrlCompleted;
164-
options.failure = me.getUrlFailed;
165-
me.options = options;
166-
me._commit(me.options);
154+
var success = options.scope? options.success.bind(options.scope) : options.success;
155+
var failure = options.scope? options.failure.bind(options.scope) : options.failure;
156+
options.success = me.getUrlCompleted(success, options);
157+
options.failure = me.getUrlFailed(failure, options);
158+
me._commit(options);
167159
}
168160

169161
/**
170162
* @function CommonServiceBase.prototype.getUrlCompleted
171163
* @description 请求成功后执行此方法。
172-
* @param {Object} result - 服务器返回的结果对象。
164+
* @param {Object} cb - 成功回调函数。
165+
* @param {Object} options - 请求参数对象。
166+
* @private
173167
*/
174-
getUrlCompleted(result) {
175-
let me = this;
176-
me._processSuccess(result);
168+
getUrlCompleted(cb, options) {
169+
// @param {Object} result - 服务器返回的结果对象。
170+
return function(result) {
171+
cb && cb(result, options);
172+
}
177173
}
178174

179175
/**
180176
* @function CommonServiceBase.prototype.getUrlFailed
181177
* @description 请求失败后执行此方法。
182-
* @param {Object} result - 服务器返回的结果对象。
178+
179+
* @param {Object} cb - 失败回调函数。
180+
* @param {Object} options - 请求参数对象。
181+
* @private
183182
*/
184-
getUrlFailed(result) {
185-
let me = this;
183+
getUrlFailed(cb, options) {
184+
const me = this;
185+
// @param {Object} result - 服务器返回的结果对象。
186+
return function(result) {
186187
if (me.totalTimes > 0) {
187-
me.totalTimes--;
188-
me.ajaxPolling();
188+
me.totalTimes--;
189+
me.ajaxPolling(options);
189190
} else {
190-
me._processFailed(result);
191+
cb && cb(result, options);
191192
}
192-
}
193+
}
194+
}
193195

194196
/**
195197
*
196198
* @function CommonServiceBase.prototype.ajaxPolling
197199
* @description 请求失败后,如果剩余请求失败次数不为 0,重新获取 URL 发送请求。
200+
* @param {Object} options - 请求参数对象。
201+
* @private
198202
*/
199-
ajaxPolling() {
203+
ajaxPolling(options) {
200204
let me = this,
201-
url = me.options.url,
205+
url = options.url,
202206
re = /^http:\/\/([a-z]{9}|(\d+\.){3}\d+):\d{0,4}/;
203207
me.index = parseInt(Math.random() * me.length);
204208
me.url = me.urls[me.index];
205209
url = url.replace(re, re.exec(me.url)[0]);
206-
me.options.url = url;
207-
me.options.isInTheSameDomain = Util.isInTheSameDomain(url);
208-
me._commit(me.options);
210+
options.url = url;
211+
options.isInTheSameDomain = Util.isInTheSameDomain(url);
212+
me._commit(options);
209213
}
210214

211215
/**
@@ -249,24 +253,30 @@ export class CommonServiceBase {
249253
* @function CommonServiceBase.prototype.serviceProcessCompleted
250254
* @description 状态完成,执行此方法。
251255
* @param {Object} result - 服务器返回的结果对象。
256+
* @param {Object} options - 请求参数对象。
257+
* @private
252258
*/
253-
serviceProcessCompleted(result) {
259+
serviceProcessCompleted(result, options) {
254260
result = Util.transformResult(result);
255261
this.events.triggerEvent('processCompleted', {
256-
result: result
262+
result: result,
263+
options: options
257264
});
258265
}
259266

260267
/**
261268
* @function CommonServiceBase.prototype.serviceProcessFailed
262269
* @description 状态失败,执行此方法。
263270
* @param {Object} result - 服务器返回的结果对象。
271+
* @param {Object} options - 请求参数对象。对象
272+
* @private
264273
*/
265-
serviceProcessFailed(result) {
274+
serviceProcessFailed(result, options) {
266275
result = Util.transformResult(result);
267276
let error = result.error || result;
268277
this.events.triggerEvent('processFailed', {
269-
error: error
278+
error: error,
279+
options: options
270280
});
271281
}
272282

@@ -376,4 +386,5 @@ export class CommonServiceBase {
376386
* @param {Object} serviceResult.object 发布应用程序事件的对象。
377387
* @param {Object} serviceResult.type 事件类型。
378388
* @param {Object} serviceResult.element 接受浏览器事件的 DOM 节点。
389+
* @param {Object} serviceResult.options 请求参数。
379390
*/

src/common/iServer/DatasetService.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,16 @@ export class DatasetService extends CommonServiceBase {
117117
url,
118118
method,
119119
scope: me,
120-
success(result) {
120+
success(result, options) {
121121
result.eventId = eventId;
122-
me.serviceProcessCompleted(result);
122+
me.serviceProcessCompleted(result, options);
123123
},
124-
failure(result) {
124+
failure(result, options) {
125125
if (result.error) {
126126
result.error.eventId = eventId;
127127
}
128128
result.eventId = eventId;
129-
me.serviceProcessFailed(result);
129+
me.serviceProcessFailed(result, options);
130130
}
131131
}
132132
params && (requestConfig.data = Util.toJSON(params));

src/common/iServer/DatasourceService.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,16 @@ export class DatasourceService extends CommonServiceBase {
9494
url,
9595
method,
9696
scope: me,
97-
success(result) {
97+
success(result, options) {
9898
result.eventId = eventId;
99-
this.serviceProcessCompleted(result);
99+
this.serviceProcessCompleted(result, options);
100100
},
101-
failure(result) {
101+
failure(result, options) {
102102
if (result.error) {
103103
result.error.eventId = eventId;
104104
}
105105
result.eventId = eventId;
106-
this.serviceProcessFailed(result);
106+
this.serviceProcessFailed(result, options);
107107
}
108108
}
109109
params && (requestConfig.data = Util.toJSON(params));

src/common/iServer/FieldService.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export class FieldService {
9595
statisticService.processAsync();
9696
}
9797

98-
_processCompleted(fieldStatisticResult) {
98+
_processCompleted(fieldStatisticResult, options) {
9999
var me = this;
100100
var getAll = true,
101101
result = fieldStatisticResult.result;
@@ -111,7 +111,7 @@ export class FieldService {
111111
}
112112
}
113113
if (getAll) {
114-
me._statisticsCallback({result: me.currentStatisticResult});
114+
me._statisticsCallback({result: me.currentStatisticResult, options});
115115
}
116116
}
117117
}

src/common/iServer/GeoprocessingService.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,29 +78,31 @@ export class GeoprocessingService extends CommonServiceBase {
7878
waitForJobCompletion(jobId, identifier, options, callback) {
7979
const me = this;
8080
const timer = setInterval(function () {
81-
const serviceProcessCompleted = function (serverResult, eventId) {
81+
const serviceProcessCompleted = function (serverResult, options) {
8282
const state = serverResult.state.runState;
8383
if (options.statusCallback) {
8484
options.statusCallback(state);
8585
}
86-
serverResult.eventId = eventId;
8786
switch (state) {
8887
case 'FINISHED':
8988
clearInterval(timer);
9089
me.events.triggerEvent('processCompleted', {
91-
result: serverResult
90+
result: serverResult,
91+
options
9292
});
9393
break;
9494
case 'FAILED':
9595
clearInterval(timer);
9696
me.events.triggerEvent('processFailed', {
97-
result: serverResult
97+
result: serverResult,
98+
options
9899
});
99100
break;
100101
case 'CANCELED':
101102
clearInterval(timer);
102103
me.events.triggerEvent('processFailed', {
103-
result: serverResult
104+
result: serverResult,
105+
options
104106
});
105107
break;
106108
}
@@ -178,18 +180,18 @@ export class GeoprocessingService extends CommonServiceBase {
178180
params: paramter,
179181
headers: { 'Content-type': 'application/json' },
180182
scope: this,
181-
success(result) {
183+
success(result, options) {
182184
result.eventId = eventId;
183185
const callback = serviceProcessCompleted || this.serviceProcessCompleted.bind(this);
184-
callback(result, eventId);
186+
callback(result, options);
185187
},
186-
failure(result) {
188+
failure(result, options) {
187189
if (result.error) {
188190
result.error.eventId = eventId;
189191
}
190192
result.eventId = eventId;
191193
const callback = serviceProcessFailed || this.serviceProcessFailed.bind(this);
192-
callback(result, eventId);
194+
callback(result, options);
193195
}
194196
});
195197
}

src/common/iServer/GetFeaturesServiceBase.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,14 @@ export class GetFeaturesServiceBase extends CommonServiceBase {
140140
* @description 查询完成,执行此方法。
141141
* @param {Object} result - 服务器返回的结果对象。
142142
*/
143-
serviceProcessCompleted(result) {
143+
serviceProcessCompleted(result, options) {
144144
var me = this;
145145
result = Util.transformResult(result);
146146
if (me.format === DataFormat.GEOJSON && result.features) {
147147
var geoJSONFormat = new GeoJSON();
148148
result.features = geoJSONFormat.toGeoJSON(result.features);
149149
}
150-
me.events.triggerEvent("processCompleted", {result: result});
150+
me.events.triggerEvent("processCompleted", {result: result, options});
151151
}
152152

153153
dataFormat() {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy