hookehuyr

fix(auth): 根据环境动态设置openid参数以适配测试和正式环境

测试环境下传递固定openid参数,正式环境仅传递code参数
<!--
* @Date: 2022-09-19 14:11:06
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-07-14 15:37:49
* @LastEditTime: 2025-07-14 16:51:45
* @FilePath: /jgdl/src/pages/auth/index.vue
* @Description: 文件描述
-->
......@@ -73,7 +73,7 @@ export default {
}
});
},
/**
* 处理登录成功后的网络请求
* @param {string} code - 微信登录code
......@@ -82,14 +82,18 @@ export default {
Taro.showLoading({
title: '授权中',
});
// 根据环境判断是否传递openid参数
const requestData = {
code: code
};
request.post('/srv/?a=openid', {
code: code,
openid: 'h-008'
// openid: 'o5NFZ5cFQtLRy3aVHaZMLkjHFusI'
// openid: 'o5NFZ5TpgG4FwYursGCLjcUJH2ak'
// openid: 'o5NFZ5cqroPYwawCp8FEOxewtgnw'
})
// 测试环境下传递openid,正式环境不传递
if (process.env.NODE_ENV === 'development') {
requestData.openid = 'h-008';
}
request.post('/srv/?a=openid', requestData)
.then(res => {
if (res.data.code) {
const cookie = res.cookies[0];
......@@ -98,7 +102,7 @@ export default {
wx.setStorageSync("sessionid", res.cookies[0]);
// 修改请求头
request.defaults.headers.cookie = res.cookies[0];
// 添加延迟确保存储操作完成
setTimeout(() => {
this.handleNavigateAfterAuth();
......@@ -120,14 +124,14 @@ export default {
Taro.hideLoading();
});
},
/**
* 处理授权成功后的页面跳转
*/
handleNavigateAfterAuth() {
try {
const params = getCurrentPageParam();
if (params.url === 'pages/productDetail/index') {
// 详情页的分享跳转处理 - 使用绝对路径
this.navigateToPage(`/pages/productDetail/index?id=${params.id}`);
......@@ -144,7 +148,7 @@ export default {
this.navigateToHome();
}
},
/**
* 跳转到指定页面
* @param {string} url - 目标页面路径
......@@ -167,7 +171,7 @@ export default {
});
}, 300);
},
/**
* 跳转到首页
*/
......@@ -190,7 +194,7 @@ export default {
});
});
},
/**
* 处理登录错误
* @param {string} message - 错误信息
......@@ -202,13 +206,13 @@ export default {
icon: 'error',
duration: 2000
});
// 错误情况下延迟跳转到首页
setTimeout(() => {
this.navigateToHome();
}, 2000);
},
bindGetUserInfo (e) {
console.warn(e.detail.userInfo)
},
......