之前分别维护微信和支付宝小程序,真的很麻烦啊,烦躁,了解了uni-app就边练手边重构项目了。先适配的微信小程序,上架后才适配支付宝小程序,只能说,后悔后悔后悔!!!应该先整支付宝的,毕竟uniapp是参照微信小程序的api写的,过渡微信比较简单,写完了支付宝还要单独拿出来适配,以下都是ios9.3支付宝测出来问题。
1.自定义方法重名,举个例子:
api.scanCode = () => {}
封装uni api的同名方法,在ios9.3的支付宝上无效,实际走的是uni api方法,不是很懂原理,只好改自定义方法名
api.scanCodeUni = () => {}
2.关于uni-app map的polygon画区域不兼容的问题,仔细看了uniapp文档后发现,文档中的参数为polygons,但是支付宝设参数polygon才能显示区域,解决办法是把两个参数都加上,如代码:
<map class="mapview" show-location="true" :latitude="latitude" :longitude="longitude" scale="15" :markers="markers" v-bind:include-points="includePoints"
:polygons="polygons" :polygon="polygons" :polyline="polylines">
支付宝的map不支持嵌套cover-view,所以地图控件必须写在<map />后面。
但是经测app端的地图控件必须嵌套在<map></map>组件内,所以多端适配需分平台编译
3.uniapp存储值问题
uni未适配支付宝存储值,分支付宝小程序平台编译
tool.setCacheSync = (key, value) => {
// #ifdef MP-ALIPAY
my.setStorageSync({
key: key,
data: value
})
// #endif
// #ifndef MP-ALIPAY
uni.setStorageSync(key, value)
// #endif
}
tool.getCacheSync = (key) => {
// #ifdef MP-ALIPAY
let value = my.getStorageSync({
key: key
})
return value.data
// #endif
// #ifndef MP-ALIPAY
let value = uni.getStorageSync(key)
if (value.hasOwnProperty('data')) {
return value.data
}
return value
// #endif
}
4.关于封装定位api,getLocation参数问题,针对支付宝单独传参数
/*
* getLocType: 是否显示支付定位城市信息, 0显示默认定位,1显示城市定位, 2显示地址定位
*/
tool.getLocationInfo = (getLocType) => {
return new Promise((resolve, reject) => {
// #ifdef MP-ALIPAY
my.getLocation({
type: getLocType || 0,
success(s) {
resolve(s)
},
fail(e) {
reject(e)
}
})
// #endif
// #ifndef MP-ALIPAY
uni.getLocation({
type: 'gcj02',
success(s) {
resolve(s)
},
fail(e) {
reject(e)
}
})
// #endif
})
}