import {BackHandler, Linking} from "react-native"; import {reduxTools} from '@yoronsoft/js-utils' import Clipboard from '@react-native-clipboard/clipboard'; import {ISystem} from "./system"; import {getConfigName} from "../config"; const system: ISystem = { /** * 退出App * 两次返回时间不超过2秒则退出app * @param timer 时间 */ exit: function (timer?: number): boolean { const name = `${getConfigName}_system_exit_time`; // 当前时间 const currTime = new Date().getTime(); // 结束时间 const lastTime = currTime + (typeof timer === "number" ? timer : 1000); // 获取上次缓存时间 const reduxLastTime = reduxTools.get(name); console.log(currTime < reduxLastTime, currTime, reduxLastTime) // 判断是否在 1 秒内 if (currTime < reduxLastTime) { BackHandler.exitApp() return } // 添加记录 if (typeof reduxLastTime === "undefined") reduxTools.create(name, lastTime); else reduxTools.update(name, lastTime); return false; }, /** * 复制 * @param data 数据 * @param successCallback 成功返回方法 */ copy: function (data: string | number, successCallback?: () => void): void { Clipboard.setString(data.toString()); if (typeof successCallback === "function") successCallback(); }, /** * 剪切板 */ clipboard: async function (): Promise { return await Clipboard.getString() }, /** * 剪切板是否有数据 */ hasClipboard: async function (): Promise { return await Clipboard.hasString() }, /** * 链接跳转 * @param url */ linking: function (url: string): void { Linking.openURL(url).then() } } export default system