之前分別維護(hù)微信和支付寶小程序彬祖,真的很麻煩啊歪赢,煩躁,了解了uni-app就邊練手邊重構(gòu)項(xiàng)目了曙砂。先適配的微信小程序艇拍,上架后才適配支付寶小程序狐蜕,只能說,后悔后悔后悔P断Α2闶汀!應(yīng)該先整支付寶的快集,畢竟uniapp是參照微信小程序的api寫的贡羔,過渡微信比較簡單,寫完了支付寶還要單獨(dú)拿出來適配个初,以下都是ios9.3支付寶測出來問題乖寒。
1.自定義方法重名,舉個(gè)例子:
api.scanCode = () => {}
封裝uni api的同名方法院溺,在ios9.3的支付寶上無效楣嘁,實(shí)際走的是uni api方法,不是很懂原理珍逸,只好改自定義方法名
api.scanCodeUni = () => {}
2.關(guān)于uni-app map的polygon畫區(qū)域不兼容的問題逐虚,仔細(xì)看了uniapp文檔后發(fā)現(xiàn),文檔中的參數(shù)為polygons谆膳,但是支付寶設(shè)參數(shù)polygon才能顯示區(qū)域叭爱,解決辦法是把兩個(gè)參數(shù)都加上,如代碼:
<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 />后面买雾。
但是經(jīng)測app端的地圖控件必須嵌套在<map></map>組件內(nèi),所以多端適配需分平臺編譯
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.關(guān)于封裝定位api漓穿,getLocation參數(shù)問題,針對支付寶單獨(dú)傳參數(shù)
/*
* getLocType: 是否顯示支付定位城市信息, 0顯示默認(rèn)定位,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
})
}