forgeplus-react/src/utils/verifyLogin.tsx

190 lines
5.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import React from 'react';
import { history, getDvaApp } from 'umi';
import { Modal, message } from 'antd';
import { isLogin, canShixunAdd, isStudents } from './authority';
import { openNewWindow } from './util';
import { ExclamationCircleOutlined } from '@ant-design/icons';
import Img from '@/assets/images/403Qrcode.png';
import Authorize from '@/assets/images/Authorize.png';
import Studnetqun from '@/assets/images/studnetqun.png';
import ENV from './env';
export const handleVerify = (dispatch: Function) => {
if (handleVerifyLogin(dispatch) && handleProfleCompletedModal()) {
return true;
}
return false;
}
export const handleVerifyLogin = (dispatch: Function) => {
if (!isLogin()) {
dispatch({
type: 'user/showPopLogin',
payload: {
showPopLogin: true,
showClosable: true
},
});
return false;
}
return true;
}
export const handleProfleCompletedModal = () => {
const { user } = getDvaApp()._store.getState();
if (!user.userInfo?.profile_completed) {
Modal.confirm({
title: '提示',
width: 530,
centered: true,
content: <div className="tc font16">
使
</div>,
okText: `立即完善`,
cancelText: "稍后完善",
onOk: () => {
window.location.href=`${ENV.FORGE_SERVER}/settings/profile`;
}
})
return false;
}
return true;
}
export const handleProfessionalCertificationModal = () => {
const { user } = getDvaApp()._store.getState();
if (!user.userInfo?.professional_certification) {
Modal.confirm({
title: '提示',
centered: true,
content: <div className="tc">使</div>,
okText: `立即完善`,
cancelText: "稍后完善",
onOk: () => {
openNewWindow('/account/certification');
}
})
return false;
}
return true;
}
export const handleCanShixunAddModal = () => {
if (canShixunAdd()) {
return true;
}
Modal.warning({
centered: true,
width: 530,
title: '提示',
content: <div className="tc" style={{marginLeft:-38}}>
<p>@群管理员</p>
<img src={isStudents() ? Studnetqun : `${ENV.IMG_SERVER}/images/educoder/qqqun20191230.png`} width={200} />
</div>,
okText: `我知道了`,
maskClosable: true,
})
return false;
}
export const AuthorizeModel = (type: any, text?: string) => {
if (type) {
return true;
}
Modal.confirm({
centered: true,
zIndex: 10000,
width: 530,
title: '提示',
content: <div>
<p>{text || '该实践资源需授权后才可使用。 您可以在QQ服务群向管理员申请获得继续操作的权限。'}</p>
<div style={{ marginLeft: '110px' }}>
<img src={Authorize} width={200} />
<div style={{ marginLeft: '35px' }}>{'714336072'}</div>
</div>
</div>,
okText: `立即联系`,
cancelText: '取消',
onOk: () => {
openNewWindow("https://qm.qq.com/cgi-bin/qm/qr?k=tIyDPXUtE0yEk-MOJxhH55lTUJS-nYAM&jump_from=webapi");
}
})
return false;
}
export const ShixunStatusModel = (dispatch: Function, text: string = '') => {
const { shixunsDetail: { detail } } = getDvaApp()._store.getState();
if (detail?.public === 2 || detail?.public === 1 || detail?.shixun_status === 3) {
Modal.info({
centered: true,
icon: <ExclamationCircleOutlined style={{ color: '#faad14' }} />,
width: 460,
title: '提示',
content: <div className="tc" style={{ marginLeft: -38 }}>
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'flex-start', paddingLeft: 38, margin: '12px 0' }}>
<span>{detail?.public === 2 ? '已公开' : (detail?.public === 1 ? '待审核' : '已关闭')}{text}</span>
<p></p>
</div>
<img style={{ border: '4px solid #1890FF', borderRadius: '4px' }} src={Img} alt='二维码' width={160} />
</div>,
okText: '我知道了'
})
return true
}
if (detail?.shixun_status === 2) {
Modal.confirm({
centered: true,
icon: <ExclamationCircleOutlined />,
title: '提示',
content: <div>
<span>{text}</span>
<br />
<span></span>
</div>,
okText: `撤销发布`,
cancelText: '取消',
onOk: () => {
Modal.confirm({
width: 440,
centered: true,
icon: <ExclamationCircleOutlined style={{ color: '#faad14' }} />,
title: '提示',
content: '撤销发布后,学员将无法进行练习。是否确认撤销发布?',
okText: `确定撤销发布`,
cancelText: '取消',
onOk: async () => {
const res = await dispatch({
type: 'shixunsDetail/cancelRelease',
payload: { id: detail?.identifier },
});
if (res.status !== 401) {
message.success('撤销发布成功。实训回到未发布的状态。')
dispatch({
type: 'shixunsDetail/getShixunsDetail',
payload: { id: detail?.identifier },
});
dispatch({
type: 'practiceSetting/getCommonData',
payload: { id: detail?.identifier }
});
}
}
})
}
})
return true;
}
return false;
}