1、修改app.js

// app.js
App({
    onLaunch() {
      // 登录
      wx.login({
        success: res => {
          // 发送 res.code 到后台换取 openId, sessionKey, unionId
          if (res.code) {
            // console.log(res.code)
            wx.request({
              url: this.globalData.url + 'api/sys_Login/Login_WeChat',
              data: { code: res.code },
              header: { "content-type": "application/json" },
              method: 'POST',
              success: res => {
                // console.log(res.data);
                this.globalData.userInfo = res.data;
                wx.setStorage({
                  key: 'userInfo',
                  data: res.data,
                })
                //网络请求可能会在Page.onLoad()之后返回,加入callback
                if (this.userInfoCallback){
                   this.userInfoCallback(res.data);
                }
              }
            })
          } else {
            console.log('登录失败!')
          }
        }
      })
    },
    globalData: {
      url: 'http://127.0.0.1:8888/',
      userInfo: null,
    }
  })

2、修改personcenter.wxml

<view class="container">
  <form catchsubmit="formSubmit">
    <view class="userinfo">
      <button class="avatar-wrapper" open-type="chooseAvatar" bind:chooseavatar="onChooseAvatar">
        <image class="avatar" src="{{userInfo.avatarUrl}}" mode='aspectFit'></image>
      </button>
      <input class="nick-name-input" type="nickname" placeholder="点击获取微信名" name="input" value="{{userInfo.nickname}}" bindblur="changeNickName" />
    </view>
    <view class="usermotto">
      <button type="primary" formType="submit" >登陆</button>
    </view>
  </form>
</view>

3、修改personcenter.wxss

.userinfo {
    margin-top: 200rpx;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.avatar-wrapper {
    background-color: white;
}

.avatar {
    overflow: hidden;
    width: 128rpx;
    height: 128rpx;
    margin: 20rpx;
    border-radius: 50%;
}

.nick-name-input {
    margin: 20rpx;
    text-align: center
}

.usermotto {
    margin-top: 200rpx;
}

4、修改personcenter.js

var app = getApp();
Page({
    data: {
        userInfo: null,
    },
    onLoad() {
        // 获取后台返回的用户信息
        if (app.globalData.userInfo == null) {
            // callback 未获取信息回调
            app.userInfoCallback = userInfo => {
                if (userInfo != null) {
                    this.setData({
                        userInfo: app.globalData.userInfo
                    });
                }
            }
        } else {
            this.setData({
                userInfo: app.globalData.userInfo
            });
        }
    },

    // 用户修改昵称
    changeNickName(e) {
        let name = e.detail.value;
        if (name.length === 0) return;
        // this.setData({
        //   ['userInfo.nickname']: e.detail.value.input
        // })
    },
    // 用户选中自定义头像的回调
    onChooseAvatar(e) {
        const {
            avatarUrl
        } = e.detail
        // 获取到的avatarUrl(临时地址):http://tmp/ZENIKXqaUC20a19f3c2fd621b82c7662b952e000d532.jpeg
        console.log(avatarUrl);
        this.setData({
            ['userInfo.avatarUrl']: avatarUrl,
        })
    },
    // 获取token
    getToken() {
        wx.request({
            url: app.globalData.url + 'api/sys_Login/wx_token',
            data: {
                openid: app.globalData.userInfo.openid
            },
            success: res => {
                // console.log(res)
                wx.setStorage({
                    key: 'token',
                    data: res.data,
                })
                wx.navigateTo({
                    url: '../workplant/workplant'
                })
            }
        })
    },
    // 登录
    formSubmit(e) {
        this.setData({
            ['userInfo.nickname']: e.detail.value.input
        })
        // console.log(this.data.userInfo)
        if (e.detail.value.input == "") {
            wx.showToast({
                title: '需要微信名登录',
                icon: 'error',
                duration: 3000
            })
            return
        } else {
            if (app.globalData.userInfo.nickname == wx.getStorageSync("userInfo").nickname) {// console.log("昵称未变更")
                this.getToken()
            } else { // console.log("昵称已变更")
                wx.request({
                    url: app.globalData.url + 'api/sys_Login/User_WeChat',
                    data: {
                        openid: app.globalData.userInfo.openid,
                        session_key: "",
                        nickname: this.data.userInfo.nickname
                    },
                    header: {
                        "content-type": "application/json"
                    },
                    method: 'POST',
                    success: res => {
                        // console.log(res.data);
                        wx.setStorage({
                            key: 'userInfo',
                            data: res.data,
                        })
                        this.getToken()
                    }
                })
            }
        }
    },

})

转自 https://www.cnblogs.com/shiliumu/p/16929979.html

posted @ 2025-02-17 08:42 韩梦芫 阅读(0) 评论(0) 推荐(0) 编辑
摘要: 今天给大家介绍一款简单易用而且美观的免费 SQL 客户端:Beekeeper Studio。 Beekeeper Studio 简介 Beekeeper Studio 是一款免费开源的 SQL 开发和数据库管理工具,具有美观高效、简单易用的特点。Beekeeper Studio 基于 Vue.js  阅读全文
posted @ 2025-01-16 16:43 韩梦芫 阅读(124) 评论(0) 推荐(0) 编辑
摘要: https://tool.ip138.com/cmyk/ 阅读全文
posted @ 2025-01-13 14:17 韩梦芫 阅读(6) 评论(0) 推荐(0) 编辑
摘要: public class WithNoLockInterceptor : DbCommandInterceptor { private static readonly Regex TableAliasRegex = new Regex(@"(?<tableAlias>(FROM|JOIN) \[[a 阅读全文
posted @ 2025-01-02 09:05 韩梦芫 阅读(15) 评论(0) 推荐(0) 编辑
摘要: yarn run vite 阅读全文
posted @ 2024-12-20 08:40 韩梦芫 阅读(3) 评论(0) 推荐(0) 编辑
摘要: 在Blazor中,如果你想在组件渲染前执行某些操作,可以使用以下几个生命周期方法: OnInitializedAsync: 这个方法在组件初始化时被调用,适合执行异步初始化操作,如从服务器加载数据。这是在组件渲染前调用的,因此你可以在这里进行数据预加载。 protected override asy 阅读全文
posted @ 2024-12-12 08:31 韩梦芫 阅读(42) 评论(0) 推荐(0) 编辑
摘要: https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html 阅读全文
posted @ 2024-11-07 14:38 韩梦芫 阅读(1961) 评论(0) 推荐(0) 编辑
摘要: powershell 执行这两个指令Register-PSRepository -SourceLocation http://10.10.14.41:8081/repository/nuget-hosted/ -PublishLocation http://10.10.14.41:8081/repo 阅读全文
posted @ 2024-10-30 09:16 韩梦芫 阅读(7) 评论(0) 推荐(0) 编辑
摘要: 最近由于项目需要,做了个FTP的上传下载 上传 /// <summary> /// 上传共享文件 /// </summary> /// <param name="server">服务器信息</param> /// <param name="files">文件列表</param> public sta 阅读全文
posted @ 2024-10-29 22:05 韩梦芫 阅读(144) 评论(0) 推荐(0) 编辑
摘要: protected readonly IUnitOfWorkManager _unitOfWorkManager;public PlanningTaskManagerBase(IUnitOfWorkManager unitOfWorkManager){ _unitOfWorkManager = un 阅读全文
posted @ 2024-09-30 17:49 韩梦芫 阅读(14) 评论(0) 推荐(0) 编辑
点击右上角即可分享
微信分享提示