增加小程序,修改游戏前端
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import { config } from '../../config';
|
||||
|
||||
Page({
|
||||
data: {
|
||||
url: ''
|
||||
},
|
||||
onLoad(options: any) {
|
||||
// 这里的 URL 必须是您后端服务器的地址
|
||||
// 注意:本地调试时,web-view 访问 localhost 需要在开发者工具勾选“不校验域名”
|
||||
// 但微信 OAuth 回调必须是公网域名,所以这里填 localhost 只能走到跳转微信那一步,回调会失败
|
||||
// 除非您配置了 host 映射或者使用了内网穿透
|
||||
const serverUrl = `${config.baseUrl}/auth/oa/login`;
|
||||
this.setData({ url: serverUrl });
|
||||
},
|
||||
onMessage(e: any) {
|
||||
console.log('WebView message:', e.detail);
|
||||
const data = e.detail.data;
|
||||
if (data && data.length > 0) {
|
||||
const lastData = data[data.length - 1];
|
||||
|
||||
// 保存到本地存储,供 index 页面 onShow 读取并触发后续逻辑
|
||||
// 保存所有可用的微信用户信息
|
||||
wx.setStorageSync('oa_user_info', {
|
||||
nickName: lastData.nickname,
|
||||
avatarUrl: lastData.headimgurl,
|
||||
unionid: lastData.unionid,
|
||||
gender: lastData.sex, // 1男 2女 0未知
|
||||
country: lastData.country,
|
||||
province: lastData.province,
|
||||
city: lastData.city,
|
||||
language: lastData.language
|
||||
});
|
||||
|
||||
// 同时更新上一页数据,确保 UI 即时刷新
|
||||
const pages = getCurrentPages();
|
||||
const prevPage = pages[pages.length - 2]; // 上一个页面 (index)
|
||||
if (prevPage) {
|
||||
prevPage.setData({
|
||||
"userInfo.avatarUrl": lastData.headimgurl,
|
||||
"userInfo.nickName": lastData.nickname,
|
||||
"userInfo.gender": lastData.sex,
|
||||
"userInfo.country": lastData.country,
|
||||
"userInfo.province": lastData.province,
|
||||
"userInfo.city": lastData.city,
|
||||
"userInfo.language": lastData.language,
|
||||
"unionid": lastData.unionid || prevPage.data.unionid
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user