UNPKG

imobile_for_reactnative

Version:

iMobile for ReactNative,是SuperMap iMobile推出的一款基于React-Native框架的移动应用开发工具。基于该开发工具,用户可以使用JavaScript开发语言,开发出在Android和IOS操作系统下运行的原生移动GIS应用,入门门槛低,一次开发,处处运行。

146 lines (124 loc) 4.16 kB
import { NativeModules, Platform, NativeEventEmitter } from 'react-native' import { EventConst } from '../../constains' import { QueryParamToStr } from './UrlUtils' import URL from './url' import { request } from '../utils' const IPortalServiceNative = NativeModules.SIPortalService const emitter = new NativeEventEmitter(IPortalServiceNative) let iPortalUrl = '' export function init(serverUrl: string) { if (Platform.OS === 'ios') { return IPortalServiceNative.init() } if (serverUrl) { iPortalUrl = serverUrl } } /** * 退出登录 * @returns 返回退出登录结果 */ export function login(serverUrl: string, userName: string, password: string, remember: boolean): Promise<boolean> { iPortalUrl = serverUrl return IPortalServiceNative.login(serverUrl, userName, password, remember) } /** * 退出登录 * @returns 返回退出登录结果 */ export function logout(): Promise<boolean> { return IPortalServiceNative.logout() } export function getCookie() { return IPortalServiceNative.getIPortalCookie() } export function getIPortalUrl() { return iPortalUrl } export function getUserInfo() { return IPortalServiceNative.getMyAccount() } // export function getMyDatas(page, pageSize) { // return IPortalServiceNative.getMyDatas(page, pageSize) // } export async function getMyContentData(params) { try { let url = getIPortalUrl() + URL.GetMyAccountData[0] + QueryParamToStr(params) let headers = {} let cookie = await getCookie() if (cookie) { headers.cookie = cookie } let result = await request(url, URL.GetMyAccountData[1], { headers: headers, body: {}, }) return result } catch (error) { } } export function deleteMyData(id) { return IPortalServiceNative.deleteMyData(id) } let uploadingFileListener, uploadFileListener export function uploadData(path, fileName, cb) { uploadingFileListener && uploadingFileListener.remove() uploadFileListener && uploadFileListener.remove() if (cb && typeof cb.onProgress === 'function') { uploadingFileListener = emitter.addListener(EventConst.IPORTAL_SERVICE_UPLOADING, function (progress) { cb.onProgress(progress) }) } if (cb && typeof cb.onResult === 'function') { uploadFileListener = emitter.addListener(EventConst.IPORTAL_SERVICE_UPLOADED, function (value) { cb.onResult(value) }) } return IPortalServiceNative.uploadData(path, fileName) } export function uploadDataByType(path, fileName, dataType, cb) { uploadingFileListener && uploadingFileListener.remove() uploadFileListener && uploadFileListener.remove() if (cb && typeof cb.onProgress === 'function') { uploadingFileListener = emitter.addListener(EventConst.IPORTAL_SERVICE_UPLOADING, function (progress) { cb.onProgress(progress) }) } if (cb && typeof cb.onResult === 'function') { uploadFileListener = emitter.addListener(EventConst.IPORTAL_SERVICE_UPLOADED, function (value) { cb.onResult(value) }) } return IPortalServiceNative.uploadDataByType(path, fileName, dataType) } let downloadListener export function downloadMyData(path, id, cb) { downloadListener && downloadListener.remove() downloadListener = emitter.addListener(EventConst.IPORTAL_SERVICE_DOWNLOADING, function (progress) { cb(progress) }) return IPortalServiceNative.downloadMyData(path, id) } export function downloadMyDataByName(path, name, cb) { downloadListener && downloadListener.remove() downloadListener = emitter.addListener(EventConst.IPORTAL_SERVICE_DOWNLOADING, function (progress) { cb(progress) }) return IPortalServiceNative.downloadMyDataByName(path, name) } export function getMyServices(page, pageSize) { return IPortalServiceNative.getMyServices(page, pageSize) } export function deleteMyService(id) { return IPortalServiceNative.deleteMyService(id) } export function publishService(id) { if (Platform.OS === 'ios') { return IPortalServiceNative.publishService(id) } } export function setServicesShareConfig(id, isPublic) { if (Platform.OS === 'ios') { return IPortalServiceNative.setServicesShareConfig(id, isPublic) } }