十四.按钮 button

分手后的思念是犯贱 2023-07-09 02:20 127阅读 0赞

button

按钮





















































































































































































属性 类型 默认值 必填 说明
size string default 按钮的大小,default/mini(小尺寸)
type string default 按钮的样式类型, primary(原色)/default(默认/warn(警告)
plain boolean false 按钮是否镂空,背景色透明
disabled boolean false 是否禁用
loading boolean false 名称前是否带 loading 图标
form-type string 用于 form 组件,点击分别会触发 form 组件的 submit/reset 事件
open-type string 微信开放能力
hover-class string button-hover 指定按钮按下去的样式类。当 hover-class=”none” 时,没有点击态效果
hover-stop-propagation boolean false 指定是否阻止本节点的祖先节点出现点击态
hover-start-time number 20 按住后多久出现点击态,单位毫秒
hover-stay-time number 70 手指松开后点击态保留时间,单位毫秒
lang string en 指定返回用户信息的语言,zh_CN 简体中文,zh_TW 繁体中文,en 英文。
session-from string 会话来源,open-type=”contact”时有效
send-message-title string 当前标题 会话内消息卡片标题,open-type=”contact”时有效
send-message-path string 当前分享路径 会话内消息卡片点击跳转小程序路径,open-type=”contact”时有效
send-message-img string 截图 会话内消息卡片图片,open-type=”contact”时有效
app-parameter string 打开 APP 时,向 APP 传递的参数,open-type=launchApp时有效
show-message-card boolean false 是否显示会话内消息卡片,设置此参数为 true,用户进入客服会话会在右下角显示”可能要发送的小程序”提示,用户点击后可以快速发送小程序消息,open-type=”contact”时有效
bindgetuserinfo eventhandle 用户点击该按钮时,会返回获取到的用户信息,回调的detail数据与wx.getUserInfo返回的一致,open-type=”getUserInfo”时有效
bindcontact eventhandle 客服消息回调,open-type=”contact”时有效
bindgetphonenumber eventhandle 获取用户手机号回调,open-type=getPhoneNumber时有效
binderror eventhandle 当使用开放能力时,发生错误的回调,open-type=launchApp时有效
bindopensetting eventhandle 在打开授权设置页后回调,open-type=openSetting时有效
bindlaunchapp eventhandle 打开 APP 成功的回调,open-type=launchApp时有效

open-type的合法值






































说明
contact 打开客服会话,如果用户在会话中点击消息卡片后返回小程序,可以从 bindcontact 回调中获得具体信息
share 触发用户转发. 不能将程序转发到朋友圈
getPhoneNumber 获取用户手机号,可以从bindgetphonenumber回调中获取到用户信息. 不是企业的小程序号, 是没有权限获取用户号码.
getUserInfo 获取用户信息,可以从bindgetuserinfo回调中获取到用户信息
launchApp 打开APP,可以通过app-parameter属性设定向APP传的参数
openSetting 打开授权设置页
feedback 打开“意见反馈”页面,用户可提交反馈内容并上传日志,开发者可以登录小程序管理后台后进入左侧菜单“客服反馈”页面获取到反馈内容

getPhoneNumber

  1. 绑定事件bindgetPhoneNumber
  2. 在事件的回调函数中, 通过参数来获取信息
  3. 获取到的信息已经加密过了, 需要用户自己搭建小程序的后台服务器. 来后台服务器中进行解析手机号, 返回小程序中就可以看到信息了

getUserInfo

getUserInfo的用法和getphoneNumber类似, 但是信息不会加密

launchApp

在小程序中直接打开APP

  1. 需要先在小程序app中,通过app的某个链接打开小程序
  2. 在小程序中再通过这个功能重新打开app

例: 用户上传图片

  1. <button bindtap='handleChooseAlbun'>选中图片</button>
  2. Page({
  3. data:{
  4. imagePata: ''
  5. },
  6. handleChooseAlbun(){
  7. //系统API, 让用户在相册中选择图片(或者拍照)
  8. wx:chooseImage({
  9. success: (res)=>{
  10. //取出路径
  11. const path = res.tempFilePaths[0]
  12. //设置imagePath
  13. this.setData({
  14. imagePath:path
  15. })
  16. }
  17. })
  18. }
  19. })
  20. <!-- <button class="default" size="default" type="default" plain="default" disabled="false" loading="false" hover-class="button-hover" hover-stop-propagation="false" form-type="submit|reset" open-type="contact|share|getUserInfo|openSetting|feedback" > </button> -->
  21. <button size="default" type="primary" >原色按钮1</button>
  22. <button size="default" type="default" >默认按钮2</button>
  23. <button size="default" type="warn" >警告按钮3</button>
  24. <button size="default" type="dispabled" >禁用按钮4</button>
  25. <button size="default" loading >loading按钮5</button>
  26. <!-- contact 打开客服会话,如果用户在会话中点击消息卡片后返回小程序,可以从 bindcontact 回调中获得具体信息 share 触发用户转发,使用前建议先阅读使用指引 getPhoneNumber 获取用户手机号,可以从bindgetphonenumber回调中获取到用户信息,具体说明 getUserInfo 获取用户信息,可以从bindgetuserinfo回调中获取到用户信息 launchApp 打开APP,可以通过app-parameter属性设定向APP传的参数具体说明 openSetting 打开授权设置页 feedback 打开“意见反馈”页面,用户可提交反馈内容并上传日志,开发者可以登录小程序管理后台后进入左侧菜单“客服反馈”页面获取到反馈内容 -->
  27. <button open-type="contact">contact</button>
  28. <button open-type="share">share</button>
  29. <button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">getPhoneNumber</button>
  30. <button open-type="getUserInfo" bindgetuserinfo="getUserInfo">getUserInfo</button>
  31. <button open-type="launchApp">launchApp</button>
  32. <button open-type="openSetting">openSetting</button>
  33. <button open-type="feedback">feedback</button>
  34. Page({
  35. data: {
  36. },
  37. getPhoneNumber (e) {
  38. console.log(e);
  39. },
  40. getUserInfo (e) {
  41. console.log(e);
  42. }
  43. })

发表评论

表情:
评论列表 (有 0 条评论,127人围观)

还没有评论,来说两句吧...

相关阅读