|
@@ -81,7 +81,7 @@
|
|
|
import md5 from "js-md5";
|
|
|
import {onMounted, ref, computed, reactive} from "vue";
|
|
|
import {Toast, Dialog, Button} from "vant";
|
|
|
-import {login, getSys, wxLogin, getOpenid} from "@/service/login";
|
|
|
+import {login, getSys, getOpenid} from "@/service/login";
|
|
|
import {setLocal, getLocal, navigatorLanguage} from "@/common/js/utils";
|
|
|
import sHeader from "@/components/SimpleHeader";
|
|
|
import logiLogoImgUrl from "@/assets/login/logo.png";
|
|
@@ -158,6 +158,7 @@ export default {
|
|
|
});
|
|
|
if (data.code === "00000") {
|
|
|
setLocal("loginUser", JSON.stringify(data.data));
|
|
|
+ console.log('loginUser JSON:',JSON.stringify(data.data));
|
|
|
Toast.success(t('login.loginSucess'));
|
|
|
// 需要刷新页面,否则 axios.js 文件里的 token 不会被重置
|
|
|
// window.location.href = '/';
|
|
@@ -184,22 +185,16 @@ export default {
|
|
|
const wxLoginHandler = async () => {
|
|
|
state.isLoading = true;
|
|
|
try {
|
|
|
- // 用户静默授权,获取 openid
|
|
|
- const { data: { data: { openid } } } = await getOpenid();
|
|
|
- if (openid) {
|
|
|
- // 调用后端接口进行微信登录
|
|
|
- const { data: { code, message } } = await wxLogin(openid);
|
|
|
- if (code === "00000") {
|
|
|
- // 登录成功,跳转到 home 页面
|
|
|
- await router.push('/home');
|
|
|
- return;
|
|
|
- }
|
|
|
- throw new Error(message || '登录失败');
|
|
|
+ // 用户静默授权,获取 用户信息
|
|
|
+ const {data} = await getOpenid();
|
|
|
+ console.log("微信登录:",data)
|
|
|
+ if (data.code === "00000") {
|
|
|
+ window.location.href = data.data;
|
|
|
+ } else {
|
|
|
+ Toast.fail('微信登录失败:'+data.message);
|
|
|
}
|
|
|
- // 未获取到 openid
|
|
|
- throw new Error('微信授权失败');
|
|
|
} catch (error) {
|
|
|
- handleError(error.message || '登录失败,请重试');
|
|
|
+ handleError(error.message || '微信登录失败,请重试');
|
|
|
} finally {
|
|
|
state.isLoading = false;
|
|
|
}
|