index.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <template>
  2. <view class="fui-wrap">
  3. <u-button
  4. text="默认按钮"
  5. size="normal"
  6. type="info"
  7. @click="click"
  8. ></u-button>
  9. </view>
  10. </template>
  11. <script>
  12. export default {
  13. data() {
  14. return {
  15. }
  16. },
  17. onLoad() {
  18. // #ifdef MP-WEIXIN
  19. wx.login({
  20. success: function(res) {
  21. wx.request({
  22. url: "https://api.weixin.qq.com/sns/jscode2session",
  23. data: {
  24. appid: process.env.UNI_WX_APPID,
  25. secret: process.env.UNI_WX_AS,
  26. js_code: res.code,
  27. grant_type: "authorization_code",
  28. },
  29. success: function(response) {
  30. const openid = response.data.openid;
  31. console.log("获取到的code:", res.code, "获取到的openid:", openid);
  32. // 使用登录凭证获取用户信息
  33. uni.getUserInfo({
  34. provider: 'weixin',
  35. success: function (infoRes) {
  36. console.log(infoRes.userInfo); // 打印用户信息
  37. console.log('用户昵称为: ' + infoRes.userInfo.nickName); // 打印用户昵称
  38. // 在这里,你可以将用户的头像和昵称保存到本地或者发送到后端进行处理
  39. // infoRes.userInfo.avatarUrl是用户的头像链接
  40. // infoRes.userInfo.nickName是用户的昵称
  41. }
  42. });
  43. }
  44. })
  45. }
  46. })
  47. // #endif
  48. },
  49. methods: {
  50. getUserInfo() {
  51. uni.getUserProfile({
  52. desc: '获取用户信息',
  53. success: (res) => {
  54. console.log(res);
  55. }
  56. })
  57. },
  58. },
  59. onShareAppMessage() {
  60. return {
  61. title: 'First UI组件库'
  62. }
  63. }
  64. }
  65. </script>
  66. <style>
  67. .fui-banner__box {
  68. width: 100%;
  69. min-height: 538rpx;
  70. position: relative;
  71. background-color: #EDF9FF;
  72. }
  73. </style>