Repository navigation
Expand file tree
/
Copy pathServiceBase.js
More file actions
107 lines (99 loc) · 3.5 KB
/
Copy pathServiceBase.js
File metadata and controls
107 lines (99 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*********************************************************************************
Copyright © SuperMap. All rights reserved.
Author: Wang zihao
E-mail: pridehao@gmail.com
**********************************************************************************/
import {NativeModules} from 'react-native';
let SB = NativeModules.JSServiceBase;
/**
* @class ServiceBase
* @description iServer 所有服务的基类(*请注意该类所有方法仅支持android端,iOS端请不要调用此方法)。
*/
export default class ServiceBase {
static REQUESTFAILED = "com.supermap.services.ServiceBase.requestFailed";
static REQUESTSUCCESS = "com.supermap.services.ServiceBase.requestSuccess";
static RECEIVERESPONSE = "com.supermap.services.ServiceBase.receiveResponse";
static DATASERVICEFINISHED = "com.supermap.services.ServiceBase.dataServiceFinished";
/**
* 获得URL远程路径
* @memberOf ServiceBase
* @returns {Promise}
*/
async getUrl(){
try{
var url = await SB.getUrl(this._SMServiceBaseId);
return url;
}catch(e){
console.error(e);
}
}
/**
* 设置URL远程路径
* @memberOf ServiceBase
* @param url - URL路径
* @returns {Promise.<void>}
*/
async setUrl(url){
try{
await SB.setUrl(this._SMServiceBaseId,url);
}catch(e){
console.error(e);
}
}
/**
* 设置服务器名称
* @memberOf ServiceBase
* @param serverName - 服务器名称
* @returns {Promise.<void>}
*/
async setServerName(serverName){
try{
await SB.setServerName(this._SMServiceBaseId,serverName);
}catch(e){
console.error(e);
}
}
/**
* 设置相应回调
* @memberOf ServiceBase
* @param {function} requestFailed - 请求失败处理函数
* @param {function} requestSuccess - 请求成功处理函数
* @param {function} receiveResponse - 接受响应处理函数
* @param {function} dataServiceFinished - 数据服务完成处理函数
* @returns {Promise.<void>} -
*/
async setResponseCallback(requestFailed,requestSuccess,receiveResponse,dataServiceFinished){
try {
DeviceEventEmitter.addListener(this.REQUESTFAILED,function (e) {
if(typeof requestFailed == 'function'){
requestFailed(e);
}else{
console.error("Could not find the first argument.");
}
});
DeviceEventEmitter.addListener(this.REQUESTSUCCESS,function (e) {
if(typeof requestSuccess == 'function'){
requestSuccess(e);
}else{
console.error("Could not find the second argument.");
}
});
DeviceEventEmitter.addListener(this.RECEIVERESPONSE,function (e) {
if(typeof receiveResponse == 'function'){
receiveResponse(e);
}else{
console.error("Could not find the second argument.");
}
});
DeviceEventEmitter.addListener(this.DATASERVICEFINISHED,function (e) {
if(typeof dataServiceFinished == 'function'){
dataServiceFinished(e);
}else{
console.error("Could not find the second argument.");
}
});
}catch(e){
console.error(e);
}
}
}