123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- import { Linking, Alert } from 'react-native';
- export default class commonutil {
- //获取appCode
- static getAppCode() {
- return '1006';
- }
- static async getFileUserInfo() {
- let a = await global.storage
- .load({
- key: 'userInfo'
- })
- .then((result) => {
- return result;
- })
- .catch((err) => {
- console.log('ERROR' + err.message);
- return null;
- });
- return a;
- }
- static async saveUserInfo() {
- global.storage
- .save({
- key: 'userInfo',
- data: JSON.stringify(global.userInfo)
- })
- .then((result) => {
- return result;
- })
- .catch((err) => {
- return 'error';
- });
- }
- //验证手机号
- static isPoneAvailable(str) {
- let myreg = /^[1][0-9]{10}$/;
- if (str.length == 0 || str == null) {
- return false;
- } else if (!myreg.test(str)) {
- return false;
- } else {
- return true;
- }
- }
- /**
- *map转化为对象(map所有键都是字符串,可以将其转换为对象)
- */
- static strMapToObj(strMap) {
- let obj = Object.create(null);
- for (let [ k, v ] of strMap) {
- obj[k] = v;
- }
- return obj;
- }
- /**
- *map转换为json
- */
- static mapToJson(map) {
- return JSON.stringify(this.strMapToObj(map));
- }
- /**
- *对象转换为Map
- */
- static objToStrMap(obj) {
- let strMap = new Map();
- for (let k of Object.keys(obj)) {
- strMap.set(k, obj[k]);
- }
- return strMap;
- }
- /**
- *json转换为map
- */
- static jsonToMap(jsonStr) {
- return this.objToStrMap(JSON.parse(jsonStr));
- }
- //调用打电话功能
- static callPhone(phone) {
- // let tel = '1008611'; // 目标电话
- Alert.alert('提示', phone, [
- {
- text: '取消',
- onPress: () => {
- console.log('取消');
- }
- },
- {
- text: '确定',
- onPress: () => {
- Linking.canOpenURL('tel:' + phone)
- .then((supported) => {
- if (!supported) {
- console.log('Can not handle tel:' + phone);
- } else {
- return Linking.openURL('tel:' + phone);
- }
- })
- .catch((error) => console.log('tel error', error));
- }
- }
- ]);
- }
- }
|