|
|
|
@ -5,14 +5,90 @@ import Logo from '@/assets/logo.svg';
|
|
|
|
import LoginForm from './form';
|
|
|
|
import LoginForm from './form';
|
|
|
|
import LoginBanner from './banner';
|
|
|
|
import LoginBanner from './banner';
|
|
|
|
import styles from './style/index.module.less';
|
|
|
|
import styles from './style/index.module.less';
|
|
|
|
import { getToken } from '@/api/user';
|
|
|
|
import { getToken, getUserInfo } from '@/api/user';
|
|
|
|
import { setToken } from '@/utils/auth';
|
|
|
|
import { setSessionUserInfo, setToken } from '@/utils/auth';
|
|
|
|
import { localGet, localRemove, openWindow } from '@/utils/common';
|
|
|
|
import { localGet, localRemove, openWindow } from '@/utils/common';
|
|
|
|
import logoImage from '@/public/assets/logo.png';
|
|
|
|
import logoImage from '@/public/assets/logo.png';
|
|
|
|
|
|
|
|
import store from '@/store';
|
|
|
|
|
|
|
|
import { updateUserInfo } from '@/store/user';
|
|
|
|
|
|
|
|
import { getMyComponents, getPubComponents, getTeamComponents } from '@/api/components';
|
|
|
|
|
|
|
|
import { getPublishPage } from '@/api/flow';
|
|
|
|
|
|
|
|
import dayjs from 'dayjs';
|
|
|
|
|
|
|
|
|
|
|
|
function Login() {
|
|
|
|
function Login() {
|
|
|
|
const router = useRouter();
|
|
|
|
const router = useRouter();
|
|
|
|
const [isNeedLogin, setIsNeedLogin] = useState(false);
|
|
|
|
const [isNeedLogin, setIsNeedLogin] = useState(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function fetchUserInfo() {
|
|
|
|
|
|
|
|
store.dispatch(updateUserInfo({ userLoading: true }));
|
|
|
|
|
|
|
|
const res: any = await getUserInfo();
|
|
|
|
|
|
|
|
setSessionUserInfo(res.data);
|
|
|
|
|
|
|
|
store.dispatch(updateUserInfo({ userInfo: { ...res.data } }));
|
|
|
|
|
|
|
|
getComponentData();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const getComponentData = async () => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const requests = [
|
|
|
|
|
|
|
|
{ promise: getMyComponents(), key: 'myLibs' },
|
|
|
|
|
|
|
|
{ promise: getPubComponents(), key: 'pubLibs' },
|
|
|
|
|
|
|
|
{ promise: getTeamComponents(), key: 'teamLibs' },
|
|
|
|
|
|
|
|
{ promise: getPublishPage(), key: 'pubFlow' }
|
|
|
|
|
|
|
|
// {promise: appId ? getMineSubs({id: appId}) : Promise.resolve(null), key: 'myFlow'},
|
|
|
|
|
|
|
|
// {promise: getEventList(), key: 'eventList'}
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const obj: any = {
|
|
|
|
|
|
|
|
myLibs: null,
|
|
|
|
|
|
|
|
pubLibs: null,
|
|
|
|
|
|
|
|
teamLibs: null,
|
|
|
|
|
|
|
|
pubFlow: null,
|
|
|
|
|
|
|
|
// myFlow: null,
|
|
|
|
|
|
|
|
updateTime: dayjs().format('YYYY-MM-DD HH:mm:ss')
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const userInfo = JSON.parse(sessionStorage.getItem('userInfo') || '{}');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 分别处理每个请求
|
|
|
|
|
|
|
|
for (const { promise, key } of requests) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const res: any = await promise;
|
|
|
|
|
|
|
|
if (res?.code === 200 && res.data?.length > 0) {
|
|
|
|
|
|
|
|
// if (key === 'myLibs') {
|
|
|
|
|
|
|
|
// addCompInfo(res.data);
|
|
|
|
|
|
|
|
// libsStore.setMyLibs(res.data);
|
|
|
|
|
|
|
|
// } else if (key === 'pubLibs') {
|
|
|
|
|
|
|
|
// addCompInfo(res.data);
|
|
|
|
|
|
|
|
// libsStore.setPubLibs(res.data);
|
|
|
|
|
|
|
|
// } else if (key === 'teamLibs') {
|
|
|
|
|
|
|
|
// addCompInfo(res.data);
|
|
|
|
|
|
|
|
// libsStore.setTeamLibs(res.data);
|
|
|
|
|
|
|
|
// } else if (key === 'pubFlow') {
|
|
|
|
|
|
|
|
// addCompInfo(res.data, true);
|
|
|
|
|
|
|
|
// libsStore.setPubFlow(res.data);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// else if (key === 'myFlow') {
|
|
|
|
|
|
|
|
// let newData = formatFlowMy(res.data);
|
|
|
|
|
|
|
|
// addCompInfo(newData, true);
|
|
|
|
|
|
|
|
// libsStore.setMyFlow(newData);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// else if (key === 'eventList') {
|
|
|
|
|
|
|
|
// eventStore.setEventList(res.data);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 更新本地存储数据
|
|
|
|
|
|
|
|
obj[key] = res?.data || null;
|
|
|
|
|
|
|
|
sessionStorage.setItem(`compLibs${userInfo.userId}`, JSON.stringify(obj));
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
console.error(`加载${key}失败:`, error);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
console.error('加载组件库失败:', error);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const handleLogin = async () => {
|
|
|
|
const handleLogin = async () => {
|
|
|
|
const url = new URL(window.location.href);
|
|
|
|
const url = new URL(window.location.href);
|
|
|
|
const code = url.searchParams.get('code');
|
|
|
|
const code = url.searchParams.get('code');
|
|
|
|
@ -43,6 +119,7 @@ function Login() {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
|
|
|
|
fetchUserInfo();
|
|
|
|
router.push('/dashboard/workplace');
|
|
|
|
router.push('/dashboard/workplace');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|