NativeApis.js 1.77 KB
export const NativeMethodNames = {
    AppInfoApi: 'nativeAppInfo',
    AppShare: 'nativeAppShare',
    AppBottomMenu: 'nativeMenu',
    nativeTextZoom: 'nativeTextZoom',
}

export const JsMethodNames = {
    PayResult: 'payResult'
}

export const JsInterfaces = objVal2Array(JsMethodNames)


export const NativeMenuApi = {
    nativeMenuShow: (param = {}) => {
        const newParam = { ...param, type: '1' }
        NativeApi.nativeMenuStatus(newParam).then(res => { }).catch(e => { })
    },
    nativeMenuHide: (param = {}) => {
        const newParam = { ...param, type: '2' }
        NativeApi.nativeMenuStatus(newParam).then(res => { }).catch(e => { })
    }
}


export const NativeApi = {
    on: (jsMethodName, callback) => {
        $api.on(jsMethodName, callback)
    },

    call: (nativeMethodName, param, isBack) => {
        return $api.call(nativeMethodName, param, isBack)
    },

    nativeAppInfo: (param) => {
        return $api.call(NativeMethodNames.AppInfoApi, param, true)
    },

    nativeAppShare: (param) => {
        return $api.call(NativeMethodNames.AppShare, param, true)
    },

    // {type: '1'-显示/'2'-隐藏, moduleName: '切换模块名称', routeName: '路由名称', routePath: '路由地址', url:'完整url'}
    nativeMenuStatus: (param) => {
        if (!param.type) {
            Object.assign(param, { type: '1' })
        }
        return $api.call(NativeMethodNames.AppBottomMenu, param, false)
    },

    // {value: 100}
    nativeTextZoom: (param) => {
        if (!param.value) {
            Object.assign(param, { value: 100 })
        }
        return $api.call(NativeMethodNames.nativeTextZoom, param, false)
    }
}



function objVal2Array (obj) {
    const arrays = []
    for (const key in obj) {
        arrays.push(obj[key])
    }
    return arrays
}