前端实现切换租户选择第三方授权登录,和优化第三方页面登录注册

This commit is contained in:
thiszhc
2023-07-01 02:26:58 +08:00
parent db6e95bb96
commit 2b7ffdf19c
4 changed files with 39 additions and 13 deletions

View File

@ -3,11 +3,14 @@
</template>
<script setup lang="ts">
import {socialLogin} from '@/api/login';
import {setToken} from '@/utils/auth';
import { socialLogin } from '@/api/login';
import { setToken } from '@/utils/auth';
import Cookies from 'js-cookie';
import { getToken } from '@/utils/auth';
import router from '@/router';
const route = useRoute();
const router = useRouter();
const loading = ref(true);
/**
@ -17,8 +20,16 @@ const router = useRouter();
const code = route.query.code;
const state = route.query.state;
const source = route.query.source as string;
const loading = ref(true);
await socialLogin(source, code, state)
const tenantId = Cookies.get("tenantId") ? Cookies.get("tenantId") as string : '000000';
const loginType = getToken() ? 'register' : 'login';
/**
* 通过code获取token
* @param {string} source
* @param {string} code
* @param {string} state
*/
await socialLogin(source, tenantId, loginType, code, state)
.then(async (res) => {
if (res.code !== 200) {
ElMessage.error(res.msg);
@ -26,9 +37,10 @@ await socialLogin(source, code, state)
return;
}
loading.value = false;
setToken(res.msg);
ElMessage.success('登录成功');
// setToken(res.msg);
loginType === 'login' ? setToken(res.data) : ElMessage.success(res.msg);
location.href = import.meta.env.VITE_APP_CONTEXT_PATH + 'index';
})
.catch(() => {
loading.value = false;