hookehuyr

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

测试环境下传递固定openid参数,正式环境仅传递code参数
1 <!-- 1 <!--
2 * @Date: 2022-09-19 14:11:06 2 * @Date: 2022-09-19 14:11:06
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2025-07-14 15:37:49 4 + * @LastEditTime: 2025-07-14 16:51:45
5 * @FilePath: /jgdl/src/pages/auth/index.vue 5 * @FilePath: /jgdl/src/pages/auth/index.vue
6 * @Description: 文件描述 6 * @Description: 文件描述
7 --> 7 -->
...@@ -73,7 +73,7 @@ export default { ...@@ -73,7 +73,7 @@ export default {
73 } 73 }
74 }); 74 });
75 }, 75 },
76 - 76 +
77 /** 77 /**
78 * 处理登录成功后的网络请求 78 * 处理登录成功后的网络请求
79 * @param {string} code - 微信登录code 79 * @param {string} code - 微信登录code
...@@ -82,14 +82,18 @@ export default { ...@@ -82,14 +82,18 @@ export default {
82 Taro.showLoading({ 82 Taro.showLoading({
83 title: '授权中', 83 title: '授权中',
84 }); 84 });
85 +
86 + // 根据环境判断是否传递openid参数
87 + const requestData = {
88 + code: code
89 + };
85 90
86 - request.post('/srv/?a=openid', { 91 + // 测试环境下传递openid,正式环境不传递
87 - code: code, 92 + if (process.env.NODE_ENV === 'development') {
88 - openid: 'h-008' 93 + requestData.openid = 'h-008';
89 - // openid: 'o5NFZ5cFQtLRy3aVHaZMLkjHFusI' 94 + }
90 - // openid: 'o5NFZ5TpgG4FwYursGCLjcUJH2ak' 95 +
91 - // openid: 'o5NFZ5cqroPYwawCp8FEOxewtgnw' 96 + request.post('/srv/?a=openid', requestData)
92 - })
93 .then(res => { 97 .then(res => {
94 if (res.data.code) { 98 if (res.data.code) {
95 const cookie = res.cookies[0]; 99 const cookie = res.cookies[0];
...@@ -98,7 +102,7 @@ export default { ...@@ -98,7 +102,7 @@ export default {
98 wx.setStorageSync("sessionid", res.cookies[0]); 102 wx.setStorageSync("sessionid", res.cookies[0]);
99 // 修改请求头 103 // 修改请求头
100 request.defaults.headers.cookie = res.cookies[0]; 104 request.defaults.headers.cookie = res.cookies[0];
101 - 105 +
102 // 添加延迟确保存储操作完成 106 // 添加延迟确保存储操作完成
103 setTimeout(() => { 107 setTimeout(() => {
104 this.handleNavigateAfterAuth(); 108 this.handleNavigateAfterAuth();
...@@ -120,14 +124,14 @@ export default { ...@@ -120,14 +124,14 @@ export default {
120 Taro.hideLoading(); 124 Taro.hideLoading();
121 }); 125 });
122 }, 126 },
123 - 127 +
124 /** 128 /**
125 * 处理授权成功后的页面跳转 129 * 处理授权成功后的页面跳转
126 */ 130 */
127 handleNavigateAfterAuth() { 131 handleNavigateAfterAuth() {
128 try { 132 try {
129 const params = getCurrentPageParam(); 133 const params = getCurrentPageParam();
130 - 134 +
131 if (params.url === 'pages/productDetail/index') { 135 if (params.url === 'pages/productDetail/index') {
132 // 详情页的分享跳转处理 - 使用绝对路径 136 // 详情页的分享跳转处理 - 使用绝对路径
133 this.navigateToPage(`/pages/productDetail/index?id=${params.id}`); 137 this.navigateToPage(`/pages/productDetail/index?id=${params.id}`);
...@@ -144,7 +148,7 @@ export default { ...@@ -144,7 +148,7 @@ export default {
144 this.navigateToHome(); 148 this.navigateToHome();
145 } 149 }
146 }, 150 },
147 - 151 +
148 /** 152 /**
149 * 跳转到指定页面 153 * 跳转到指定页面
150 * @param {string} url - 目标页面路径 154 * @param {string} url - 目标页面路径
...@@ -167,7 +171,7 @@ export default { ...@@ -167,7 +171,7 @@ export default {
167 }); 171 });
168 }, 300); 172 }, 300);
169 }, 173 },
170 - 174 +
171 /** 175 /**
172 * 跳转到首页 176 * 跳转到首页
173 */ 177 */
...@@ -190,7 +194,7 @@ export default { ...@@ -190,7 +194,7 @@ export default {
190 }); 194 });
191 }); 195 });
192 }, 196 },
193 - 197 +
194 /** 198 /**
195 * 处理登录错误 199 * 处理登录错误
196 * @param {string} message - 错误信息 200 * @param {string} message - 错误信息
...@@ -202,13 +206,13 @@ export default { ...@@ -202,13 +206,13 @@ export default {
202 icon: 'error', 206 icon: 'error',
203 duration: 2000 207 duration: 2000
204 }); 208 });
205 - 209 +
206 // 错误情况下延迟跳转到首页 210 // 错误情况下延迟跳转到首页
207 setTimeout(() => { 211 setTimeout(() => {
208 this.navigateToHome(); 212 this.navigateToHome();
209 }, 2000); 213 }, 2000);
210 }, 214 },
211 - 215 +
212 bindGetUserInfo (e) { 216 bindGetUserInfo (e) {
213 console.warn(e.detail.userInfo) 217 console.warn(e.detail.userInfo)
214 }, 218 },
......