diff --git a/root/bind/applyForm.vue b/root/bind/applyForm.vue index face299..1b11440 100644 --- a/root/bind/applyForm.vue +++ b/root/bind/applyForm.vue @@ -37,18 +37,17 @@ 'color':!newForm.wxname ? '#333' : '#666' }" > - {{ newForm.wxname || '微信昵称' }} + {{ newForm.wxname || '点击获取微信昵称' }}
- + + @@ -226,26 +225,38 @@ export default { } }, methods: { - getUserInfo(e) { + // 使用新的getUserProfile API获取用户信息 + getUserProfile() { let that = this; - console.log("获取用户信息:", e); - if (e.detail.userInfo) { - // 用户同意授权 - that.newForm.wxname = e.detail.userInfo.nickName; - that.newForm.wxavatar = e.detail.userInfo.avatarUrl || 'https://bocai-cms.oss-cn-beijing.aliyuncs.com/web-resource/pugongying/default.svg'; - } else { - // 用户拒绝授权 - uni.showModal({ - title: '提示', - content: '您已拒绝授权,将无法获取微信昵称信息,请重新授权', - showCancel: false, - confirmText: '知道了', - success: function(res) { - console.log('用户已拒绝授权'); - } - }); + // 检查是否已经授权过 + if (that.newForm.wxname && that.newForm.wxname !== '微信昵称') { + return; } - }, + + uni.getUserProfile({ + desc: '用于完善用户资料', // 声明获取用户个人信息后的用途 + success: (res) => { + console.log("获取用户信息成功:", res); + if (res.userInfo) { + that.newForm.wxname = res.userInfo.nickName; + that.newForm.wxavatar = res.userInfo.avatarUrl || 'https://bocai-cms.oss-cn-beijing.aliyuncs.com/web-resource/pugongying/default.svg'; + uni.showToast({ + title: '获取成功', + icon: 'success' + }); + } + }, + fail: (err) => { + console.log("获取用户信息失败:", err); + uni.showModal({ + title: '提示', + content: '您取消了授权,将无法获取微信昵称信息', + showCancel: false, + confirmText: '知道了' + }); + } + }); + }, init() { let that = this; that.isloading = true;