bsm-sdk

1.3.0 • Public • Published

巴士盟js-sdk

第一步:在 main.js 中引入并使用

//引入
import {use} from 'bsm-sdk'
//使用
use()

第二步:使用sdk

//引入sdk
import appBridge from 'bsm-sdk'

//使用
async function getAppInfo(){
    try {
        const {data} = await appBridge.ssGetAppInfo()
        appInfo.value = JSON.stringify(data)
    } catch (e) {
        console.error(e)
    }
}

sdk列表

从相册选择图片或者拍照

const imgs = ref([])
async function onChoose() {
    try {
        const {data} = await appBridge.ssTakePhotos()
        if (data != null) {
            // 显示原生传过来的图片
            const bytes = new Uint8Array(data)
            const blob = new Blob([bytes], { type: 'image/png' })
            imgs.value.push({
                //本地路径
                url: URL.createObjectURL(blob),
                //图片内容
                blob
            })
        }
    } catch (e) {
        console.error(e)
    }
}

获取当前GPS

/*国测局坐标转百度坐标*/
/*BMap自己引入百度地图的js*/
function transGPStoBPointsByGcj02(Point) {
  return new Promise((resolve, reject) => {
    try {
      const convertor = new BMap.Convertor()
      const pointArr = []
      pointArr.push(Point)
      /*
      from----------------------
      1:GPS设备获取的角度坐标,WGS84坐标;
      2:GPS获取的米制坐标、sogou地图所用坐标;
      3:google地图、soso地图、aliyun地图、mapabc地图和amap地图所用坐标,国测局(GCJ02)坐标;
      4:3中列表地图坐标对应的米制坐标;
      5:百度地图采用的经纬度坐标;
      6:百度地图采用的米制坐标;
      7:mapbar地图坐标;
      8:51地图坐标
      * */


      /*
      to----------------------
      3:国测局(GCJ02)坐标;
      4:3中对应的米制坐标;
      5:bd09ll(百度经纬度坐标);
      6:bd09mc(百度米制经纬度坐标)
      * */
      convertor.translate(pointArr, 3, 5, data => {
        data.status === 0 ? resolve(data.points[0]) : reject('转换失败')
      })
    } catch (e) {
      reject(e.toString())
    }
  })
}

async function getGeo() {
    try {
        const location = await appBridge.ssGetLocation()
        const {lng, lat} = await transGPStoBPointsByGcj02(new BMap.Point(location.data.longitude, location.data.latitude))
        info.value = `从手机获取的GPS:${location.data.longitude},${location.data.latitude}<br/>转换成百度坐标:${lng},${lat}`
    } catch (e) {
        console.error(e)
    }
}

设置导航标题

async function onSet() {
    try {
        await appBridge.ssAppBarTitle({title:'巴士盟123'})
    } catch (e) {
        console.error(e)
    }
}

扫二维码

async function onScan() {
    try {
        const {data} = await appBridge.ssOpenScanCode('')
        alert(`扫码出来的内容是:${JSON.stringify(data)}`)
    } catch (e) {
        console.error(e)
    }
}

分享给微信联系人

async function onShare() {
    try {
        await appBridge.ssOpenShare({
            title: '标题,非必传',
            image: '图片URL,非必传',
            link: '跳转链接,必填',
            desc: '描述,必填'
        })
    } catch (e) {
        console.error(e)
    }
}

获取用户信息

async function getUserInfo() {
    try {
        const {data} = await appBridge.ssGetUserInfo()
        console.log(JSON.stringify(data))
    } catch (e) {
        console.error(e)
    }
}

获取app信息

async function getAppInfo(){
    try {
        const {data} = await appBridge.ssGetAppInfo()
        console.log(JSON.stringify(data))
    } catch (e) {
        console.error(e)
    }
}

支付

async function openPay() {
    try {
        await appBridge.ssOpenPay({
            appCode: '应用CODE',
            tenantId: '租户id',
            groupOrderNo: '组合订单号',
            payAmount: '应付款'
        })
    } catch (e) {
        console.error(e)
    }
}

跳转小程序

async function openMiniprogram() {
    try {
        await appBridge.ssOpenMiniprogram({
            appid:'小程序APPID',
            path:'指定小程序的页面路径,可以带参数',
            params:'额外参数:根据需要,可能还需要传递其他参数,如跳转时携带的数据等'
        })
    } catch (e) {
        console.error(e)
    }
}

跳转其他APP

async function openApp() {
    try {
        await appBridge.ssOpenApp({
            scheme:'APP的scheme'
        })
    } catch (e) {
        console.error(e)
    }
}

关闭应用(整个关闭)

async function onBack() {
    try {
        await appBridge.ssExitApp()
    } catch (e) {
        console.error(e)
    }
}

退出webview

async function backApp() {
    try {
        await appBridge.ssBack()
    } catch (e) {
        console.error(e)
    }
}

隐藏、显示导航栏 1.1.0+

async function hideNav() {
    try {
        //隐藏
        await appBridge.ssHideNav(false)
        //显示
        // await appBridge.ssHideNav(true)
    } catch (e) {
        console.error(e)
    }
}

跳转APP内部某个页面 1.2.0+

async function jumpToAppPage() {
    try {
        await appBridge.ssJumpToPage()
    } catch (e) {
        console.error(e)
    }
}

打开、关闭loading 1.2.0+

async function toggleLoading() {
    try {
        //打开
        await appBridge.ssToggleLoading(true)
        //关闭
        // await appBridge.ssToggleLoading(false)
    } catch (e) {
        console.error(e)
    }
}

Readme

Keywords

Package Sidebar

Install

npm i bsm-sdk

Weekly Downloads

1

Version

1.3.0

License

ISC

Unpacked Size

14 kB

Total Files

6

Last publish

Collaborators

  • robin901118