rn_supermap
Version:
rn_supermap 一款基于React-Native框架的移动应用开发工具。基于该开发工具,用户可以使用JavaScript开发语言,开发出在Android和IOS操作系统下运行的原生移动GIS应用,入门门槛低,一次开发,处处运行。
223 lines (204 loc) • 4.66 kB
JavaScript
/**
* Created by will on 2016/7/13.
*/
import {NativeModules, Platform} from 'react-native';
let FU = NativeModules.SMFileUtil;
let FT = NativeModules.FileTools;
/**
* @class Point - 像素点类。用于标示移动设备屏幕的像素点。
*/
export default class SystemUtil {
/**
* 获取沙盒路径
* @returns {Promise.<string>}
*/
async getHomeDirectory() {
try {
var {homeDirectory} = await FU.getHomeDirectory();
return homeDirectory;
} catch (e) {
console.error(e);
}
}
/**
* 获取文件夹中的目录内容
* @param path
* @returns {Promise}
*/
async getDirectoryContent(path) {
try {
let directoryContent = await FU.getDirectoryContent(path);
return directoryContent;
} catch (e) {
console.error(e);
}
}
/**
* 判断文件是否存在
* @param path
* @returns {Promise}
*/
async fileIsExist(path) {
try {
let {isExist} = await FU.fileIsExist(path);
return isExist;
} catch (e) {
console.error(e);
}
}
/**
* 判断文件是否存在在Home Directory中
* @param path
* @returns {Promise}
*/
async fileIsExistInHomeDirectory(path) {
try {
let {isExist} = await FU.fileIsExistInHomeDirectory(path);
return isExist;
} catch (e) {
console.error(e);
}
}
/**
* 创建文件目录
* @param path - 绝对路径
* @returns {Promise}
*/
async createDirectory(path) {
try {
return await FU.createDirectory(path);
} catch (e) {
console.error(e);
}
}
/**
* 获取文件夹内容
* @param path
* @returns {Promise}
*/
async getPathList(path) {
try {
let fileList = await FU.getPathList(path);
return fileList;
} catch (e) {
console.error(e);
}
}
/**
* 根据过滤条件获取文件夹内容
* @param path
* @param filter {name: 文件名, extension: 后缀, type: 文件类型(file | Directory)}
* @returns {Promise}
*/
async getPathListByFilter(path, filter) {
try {
let fileList = await FU.getPathListByFilter(path, filter);
return fileList;
} catch (e) {
console.error(e);
}
}
/**
* 判断是否是文件夹
* @param path
* @returns {Promise.<Promise|*>}
*/
async isDirectory(path) {
try {
let reFUlt = await FU.isDirectory(path);
return reFUlt;
} catch (e) {
console.error(e);
}
}
async zipFile(filePath, targetDir) {
try {
let reFUlt;
if (Platform.OS === 'ios') {
reFUlt = await FT.zipFile(filePath, targetDir);
} else {
reFUlt = await FU.doZipFiles([filePath], targetDir);
}
return reFUlt;
} catch (e) {
console.error(e);
}
}
async zipFiles(filePaths, targetDir) {
try {
let reFUlt;
if (Platform.OS === 'ios') {
reFUlt = await FT.zipFiles(filePaths, targetDir);
} else {
reFUlt = await FU.doZipFiles(filePaths, targetDir);
}
return reFUlt;
} catch (e) {
console.error(e);
}
}
async unZipFile(zipFile, targetPath) {
try {
let reFUlt;
if (Platform.OS === 'ios') {
reFUlt = await FT.unzipFile(zipFile, targetPath);
} else {
reFUlt = await FU.unzipFile(zipFile, targetPath);
}
return reFUlt;
} catch (e) {
console.error(e);
}
}
async deleteFile(zipFile) {
try {
let reFUlt;
if (Platform.OS === 'ios') {
reFUlt = await FT.deleteFile(zipFile);
} else {
reFUlt = await FU.deleteFile(zipFile);
}
await reFUlt;
} catch (e) {
console.error(e);
}
}
async readFile(filePath) {
try {
let {reFUlt} = {};
if (Platform.OS === 'ios') {
reFUlt = await FT.readFile(filePath);
} else {
reFUlt = await FU.readFile(filePath);
}
return reFUlt;
} catch (e) {
console.error(e);
}
}
async writeFile(filePath, strJson) {
try {
let reFUlt;
if (Platform.OS === 'ios') {
reFUlt = await FT.writeToFile(filePath, strJson);
} else {
reFUlt = await FU.writeToFile(filePath, strJson);
}
return reFUlt;
} catch (e) {
console.error(e);
}
}
copyFile(fromPath, toPath) {
try {
if (!fromPath || !toPath) return false
if (Platform.OS === 'ios') {
return FT.copyFile(fromPath, toPath);
} else {
// return FU.writeToFile(filePath, strJson);
}
} catch (e) {
console.error(e);
}
}
}