Merge branch 'main' of https://git.1024tool.vip/xz/wx-chant into main

This commit is contained in:
左哥 2025-10-29 21:37:26 +08:00
commit 42565511df
6 changed files with 38 additions and 41 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

BIN
pages/.DS_Store vendored Normal file

Binary file not shown.

View File

@ -35,9 +35,8 @@ Page({
this.setData({
appid: accountInfo.miniProgram.appId,
});
console.log('contact page onLoad, options:', options);
// this.getMessages()
// 检查是否已有用户信息
if (wx.getStorageSync('user_info')) {
this.setData({
showGetUser: false,
@ -47,16 +46,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 +131,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 +226,7 @@ Page({
}
},
dismissGetUser() {
this.setData({
showGetUser: false
});
},
onReady() {
// 初始化欢迎消息,带时间分割线

View File

@ -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>

View File

@ -144,5 +144,19 @@ Page({
danceIndex: nextIndex,
currentDance: danceList[nextIndex]
});
},
handleContact() {
wx.requestSubscribeMessage({
tmplIds: ['9dCV3z7vRPBGm8iMtSXsD7ZVyUjld46w7HTH9zLnzWw'],
success: (res) => {
wx.navigateTo({
url: `/pages/contact/index`
});
},
fail: (err) => {
console.log(err);
}
});
}
});

View File

@ -9,14 +9,14 @@
></image>
<!-- 客服跳转导航url 拼接 appId与 JS 中 appId 变量对齐 -->
<navigator
url="/pages/contact/index{{ appId ? ('?app_id=' + appId) : '' }}"
<view
bindtap="handleContact"
style="position:fixed; width:80%; margin-left:10%; bottom:240rpx; color:#fff; background:#ec6d23; border-radius:15rpx; height:75rpx; display:flex; justify-content:center; align-items:center; margin-top:50rpx; z-index:9999; text-decoration:none;"
>
<view style="width:100%; height:100%; display:flex; justify-content:center; align-items:center; color:#fff;">
欢迎联系人工客服
</view>
</navigator>
</view>
</view>
<!-- 2. 舞蹈详情区域(对应原逻辑中 wallpaperUrl≠1 的场景) -->