diff --git a/src/layouts/index.tsx b/src/layouts/index.tsx index 6545930e..92f4af8b 100644 --- a/src/layouts/index.tsx +++ b/src/layouts/index.tsx @@ -26,6 +26,7 @@ const SimpleLayouts: FC = ({ loading, globalSetting, children, user, const getData = async () => { let res; + if (location?.search) { let subject_id; const path = location.pathname.split("/"); @@ -49,7 +50,9 @@ const SimpleLayouts: FC = ({ loading, globalSetting, children, user, }, }) } - + if(res){ + InitSetting(); + } if (res?.username && loca.pathname === '/login') { location.href = "/" } @@ -89,9 +92,9 @@ const SimpleLayouts: FC = ({ loading, globalSetting, children, user, delCookie("logintrustie"); getData(); }, [location.pathname]) - useEffect(() => { + + const InitSetting= async () =>{ if (location.pathname.indexOf("classrooms") > -1 && location.pathname.indexOf("detail") === -1) { - } else { document.body.scrollIntoView() } @@ -100,16 +103,13 @@ const SimpleLayouts: FC = ({ loading, globalSetting, children, user, window.location.href = "https://kepukehuan.educoder.net/classrooms/4RW9CYHY/exercise" return; } - + dispatch({ type: 'globalSetting/query', payload: {}, }) dispatch({ type: "globalSetting/setGlobalLoading", payload: { show: false, text: "" } }) - // dispatch({ type: "globalSetting/getSystemUpdate", payload: { show: false, text: "" } }) - console.log(location, ":location") - // http://localhost:8000 - // https://jetcoder.educoder.net + if (window.location.href === 'https://jetcoder.educoder.net' || window.location.href === 'https://jetcoder.educoder.net/') { window.location.href = 'https://www.educoder.net/problems' return @@ -132,7 +132,7 @@ const SimpleLayouts: FC = ({ loading, globalSetting, children, user, } Modal.destroyAll(); setLocale('zh-CN', false); - }, [location.pathname]) + } useEffect(() => { if (globalSetting.updateData.system_update) { diff --git a/src/models/user/index.ts b/src/models/user/index.ts index f1b498df..6dc29199 100755 --- a/src/models/user/index.ts +++ b/src/models/user/index.ts @@ -1,6 +1,6 @@ import { Effect, Reducer, Subscription, history } from 'umi' import { Action } from '@@/plugin-dva/connect' -import { LoginIn, getUserInfo, getNavigationInfo , ForgeLogin , getEducoderUserInfo } from '@/service/user' +import { LoginIn, getUserInfo, getNavigationInfo , ForgeLogin , getEducoderUserInfo , ForgeCheckName , ForgeSaveUserInfo , ForgeCheckEmail } from '@/service/user' export interface UserModelState { name: string @@ -22,7 +22,10 @@ export interface UserModelType { getNavigationInfo: Effect setActionTabs: Effect; ForgeLogin:Effect; - getEducoderUserInfo:Effect + getEducoderUserInfo:Effect, + ForgeCheckName:Effect, + ForgeCheckEmail:Effect, + ForgeSaveUserInfo:Effect } reducers: { save: Reducer @@ -72,7 +75,17 @@ const UserModel: UserModelType = { }) }, *ForgeLogin({ payload }, { call, put }) { + const { to } = payload const response = yield call(ForgeLogin, { ...payload }) + if (!response.status) { + try { + if (to) { + history.replace(to) + } else { + location.reload() + } + } catch (e) { } + } return response; }, *getUserInfo({ payload }, { call, put }) { @@ -84,6 +97,7 @@ const UserModel: UserModelType = { type: 'save', payload: { userInfo: { ...response } }, }) + return response; }, *getEducoderUserInfo({ payload }, { call, put }) { const response = yield call(getEducoderUserInfo, { ...payload}) @@ -102,6 +116,18 @@ const UserModel: UserModelType = { payload: { actionTabs: { ...payload } }, }); }, + *ForgeCheckName({ payload }, { call, put }) { + const response = yield call(ForgeCheckName, { ...payload,debug:"admin" }); + return response; + }, + *ForgeCheckEmail({ payload }, { call, put }) { + const response = yield call(ForgeCheckEmail, { ...payload,debug:"admin" }); + return response; + }, + *ForgeSaveUserInfo({ payload }, { call, put }) { + const response = yield call(ForgeSaveUserInfo, { ...payload }); + return response; + } }, reducers: { save(state, action) { diff --git a/src/pages/Competitions/Detail/components/InitGitLink/index.less b/src/pages/Competitions/Detail/components/InitGitLink/index.less index dd31f6ed..935ca24b 100644 --- a/src/pages/Competitions/Detail/components/InitGitLink/index.less +++ b/src/pages/Competitions/Detail/components/InitGitLink/index.less @@ -9,4 +9,7 @@ div[class~='ant-form-item-control-input-content'] { text-align: left; } + div[class~='ant-form-item-explain'] { + text-align: left; + } } diff --git a/src/pages/Competitions/Detail/components/InitGitLink/index.tsx b/src/pages/Competitions/Detail/components/InitGitLink/index.tsx index 41f0e99b..092350f5 100644 --- a/src/pages/Competitions/Detail/components/InitGitLink/index.tsx +++ b/src/pages/Competitions/Detail/components/InitGitLink/index.tsx @@ -7,8 +7,9 @@ import { connect, Dispatch, } from 'umi'; -import { Modal, Button , Form , Input, Checkbox } from 'antd'; +import { Modal, Button , Form , Input, Spin } from 'antd'; import styles from './index.less'; +import { getCourseParam } from '@/components/Header'; interface PageProps extends Partial { @@ -22,23 +23,96 @@ const InitGitlink:FC=({ visible, user, onClose = () => { }, + dispatch })=>{ const [form] = Form.useForm(); - const [ updateEmail , setUpdateEmail ] = useState(false); + const [ emailforName , setEmailforName ] = useState(false); + const [ loading , setLoading ] = useState(false); useEffect(()=>{ - if(user?.userInfo?.email){ - setUpdateEmail(true); - form.setFieldsValue({ email: user?.userInfo?.email }); + if(!user?.userInfo?.email || (user?.userInfo?.email && user?.userInfo?.email.indexOf("gitlink.org.cn")>-1)){ + form.setFieldsValue({email:""}) }else{ - setUpdateEmail(false); + form.setFieldsValue({ + email:user?.userInfo?.email, + username:user?.userInfo?.login + }) + setEmailforName(true) } },[user?.userInfo]) - function handleFinish(values:any){ - + const handleFinish=async (values:any)=>{ + setLoading(true); + if(emailforName){ + // 如果输入的邮箱已存在用户就走登录流程 + dispatch({ + type:"user/ForgeLogin", + payload:{ + login:values?.email || user?.userInfo?.email, + password:values?.password + } + }) + }else{ + let res = await dispatch({ + type:"user/ForgeSaveUserInfo", + payload:{ + ...values, + email:values?.email || user?.userInfo?.email + } + }) + if(res){ + setLoading(false); + onClose(); + const payload = getCourseParam(); + let res = dispatch({ + type: 'user/getUserInfo', + payload: { + ...payload, + }, + }) + if(res){ + dispatch({ + type: 'globalSetting/query', + payload: {}, + }) + } + } + } } + //判断用户名(username)是否注册 + async function usernameConfirm(rule:any, value:string, callback:any,type:any){ + if(value){ + var result = await dispatch({ + type:"user/ForgeCheckName", + payload:{ + value,type + } + }) + } + callback(); + } + //判断邮箱(email)是否注册 + async function useremailConfirm(rule:any, value:string, callback:any,type:any){ + if(value){ + var result = await dispatch({ + type:"user/ForgeCheckEmail", + payload:{ + email:value + } + }) + if(result?.login){ + setEmailforName(true); + form.setFieldsValue({username:result?.login}) + }else{ + setEmailforName(false); + form.setFieldsValue({username:""}) + } + } + callback(); + } + + return( =({ onCancel={onClose} footer={null} > +
=({ {user?.userInfo?.real_name} { useremailConfirm(rule, value, callback,2) } }]} + validateTrigger={"onBlur"} + validateFirst={true} > - + + + { usernameConfirm(rule, value, callback,1) } + } + ]} + validateTrigger={"onBlur"} + validateFirst={true} + > + - { - !updateEmail && - - - - } =({
+
) } diff --git a/src/pages/Competitions/Detail/index.tsx b/src/pages/Competitions/Detail/index.tsx index 603ae4fd..0405f7e4 100644 --- a/src/pages/Competitions/Detail/index.tsx +++ b/src/pages/Competitions/Detail/index.tsx @@ -87,12 +87,6 @@ const competitionDetails: FC = ({ useEffect(() => { async function init() { - setStaffDetail(await dispatch({ - type: 'competitions/getStaff', - payload: { - identifier: identifier - } - })) const res = await dispatch({ type: 'competitions/getHeader', payload: { @@ -100,7 +94,14 @@ const competitionDetails: FC = ({ } }) setHeaderDetail(res) - setDocumentTitle(res?.name || '竞赛') + setDocumentTitle(res?.name || '竞赛'); + + setStaffDetail(await dispatch({ + type: 'competitions/getStaff', + payload: { + identifier: identifier + } + })) } if (identifier) { init(); @@ -322,7 +323,7 @@ const competitionDetails: FC = ({ return (
setSubComShow(false)} filterlist={subComList}/> - setSubGitlinkShow(false)}/> + setSubGitlinkShow(false)}/> 在线竞赛 {HeaderDetail.name}{HeaderDetail.sub_title ? '-' + HeaderDetail.sub_title : null} diff --git a/src/service/user.ts b/src/service/user.ts index 3551b2d7..0bc5855b 100755 --- a/src/service/user.ts +++ b/src/service/user.ts @@ -13,6 +13,24 @@ export async function ForgeLoginOut(params: any) { // body: { ...params }, }); } +export async function ForgeCheckName(params: any) { + return Fetch(`${ENV.FORGE_SERVER}/api/accounts/check.json`, { + method: 'post', + body: { ...params }, + }); +} +export async function ForgeCheckEmail(params: any) { + return Fetch(`${ENV.FORGE_SERVER}/api/users/email_search.json`, { + method: 'get', + params: {...params} + }); +} +export async function ForgeSaveUserInfo(params: any) { + return Fetch(`${ENV.FORGE_SERVER}/api/accounts/simple_update.json`, { + method: 'post', + body: { ...params }, + }); +} export async function LoginIn(params: any) { return Fetch('/api/accounts/login.json', { method: 'post',