Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
jgdl
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
hookehuyr
2025-07-14 16:59:05 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
3bc6417f30fd5742df74141b7d1e64e027a0bb36
3bc6417f
1 parent
70840d18
fix(auth): 根据环境动态设置openid参数以适配测试和正式环境
测试环境下传递固定openid参数,正式环境仅传递code参数
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
17 deletions
src/pages/auth/index.vue
src/pages/auth/index.vue
View file @
3bc6417
<!--
* @Date: 2022-09-19 14:11:06
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-07-14 1
5:37:49
* @LastEditTime: 2025-07-14 1
6: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)
},
...
...
Please
register
or
login
to post a comment