fix(contact): 替换用户授权弹窗为静默登录提示
将用户授权弹窗改为静默登录提示,优化登录流程。同时更新API基础URL配置,移除废弃代码。
This commit is contained in:
parent
86b605b574
commit
8ebe968b1b
@ -1,5 +1,5 @@
|
||||
// const baseUrl = 'https://mini-chat.1024tool.vip/api/';
|
||||
const baseUrl = 'https://dsjhd9s.tbmw.cn/api/'
|
||||
const baseUrl = 'https://mini-chat.1024tool.vip/api/';
|
||||
// const baseUrl = 'https://dsjhd9s.tbmw.cn/api/'
|
||||
function request(url, method = 'GET', data = {}) {
|
||||
|
||||
const header = {
|
||||
|
||||
BIN
pages/.DS_Store
vendored
Normal file
BIN
pages/.DS_Store
vendored
Normal file
Binary file not shown.
@ -37,7 +37,7 @@ Page({
|
||||
});
|
||||
console.log('contact page onLoad, options:', options);
|
||||
|
||||
// this.getMessages()
|
||||
// 检查是否已有用户信息
|
||||
if (wx.getStorageSync('user_info')) {
|
||||
this.setData({
|
||||
showGetUser: false,
|
||||
@ -47,16 +47,9 @@ Page({
|
||||
// start polling when page loads and user is present
|
||||
this.startPolling();
|
||||
} else {
|
||||
this.setData({
|
||||
showGetUser: true,
|
||||
});
|
||||
// 直接进行静默登录,不显示授权弹窗
|
||||
this.silentLogin();
|
||||
}
|
||||
|
||||
// this.setData({
|
||||
// appid: accountInfo.miniProgram.appId,
|
||||
// });
|
||||
|
||||
// console.log('appId',accountInfo.miniProgram);
|
||||
},
|
||||
// onShow() {
|
||||
// this.getMessages()
|
||||
@ -139,43 +132,43 @@ Page({
|
||||
that.setData({ loadingMore: false });
|
||||
});
|
||||
},
|
||||
requestUserProfile(e) {
|
||||
console.log('user', e.detail);
|
||||
const user = e.detail;
|
||||
// 静默登录方法,只需要appid和js_code
|
||||
silentLogin() {
|
||||
const that = this;
|
||||
// wx.setStorageSync('user_info', e.detail.userInfo);
|
||||
const accountInfo = wx.getAccountInfoSync();
|
||||
wx.login({
|
||||
success: function (res) {
|
||||
request('wechat/miniprogram/login', 'post', {
|
||||
"app_id": accountInfo.miniProgram.appId,
|
||||
"js_code": res.code,
|
||||
"encrypted_data": user.encryptedData,
|
||||
"iv": user.iv,
|
||||
"raw_data": user.rawData,
|
||||
"signature": user.signature
|
||||
"js_code": res.code
|
||||
}).then(resp => {
|
||||
wx.setStorageSync('user_info', resp);
|
||||
// wx.setStorageSync('open_id', resp.openid);
|
||||
that.setData({
|
||||
showGetUser: false,
|
||||
userInfo: resp
|
||||
});
|
||||
request('app/user/create', 'post', {
|
||||
"app_id": accountInfo.miniProgram.appId,
|
||||
"user_avatar": resp.user_avatar,
|
||||
"user_avatar": resp.user_avatar || '/static/user.png',
|
||||
"user_id": resp.openid,
|
||||
"user_name": resp.user_name
|
||||
"user_name": resp.user_name || '微信用户'
|
||||
}).then(resp => {
|
||||
that.getMessages()
|
||||
// start polling once user info exists
|
||||
that.startPolling();
|
||||
|
||||
});
|
||||
}).catch(err => {
|
||||
console.error('静默登录失败:', err);
|
||||
// 如果静默登录失败,可以选择显示授权弹窗或其他处理
|
||||
that.setData({
|
||||
showGetUser: true
|
||||
});
|
||||
});
|
||||
},
|
||||
fail: function(err) {
|
||||
console.error('wx.login失败:', err);
|
||||
}
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
// Start polling messages every 1 second. Ensures only one interval exists.
|
||||
@ -234,11 +227,7 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
dismissGetUser() {
|
||||
this.setData({
|
||||
showGetUser: false
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
onReady() {
|
||||
// 初始化欢迎消息,带时间分割线
|
||||
|
||||
@ -39,17 +39,12 @@
|
||||
<button class="btn-send" bindtap="sendText">发送</button>
|
||||
</view>
|
||||
|
||||
<!-- 获取用户信息弹窗 -->
|
||||
<!-- 静默登录中提示 -->
|
||||
<block wx:if="{{showGetUser}}">
|
||||
<view class="overlay">
|
||||
<view class="popup">
|
||||
<text class="popup-title">授权获取您的用户信息</text>
|
||||
<text class="popup-desc">授权后可用于显示头像、昵称等,提升聊天体验。</text>
|
||||
<view class="popup-actions">
|
||||
<button class="btn-primary" open-type="getUserInfo" bindgetuserinfo="requestUserProfile">获取用户信息</button>
|
||||
|
||||
<!-- <button class="btn-secondary" bindtap="dismissGetUser">稍后再说</button> -->
|
||||
</view>
|
||||
<text class="popup-title">正在登录...</text>
|
||||
<text class="popup-desc">请稍候,正在为您自动登录。</text>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user