index.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <view class="fui-wrap">
  3. <u-button
  4. text="默认按钮"
  5. size="normal"
  6. type="info"
  7. @click="onClick"
  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. onClick() {
  51. uni.navigateTo({
  52. url: '/pasb/pages/file/index'
  53. })
  54. },
  55. getUserInfo() {
  56. uni.getUserProfile({
  57. desc: '获取用户信息',
  58. success: (res) => {
  59. console.log(res);
  60. }
  61. })
  62. },
  63. },
  64. onShareAppMessage() {
  65. return {
  66. title: 'First UI组件库'
  67. }
  68. }
  69. }
  70. </script>
  71. <style>
  72. .fui-banner__box {
  73. width: 100%;
  74. min-height: 538rpx;
  75. position: relative;
  76. background-color: #EDF9FF;
  77. }
  78. </style>