index.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. const api = require("../../api/index")
  2. // index.js
  3. const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
  4. Page({
  5. data: {
  6. motto: 'Hello World',
  7. userInfo: {
  8. avatarUrl: defaultAvatarUrl,
  9. nickName: '',
  10. },
  11. hasUserInfo: false,
  12. canIUseGetUserProfile: wx.canIUse('getUserProfile'),
  13. canIUseNicknameComp: wx.canIUse('input.type.nickname'),
  14. keyword:'',
  15. btnList:[
  16. {
  17. type:'1',
  18. label:'我要查风险',
  19. color:'blue'
  20. },
  21. {
  22. type:'2',
  23. label:'我要申诉',
  24. color:'rgb(252 202 0)'
  25. },
  26. {
  27. type:'3',
  28. label:'我要维权',
  29. color:'red'
  30. },
  31. {
  32. type:'4',
  33. label:'我要申请',
  34. color:'#7232dd'
  35. }
  36. ]
  37. },
  38. bindViewTap() {
  39. wx.navigateTo({
  40. url: '../logs/logs'
  41. })
  42. },
  43. onReady(){
  44. },
  45. onLoad(){
  46. api.search().then(res=>{
  47. console.log(res)
  48. })
  49. },
  50. //修改输入的关键词
  51. changeKeyword(e){
  52. this.setData(
  53. {
  54. keyword:e.detail
  55. }
  56. )
  57. },
  58. //点击输入框内部图标
  59. clickInnerIcon(e){
  60. // console.log(e)
  61. },
  62. //点击搜索按钮
  63. search(e){
  64. // console.log(e)
  65. // this.setData(
  66. // {
  67. // result:this.data.keyword
  68. // }
  69. // )
  70. },
  71. //点击四个功能按钮(我要查风险)
  72. btnClick:function(e){
  73. console.log(e)
  74. var type = e.currentTarget.dataset.type
  75. console.log(type)
  76. },
  77. onChooseAvatar(e) {
  78. const { avatarUrl } = e.detail
  79. const { nickName } = this.data.userInfo
  80. this.setData({
  81. "userInfo.avatarUrl": avatarUrl,
  82. hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl,
  83. })
  84. },
  85. onInputChange(e) {
  86. const nickName = e.detail.value
  87. const { avatarUrl } = this.data.userInfo
  88. this.setData({
  89. "userInfo.nickName": nickName,
  90. hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl,
  91. })
  92. },
  93. getUserProfile(e) {
  94. // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
  95. wx.getUserProfile({
  96. desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  97. success: (res) => {
  98. console.log(res)
  99. this.setData({
  100. userInfo: res.userInfo,
  101. hasUserInfo: true
  102. })
  103. }
  104. })
  105. },
  106. })