init 登录跳转

This commit is contained in:
yuping
2023-03-08 14:53:44 +08:00
parent e864536e86
commit ed1c928919
2 changed files with 22 additions and 19 deletions

View File

@@ -99,8 +99,8 @@ export async function request(_url, params) {
if (response.code !== 200 && response.code !== 0) { if (response.code !== 200 && response.code !== 0) {
console.log('window.location.', window, router) console.log('window.location.', window, router)
if (response.code === 1000) { if (response.code === 1000) {
delCookie() delCookie();
(import.meta.env.MODE === 'development' || import.meta.env.MODE === 'test') ? router.push({ path: '/login', query: { returnUrl: router.currentRoute.value.fullPath } }) : window.open(window.location.protocol + import.meta.env.VITE_BASE_LOGIN_URL + encodeURIComponent(window.location.protocol + import.meta.env.VITE_BOE_BASE_URL + import.meta.env.VITE_BASE + router.currentRoute.value.fullPath), '_top') (import.meta.env.MODE === 'development' || import.meta.env.MODE === 'test') ? router.push({ path: '/login', query: { returnUrl: router.currentRoute.value.fullPath } }) : window.open(window.location.protocol + import.meta.env.VITE_BASE_LOGIN_URL + encodeURIComponent(window.location.protocol + import.meta.env.VITE_BOE_BASE_URL + import.meta.env.VITE_BASE + router.currentRoute.value.fullPath), '_top')
} }
if (response.code === 2001) { if (response.code === 2001) {
router.push({ path: '/FaceTeachSignUp', query: { courseId: router.currentRoute.value.query.courseId, type: 3 } }) router.push({ path: '/FaceTeachSignUp', query: { courseId: router.currentRoute.value.query.courseId, type: 3 } })

View File

@@ -6,33 +6,36 @@
* @FilePath: /stu_h5/src/api/utils.js * @FilePath: /stu_h5/src/api/utils.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/ */
import { watch, ref } from "vue"; import {watch, ref} from "vue";
import { boeRequest } from "@/api/request"; import {boeRequest} from "@/api/request";
import { GET_USER_LIST } from "@/api/ThirdApi"; import {GET_USER_LIST} from "@/api/ThirdApi";
export function useImage(src) { export function useImage(src) {
return new URL(`../assets/image/${src}`, import.meta.url).href return new URL(`../assets/image/${src}`, import.meta.url).href;
} }
export function setCookie(name, value, perpetual) { export function setCookie(name, value, perpetual) {
const d = new Date() const d = new Date();
d.setDate(perpetual * 24 * 60 * 60 * 1000) d.setDate(perpetual * 24 * 60 * 60 * 1000);
document.cookie = `${name}=${value};expires=${d.toGMTString()};path=/` document.cookie = `${name}=${value};expires=${d.toGMTString()};path=/`;
} }
export function getCookie(name) { export function getCookie(name) {
return document.cookie?.split(";").find(e => e.includes(name))?.replace(`${name}=`, '') || '' return document.cookie?.split(";").find(e => e.includes(name))?.replace(`${name}=`, "") || "";
} }
export function delCookie() { export function delCookie() {
setCookie("token", "", -1) setCookie("token", "", -1);
localStorage.removeItem("userInfo");
} }
export function useUserInfo(id) { export function useUserInfo(id) {
const userInfo = ref({}) const userInfo = ref({});
watch(id, () => { watch(id, () => {
id.value && boeRequest(GET_USER_LIST, { id: id.value }).then(res => { id.value && boeRequest(GET_USER_LIST, { id: id.value }).then(res => {
userInfo.value = res.result.userInfoList[0] userInfo.value = res.result.userInfoList[0];
userInfo.value.avatar = userInfo.value.avatar ? userInfo.value.avatar.includes(import.meta.env.VITE_FILE_PATH) ? userInfo.value.avatar : (import.meta.env.VITE_FILE_PATH + userInfo.value.avatar) : '/800e23f7-b58c-4192-820d-0c6a2b7544cc.png' userInfo.value.avatar = userInfo.value.avatar ? userInfo.value.avatar.includes(import.meta.env.VITE_FILE_PATH) ? userInfo.value.avatar : (import.meta.env.VITE_FILE_PATH + userInfo.value.avatar) : "/800e23f7-b58c-4192-820d-0c6a2b7544cc.png";
}) });
}) });
return userInfo return userInfo;
} }