wx.chooseImage()
从本地相册选择图片或使用相机拍照。
部分配置参数如下:
- count,最多可以选择的图片张数,是一个数值,默认值是9。
- sizeType,所选图片的尺寸,是一个数组,默认值是
['original','compressed']
。original
,使用原图compressed
,使用压缩图
- sourceType,选择图片的来源,是一个数组,默认值是
['album,'camera']
。album
,从本地相册中选图camera
,使用相机
- success
回调函数参数有,tempFilePaths
,临时文件路径列表,是一个数组,数组元素是一个字符串tempFiles
,临时文件列表,是一个数组,数组元素是一个对象,每个对象包含如下属性,path
,本地临时文件路径size
,本地临时文件大小
wx.chooseAddress()
调用用户编辑收货地址的原生页面。
所谓 “用户编辑收获地址的原生页面”,就是这里,见下列截图。
这里需要关注的就是success回调函数的参数,包含如下属性:
nationalCode
,收货地址国家码privinceName
,国标收货地址第一级地址,即省地址。cityName
,国标收货地址第二级地址,即市地址。countyName
,国标收货地址第三级地址,即县地址detailInfo
,详细收货地址信息。postalCode
,邮编。telNumber
,收货人手机号码userName
,收货人姓名
wx.makePhoneCall()
拨打电话。其中,参数phoneNumber
是必填项。
实例1
<!--index.wxml-->
<button bindtap="chooseImage">选择图片</button>
<button bindtap="chooseAddress">选择地址</button>
<button bindtap="makePhoneCall">拨打电话</button>
// index.js
Page({
chooseImage:function(){
wx.chooseImage({
})
},
chooseAddress:function(){
wx.chooseAddress({
})
},
makePhoneCall:function(){
wx.makePhoneCall({
phoneNumber: '12345678901',
})
}
})
实例2
<!--index.wxml-->
<button bindtap="chooseImage">选择图片</button>
<button bindtap="chooseAddress">选择地址</button>
<button bindtap="makePhoneCall">拨打电话</button>
// index.js
Page({
chooseImage:function(){
wx.chooseImage({
sizeType:["original","compressed"],
sourceType:["album","camera"],
success:(res) => {
console.log("选好图片了,",res);
}
})
},
chooseAddress:function(){
wx.chooseAddress({
success:(res) => {
console.log("选好地址了,",res);
}
})
},
makePhoneCall:function(){
wx.makePhoneCall({
phoneNumber: '12345678901',
success:(res) => {
console.log("拨好电话了,",res);
}
})
}
})