h5与原生app通信的各种功能

时间:2023-02-21 18:13:55
import config from '@/config/index';
import cubeModule from '_public/CubeModule.json';
const _MIDEA_COMMON = 'MideaCommon'; // 通用组件
const _MIDEA_USER = 'MideaUser'; // 用户信息相关
const _MIDEA_BARCODE = 'MideaBarcode'; // 二维码扫描相关
const _MIDEA_MAP = 'MideaMap'; // 地图定位相关
const _MIDEA_PDF = 'MideaPdf'; // 附近展示相关
const _MIDEA_ORG = 'Organization'; // 组织架构相关

const agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];
export default {
    /**
     * 获取设备平台
     * @returns {number} 2-安卓,1-IOS,0-未知
     */
    getPlatForm() {
        const u = navigator.userAgent;
        const isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; // android终端
        const isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); // ios终端
        let flatform = isAndroid ? 2 : isiOS ? 1 : 0;
        return flatform;
    },
    // 判断是不是T信移动客户端
    isTLinkMobile() {
        const userAgent = navigator.userAgent;
        //T信环境
        let isTLinkClient = userAgent.includes("teamwork");
        //是否PC环境
        let IsPC = true;
        for (let v = 0; v < agents.length; v++) {
            if (userAgent.includes(agents[v])) {
                IsPC = false;
                break;
            }
        }
        return !IsPC && isTLinkClient;
    },
    // 判断是不是T信PC端
    isTLinkPC() {
        const userAgent = navigator.userAgent;
        let IsPC = true;
        for (let v = 0; v < agents.length; v++) {
            if (userAgent.includes(agents[v])) {
                IsPC = false;
                break;
            }
        }
        let isTLinkClient = userAgent.includes("teamwork");
        return IsPC && isTLinkClient;
    },
    /**
     * 调用cordova的方法
     * @param name {string} 方法组、类别
     * @param method {string} 方法名称
     * @param params {Array} 参数
     * @return {promise}
     */
    callApi(name, method, params) {
        var promise = new Promise((resolve, reject) => {
            if (window.cordova) {
                try {
                    window.cordova.exec((msg) => {
                        resolve(msg);
                    }, (msg) => {
                        reject(msg)
                    }, name, method, params || [])
                } catch (e) {
                    console.log('_error', 'widget error:', e);
                    reject(e);
                }
            } else {
                console.log('_debug', 'Cordova is not exist');
            }
        });
        return promise;
    },
    // 3.复制  参数 [copy内容]
    copy(param = []) {
        return this.callApi(_MIDEA_COMMON, 'copy', param).then((message) => {
            //成功
        });
    },
    // 4.粘贴  参数 []
    paste(param = []) {
        return this.callApi(_MIDEA_COMMON, 'paste', param).then((message) => {
            //成功
        });
    },
    /**
     * 验证密码,主要用于hr自助认证
     */
    password() {
        return this.callApi(_MIDEA_COMMON, 'authPassword').then((message) => {
            if (message === 0) {
                this.password();
            } else if (message === -1) {
                this.exit();
            }
        })
    },
    /**
     * 显示菜单
     */
    showMenu: function () {
        return this.callApi(_MIDEA_COMMON, 'showMenu', null);
    },
    /**
     * 显示导航
     */
    showNav: function () {
        return this.callApi(_MIDEA_COMMON, 'showNav', null);
    },
    /**
     * 隐藏导航
     */
    hideNav: function () {
        return this.callApi(_MIDEA_COMMON, 'hideNav', null)
    },
    /**
     * 退出应用
     */
    exit: function () {
        return this.callApi(_MIDEA_COMMON, 'exit', null)
    },
    /**
     * 后退
     */
    goBack: function () {
        return this.callApi(_MIDEA_COMMON, 'goBack', null)
    },
    /**
     * 开始监听手机摇动
     */
    shake: function () {
        return this.callApi(_MIDEA_COMMON, 'shake', null);
    },
    /**
     * 停止监听手机摇动
     */
    shakeStop: function () {
        return this.callApi(_MIDEA_COMMON, 'shakeStop', null);
    },
    /**
     * 显示悬浮菜单
     */
    showFloat: function () {
        return this.callApi(_MIDEA_COMMON, 'showFloat', null);
    },
    /**
     * 隐藏悬浮菜单
     */
    hideFloat: function () {
        return this.callApi(_MIDEA_COMMON, 'hideFloat', null);
    },
    /**
     * 获取当前语言
     */
    language: function () {
        if (config.env === 'local') {
            return new Promise((resolve, reject) => {
                resolve({ language: config.language });
            })
        } else {
            return this.callApi(_MIDEA_COMMON, 'language', []);
        }
    },
    /**
     * 获取用户信息
     */
    getUser: function () {
        if (config.env.includes('local')) {
            return config.developer;
        } else {
            return this.callApi(_MIDEA_USER, 'getUser', []);
        }
    },
    /**
     * 跳转到用户详情
     */
    showUser: function (params) {
        return config.env === 'local' ? config.developer : this.callApi(_MIDEA_USER, 'vcard', params);
    },
    /**
     * 58.搜索用户    参数 [type搜索类型0-部门1-职位2-邮箱]
     */
    search: function (p = []) {
        return this.callApi(_MIDEA_BARCODE, 'search', p);
    },
    /**
     * 获取邮箱SID    参数 []
     */
    mailSid: function (p = []) {
        return this.callApi(_MIDEA_BARCODE, 'mailSid', p);
    },
    /**
     * 启动扫码
     */
    scan: function () {
        return this.callApi(_MIDEA_BARCODE, 'scan', null);
    },
    /**
     * 启动扫码
     */
    scanNow: function () {
        return this.callApi(_MIDEA_BARCODE, 'scanNow', null);
    },
    /**
     * 获取扫码结果
     */
    getScanExtra: function () {
        return this.callApi(_MIDEA_BARCODE, 'getScanExtra', null);
    },
    /**
     * 获取位置信息
     * @param arr {array} 参数
     */
    location: function (arr) {
        return this.callApi(_MIDEA_MAP, 'location', arr);
    },
    /** * 62.获取地图定位    参数 [] */
    mapLocation: function (arr) {
        return this.callApi(_MIDEA_MAP, 'mapLocation', arr);
    },

    /**
     * 66.高德开启持续定位    参数 [持续定位更新最小时间间隔,单位毫秒(可选-2000)]
     * @param arr {array} 参数
     */
    startUpdatingLocation: function (arr) {
        return this.callApi(_MIDEA_MAP, 'startUpdatingLocation', arr);
    },
    /**
     * 停止更新位置信息
     */
    stopUpdatingLocation: function () {
        return this.callApi(_MIDEA_MAP, 'stopUpdatingLocation', null);
    },
    /**
     * 68.修改导航标题    参数 ['标题'(必传)]
     */
    modifyNativeTitle: function () {
        return this.callApi(_MIDEA_MAP, 'modifyNativeTitle', null);
    },
    /**
     * 导航
     * @param arr {array} 参数
     */
    navigation: function (arr) {
        return this.callApi(_MIDEA_MAP, 'navTo', arr);
    },
    /**
     * 64.从某地导航至某地    参数 [latitude目的地纬度(必传),longitude目的地经度(必传),from_latitude出发地纬度(必传),from_longitude出发地经度
     */
    navToWithFrom: function (arr) {
        return this.callApi(_MIDEA_MAP, 'navToWithFrom', arr);
    },
    /**
     * 65.获取高德地图单次定位    参数 [(数据类型int,返回坐标系类型,0-默认、1-Baidu、2-MapBar、3-ABC、4-SoSoMap、5-AliYun、6-Google、7-GPS,不建议传值(可选)),(数据类型String,Best高精度,HundredMeters中等精度,精度越高,获取速度越慢(可选))]
     */
    amapLocation: function (arr) {
        return this.callApi(_MIDEA_MAP, 'amapLocation', arr);
    },
    /**
     * 拍照或选择图片
     * @param params {object} 参数
     * @return {*}
     */
    getPicture: function (params) {
        // return promise
        const imgPackageHeader = 'data:image/jpeg;base64,'
        const imgDefaultBase64Code = '/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAABQAAD/4QMpaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLwA8P3hwYWNrZXQgYmVnaW49Iu+7vyIgaWQ9Ilc1TTBNcENlaGlIenJlU3pOVGN6a2M5ZCI/PiA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJBZG9iZSBYTVAgQ29yZSA1LjAtYzA2MCA2MS4xMzQ3NzcsIDIwMTAvMDIvMTItMTc6MzI6MDAgICAgICAgICI+IDxyZGY6UkRGIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyI+IDxyZGY6RGVzY3JpcHRpb24gcmRmOmFib3V0PSIiIHhtbG5zOnhtcD0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLyIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bXA6Q3JlYXRvclRvb2w9IkFkb2JlIFBob3Rvc2hvcCBDUzUgV2luZG93cyIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDozMzM5RDY2ODMyNzQxMUU1QTJENkEwOTg5MjdGQTczNiIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDozMzM5RDY2OTMyNzQxMUU1QTJENkEwOTg5MjdGQTczNiI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOjMzMzlENjY2MzI3NDExRTVBMkQ2QTA5ODkyN0ZBNzM2IiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOjMzMzlENjY3MzI3NDExRTVBMkQ2QTA5ODkyN0ZBNzM2Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+/+4ADkFkb2JlAGTAAAAAAf/bAIQAAgICAgICAgICAgMCAgIDBAMCAgMEBQQEBAQEBQYFBQUFBQUGBgcHCAcHBgkJCgoJCQwMDAwMDAwMDAwMDAwMDAEDAwMFBAUJBgYJDQsJCw0PDg4ODg8PDAwMDAwPDwwMDAwMDA8MDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwM/8AAEQgAEAAQAwERAAIRAQMRAf/EAG8AAAMBAAAAAAAAAAAAAAAAAAQFBggBAAIDAAAAAAAAAAAAAAAAAAMEBQcIEAABBAEDBAMAAAAAAAAAAAABAgMEBQYAERIhMUEHYSIUEQACAgAGAgMBAAAAAAAAAAABAhEDACFREgQFMUFhoRQi/9oADAMBAAIRAxEAPwDWfripp7WwyFy7q13MWmoZtmzXIecYLr0ct8U82vsN+RGq06+pHZt67gqkxMZiNMaH73k3U11ip9hexV3QDAafRywd7BxuorKfDchrKaXjLmTtTVS8cmPl9TP5HUIQ8hTiUOcHgokch46EjronP46IldiqV3T/ACTMQfOsH5wHpOfdddfRY62CsrDqIncCSDBIlYzjXPCbBMsGHy76ehyUxNn0kuvq5UTYLZlPFBbcKipJSElPUjc/Gg8LlfnZmzkqQI9E4a7jrf3pWhAKrYrMD4KiZHg64mLW4tr2WqfdWcq1mrASqVLdW85xHZIUskgDwOw0tbc9rbnJJ+c8SHG4tXGTZUgVdAAB9Y//2Q=='

        if (config.env === 'local') { // 本地调试
            return new Promise((resolve, reject) => {
                resolve({
                    base64Code: imgDefaultBase64Code,
                    base64Url: imgPackageHeader + imgDefaultBase64Code
                });
            })
        } else { // 测试或者生产环境
            let opt = {
                quality: params.quality || 50,
                destinationType: params.destinationType || 0,
                allowEdit: params.allowEdit || false,
                encodingType: params.encodingType || 0,
                saveToPhotoAlbum: params.saveToPhotoAlbum || false,
                sourceType: params.sourceType || 0,
                mediaType: params.mediaType || 0,
                correctOrientation: params.correctOrientation || true,
                cameraDirection: params.cameraDirection || 0
            }
            if (params.sourceType == 0) {
                return new Promise(async (resolve, reject) => {
                    try {
                        const res = await this.callApi(_MIDEA_COMMON, 'getPicture', ['1', '0']);
                        return resolve({
                            base64Code: res[0],
                            base64Url: imgPackageHeader + res[0]
                        });
                    } catch (e) {
                        console.log('_warn', 'Cordova maybe not exist.')
                        reject(e)
                    };
                });
            } else {
                return new Promise((resolve, reject) => {
                    try {
                        navigator.camera.getPicture(
                            async (data) => {
                                let base64Url = imgPackageHeader + data;
                                if (data.indexOf("file://") > -1) { //安卓拍照
                                    const obj = await this.callApi('MideaCommon', 'getBase64s', [data]);
                                    base64Url = imgPackageHeader + obj.base64[0];
                                    // Indicator.close()
                                    resolve({
                                        base64Code: data,
                                        base64Url: base64Url
                                    });
                                } else {
                                    resolve({
                                        base64Code: data,
                                        base64Url: base64Url
                                    });
                                }
                            },
                            (data) => {
                                Indicator.close();
                                reject(data);
                            }, opt)
                    } catch (e) {
                        console.log('_warn', 'Cordova maybe not exist.');
                        reject(e);
                    }
                })
            }
        }
    },
    /**
     * 获取通讯录
     * @param fields {string} 查找内容
     * @param options {array} 参数
     * @return {*}
     */
    getContact: function (fields, options) {
        var promise = new Promise((resolve, reject) => {
            try {
                navigator.service.contacts.find(fields,
                    function (msg) { resolve(msg) },
                    function (msg) { reject(msg) }, options)
            } catch (e) {
                console.log('_warn', 'Cordova maybe not exist.');
                reject(e);
            }
        });
        return promise;
    },
    /**
     * 组织架构单选
     */
    orgChoose: function () {
        return this.callApi(_MIDEA_USER, 'orgChoose', null);
    },
    /**
     * 组织架构多选
     * @param p {array} 参数
     */
    orgMuChoose: function (p) {
        return this.callApi(_MIDEA_USER, 'orgMuChoose', p);
    },
    /**
     *  56.部门选择    参数 ['orgidString_1','orgidString_2','orgidString_3',...]
     */
    departmentChoose: function (p = []) {
        return this.callApi(_MIDEA_USER, 'departmentChoose', p);
    },
    /**
     * 根据组织id获取组织内容
     * @param p {array} 参数
     * {
        "withChild": true,
        "withUser": true,
        "departId": orgId
      }
     */
    fetchDepart: function (p) {
        return this.callApi(_MIDEA_ORG, 'fetchDepart', p);
    },
    /**
     * 改变状态栏颜色-仅IOS
     * @param p {array} 参数 [r, g, b]
     */
    changeColor: function (p) {
        return this.callApi(_MIDEA_COMMON, 'statusBarColor', p);
    },
    /**
     * 登出,注销用户
     */
    logout: function () {
        return this.callApi(_MIDEA_COMMON, 'logout', null);
    },
    /**
     * 获取webview信息
     */
    webview: function () {
        return this.callApi(_MIDEA_COMMON, 'webview', null);
    },
    /**
     * 获取屏幕信息
     */
    screen: function () {
        return this.callApi(_MIDEA_COMMON, 'screen', null);
    },
    /**
     * 获取额外启动参数
     * @param params {array} 参数
     */
    getExtra: function (params) {
        return this.callApi(_MIDEA_COMMON, 'getExtra', params || [cubeModule.identify])
    },
    /**
     * 获取设备信息
     */
    getDeviceInfo: function () {
        return this.callApi(_MIDEA_COMMON, 'getDeviceInfo', null);
    },
    /**
     * 19.开启手机横竖屏    参数 [0表示关闭,1表示开启,2表示横竖屏都支持,3表示竖屏]
     */
    orientation: function (param = []) {
        return this.callApi(_MIDEA_COMMON, 'orientation', param);
    },
    /**
     * 52.设置手机横竖屏    参数 [0或者1(0竖屏,1横屏 必传)]
     */
    setScreenOrientation: function (param = []) {
        return this.callApi(_MIDEA_COMMON, 'setScreenOrientation', param);
    },
    /**
     * 用外部浏览器打开链接
     * @param url {string} 链接地址url
     */
    openUrl: function (url) {
        return this.callApi(_MIDEA_COMMON, 'openSysBrowser', [url]);
    },
    /**
     * 21.检测应用是否安装    参数 [程序包名]
     */
    apk: function (param = []) {
        return this.callApi(_MIDEA_COMMON, 'apk', param);
    },
    /**
     * 22.启动指定原生APP    参数 [参数1:包名的id 参数2:该包名的appkey 用户传输密码密文]
     */
    startApp: function (param = []) {
        return this.callApi(_MIDEA_COMMON, 'startApp', param);
    },
    /**
     * h5事件监听 Bugly设置关键数据    参数 [{"key":"key","value":"value"}]
     * @param params {array} 参数
     */
    statistics: function (params) {
        return this.callApi(_MIDEA_COMMON, 'onEvent', params);
    },
    /**
     * 36.调用银联    参数 [订单信息]
     */
    callUpPay: function (params) {
        return this.callApi(_MIDEA_COMMON, 'callUpPay', params);
    },
    /**
     * 37.获取当前H5轻应用信息    参数 []
     */
    appLogInfo: function (params) {
        return this.callApi(_MIDEA_COMMON, 'appLogInfo', params);
    },
    /**
     * 38.切换H5轻应用    参数 [pluginId(切换的目标H5标识)]
     */
    openApp: function (params) {
        return this.callApi(_MIDEA_COMMON, 'openApp', params);
    },
    /**
     * 39.打开在线文件    参数 [fileUrl文件地址(必传),title文件标题(可选)]
     */
    previewFile: function (params) {
        return this.callApi(_MIDEA_COMMON, 'previewFile', params);
    },
    /**
     * 分享
     * @param params {array} 参数
     */
    share: function (params) {
        return this.callApi(_MIDEA_COMMON, 'share', params);
    },
    /**
     * 50.分享选择器    参数 [{title: '测试',subTitle: '',action: 'openH5',widgetId: '', widgetExtra: '',imageUrl: '',actionType: 1,shareRange: 2,url:''}]
     */
    showShare: function (param = []) {
        return this.callApi(_MIDEA_COMMON, 'showShare', param);
    },
    /**
     *  51.跳转指定用户单聊页面    参数 [uid 用户UID(必传),name 昵称(可选,默认取用户详情名字)]
     */
    chatMessage: function (param = []) {
        return this.callApi(_MIDEA_COMMON, 'chatMessage', param);
    },
    /**
     * 打开应用页面
     */
    showAppView: function () {
        return this.callApi(_MIDEA_COMMON, 'showAppView', ['messageView']);
    },
    /**
     * 打开时间日期选择
     * @param params {array} 参数
     * @return {*}
     */
    showPicker: function (params) {
        var promise = new Promise((resolve, reject) => {
            if (window.datePicker) {
                params = Object.assign({
                    date: new Date(),
                    mode: 'date',
                    type: 'day'
                }, params);

                window.datePicker && window.datePicker.show(params, function (date) {
                    resolve(date);
                })
            } else {
                console.log('_debug', 'datePicker is not exist')
            }
        });
        return promise;
    },
    /**
     * 打开通讯录
     */
    getPhoneMan: function () {
        return this.callApi(_MIDEA_USER, 'getContact', null);
    },
    /**
     * 打开个人设置页面
     */
    goPersonalSet: function () {
        return this.callApi(_MIDEA_COMMON, 'showSetView', null);
    },
    /**
     * 打开“我的”页面
     */
    goMyView: function () {
        return this.callApi(_MIDEA_COMMON, 'showMyView', null);
    },
    /**
     * 打开widget
     * @param params {array} 参数
     */
    showWidget: function (params) {
        return this.callApi(_MIDEA_COMMON, 'showWidget', params);
    },
    /**
     * 显示键盘
     */
    showInput: function () {
        return this.callApi(_MIDEA_COMMON, 'showInput', null);
    },
    /**
     * 隐藏键盘
     * @return {*|promise}
     */
    hideInput: function () {
        return this.callApi(_MIDEA_COMMON, 'hideInput', null);
    },
    /**
     * 打开消息页面
     */
    showMessageView: function () {
        return this.callApi(_MIDEA_COMMON, 'showAppView', ['messageView']);
    },
    /**
     * 批量将图片转换成base64码
     * @param pictureList {array} 图片列表
     */
    getBase64CodeFromPictures: function (pictureList) {
        return this.callApi(_MIDEA_COMMON, 'getBase64s', pictureList);
    },
    /**
     * 跳转到系统设置页面,
     * @param arr arr[0]为要跳转的对应的设置页面,暂时支持  蜂窝网络:CellularNetWork,WIFI:WIFI
     * @returns {*}
     */
    gotoSystemSetting: function (arr) {
        return this.callApi(_MIDEA_COMMON, 'gotoSystemSetting', arr);
    },
    /**
     * 附件展示
     * @param param {array} 附件链接url列表
     */
    showPdf: function (param) {
        return this.callApi(_MIDEA_PDF, 'showPdf', param);
    },
    /**
     * 附件txt展示
     * @param param {array} 参数
     */
    showTxt: function (param) {
        return this.callApi(_MIDEA_PDF, 'showTxt', param);
    },
    /**
     * @description 获取底座密码
     */
    getUserPassword: function () {
        return this.callApi(_MIDEA_USER, 'getUserPassword', []);
    },
    /**
     * @description 打电话(底座有bug)
     * @param phoneNumber {string}
     */
    callPhone: function (phoneNumber) {
        return this.callApi(_MIDEA_COMMON, 'callPhone', [phoneNumber]);
    },
    /**
     *  是否禁用webview橡皮筋效果
     * @param params params '1': 启用 '0': 禁止
     * @returns {*}
     */
    setBounces(params) {
        return this.callApi(_MIDEA_COMMON, 'setBounces', [params]);
    },
    /**
     *  41.发送卡片消息    参数 [uid发送目标uid(必传),content发送内容(必传),title卡片消息标题(必传),description卡片消息摘要(必传),icon卡片消息icon url(必传)]
     */
    sendCardMessage(param = []) {
        return this.callApi(_MIDEA_COMMON, 'sendCardMessage', param);
    },
    /**
     *  42.添加T信隐形水印    参数 [图片base64字符串(),水印文字()]
     */
    addTChatWaterMask(param = []) {
        return this.callApi(_MIDEA_COMMON, 'addTChatWaterMask', param);
    },
    /**
     *  43.预览多张图片    参数 [[{"type":"0-在线url,1-base64","data":"base64或者在线url"}](必传),参数数组顺序1,选择首张预览位置(可传)]
     */
    previewPicture(param = []) {
        return this.callApi(_MIDEA_COMMON, 'previewPicture', param);
    },
    /**
     *  44.播放在线视频    参数 [视频地址url]
     */
    playVideo(param = []) {
        return this.callApi(_MIDEA_COMMON, 'playVideo', param);
    },
    /**
     *  45.录制视频    参数 [time录制视频最大长度(可选)]
     */
    videoRecord(param = []) {
        return this.callApi(_MIDEA_COMMON, 'videoRecord', param);
    },
    /**
     *  46.获取是否为根目录    参数 []
     */
    isRootNativePage(param = []) {
        return this.callApi(_MIDEA_COMMON, 'isRootNativePage', param);
    },
    /**
     *  47.上传文件    参数 [{"url":"指定上传路径地址","files":"['本地文件路径']"}(必传)]
     */
    upload(param = []) {
        return this.callApi(_MIDEA_COMMON, 'upload', param);
    },
    /**
     * 打开外链url
     * @param url {string} 链接地址url
     */
    neiOpenUrl: function (url) {
        return this.callApi(_MIDEA_COMMON, 'openUrl', [url]);
    },
    /**
     * 26.修改底座导航条标题    参数 [标题文字]
     */
    showTitle: function (pram = []) {
        return this.callApi(_MIDEA_COMMON, 'showTitle', pram);
    },
    /**
     * 27.自定义导航栏右侧按钮    参数 [文字标题(必传(无文字的传空字符串)),触发事件调起的JS函数名(必传),icon样式 1-搜索,2-我的,3-删除,4-筛选,5-编辑,6-关闭,7-自定义icon(必传),自定义icon base64(可选)]
     */
    showRightButton: function (pram = []) {
        return this.callApi(_MIDEA_COMMON, 'showRightButton', pram);
    },
    /**
     * 28.上报埋点信息至T信后台服务器    参数 [插件ID(必传),page页面参数(必传),func函数名参数(必传),res参数 0-成功,其他-失败Code(可选),msg备注信息(可选),url查询邮件列表则填写url,本地操作未空(可选)]
     */
    recordPlugin: function (pram = []) {
        return this.callApi(_MIDEA_COMMON, 'recordPlugin', pram);
    },
    /**
     * 29.PDF浏览    参数 [PDF在线地址URL]
     */
    readPDF: function (pram = []) {
        return this.callApi(_MIDEA_COMMON, 'readPDF', pram);
    },
    /**
     * 30.设置会话过期    参数 []
     */
    sessionout: function (pram = []) {
        return this.callApi(_MIDEA_COMMON, 'sessionout', pram);
    },
    /**
     * 31.发送手机短信    参数 [手机号码,短信内容]
     */
    sendSms: function (pram = []) {
        return this.callApi(_MIDEA_COMMON, 'sendSms', pram);
    },
    /**
     * 32.关闭原生返回功能(仅iOS)    参数 []
     */
    closeSlideOut: function (pram = []) {
        return this.callApi(_MIDEA_COMMON, 'closeSlideOut', pram);
    },
    /**
     * 33.显示\隐藏水印    参数 [显示标识(0-显示1-隐藏)]
     */
    waterMarkManage: function (pram = []) {
        return this.callApi(_MIDEA_COMMON, 'waterMarkManage', pram);
    },
    /**
     * 34.获取原生用户配置信息    参数 [配置表key值]
     */
    getId: function (pram = []) {
        return this.callApi(_MIDEA_COMMON, 'getId', pram);
    },
    /**
     *  判断安卓、ios
     * @param
     * @returns true:false
     */
    isAndroid() {
        let u = navigator.userAgent;
        return u.indexOf('Android') > -1 || u.indexOf('Adr') > -1;
    },
    isIOS() {
        let u = navigator.userAgent;
        return !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
    },
    saveToGallery(url) {
        return this.callApi(_MIDEA_COMMON, 'saveToGallery', [url]);
    },
    // 49.电子定制接口-取消WebView栈顶通知(仅iOS)    参数 []
    closeMoniterViewAppear(param = []) {
        return this.callApi(_MIDEA_COMMON, 'closeMoniterViewAppear', param);
    },
    /*
     **
     **  从其他 应用中返回 调用 传入的fun方法
     **  @param fun { Function } 回调方法
     ** 48.电子定制接口-WebView栈顶通知(仅iOS)    参数 []
     */
    viweAppear(fun) {
        if (this.isIOS) {
            window.setTimeout(function () {
                var promise = new Promise((resolve, reject) => {
                    if (window.cordova) {
                        try {
                            window.cordova.exec((msg) => {
                                fun();
                                this.viweAppear(fun);
                                resolve(msg);
                            }, (msg) => {
                                reject(msg);
                            }, 'MideaCommon', 'moniterViewAppear', null)
                        } catch (e) {
                            console.log('_error', 'widget error:', e);
                            reject(e);
                        }
                    } else {
                        console.log('_debug', 'Cordova is not exist');
                    }
                })
            }, 1000);
        }
        if (this.isAndroid) {
            try {
                document.addEventListener('resume', function () {
                    fun();
                }, false);
            } catch (e) {
                console.log('not exist');
            }
        }
    }
}