@@ -6,6 +6,7 @@ import { throttle } from 'lodash'; | |||||
import { handleRequest, isValidPhone } from '@/utils/tool'; | import { handleRequest, isValidPhone } from '@/utils/tool'; | ||||
import { useInterval } from 'ahooks'; | import { useInterval } from 'ahooks'; | ||||
import classNames from 'classnames'; | import classNames from 'classnames'; | ||||
import { fetchApi } from '@/utils/request'; | |||||
interface SmsInputerProps extends InputProps { | interface SmsInputerProps extends InputProps { | ||||
phone?: string; | phone?: string; | ||||
@@ -24,13 +25,10 @@ export default function SmsInputer(props: SmsInputerProps) { | |||||
return; | return; | ||||
} | } | ||||
setTickFlag(true); | setTickFlag(true); | ||||
// todo: 调用发送验证码的接口 | |||||
const res: API.ResponseData<null> = { | |||||
code: 0, | |||||
data: null, | |||||
requestIsSuccess: true, | |||||
success: true, | |||||
}; | |||||
// 调用发送验证码的接口 | |||||
const res = await fetchApi<null>('company/sendVerificationCode', { | |||||
Phone: phone, | |||||
}); | |||||
handleRequest(res).error(() => { | handleRequest(res).error(() => { | ||||
message.error('验证码发送失败,请稍后再试'); | message.error('验证码发送失败,请稍后再试'); | ||||
setTickFlag(false); | setTickFlag(false); | ||||
@@ -1,13 +1,12 @@ | |||||
import React, { useState } from 'react'; | import React, { useState } from 'react'; | ||||
import { Input, Button, Form, Modal, ModalProps } from 'antd'; | |||||
import { Input, Button, Form, Modal, ModalProps, message } from 'antd'; | |||||
import styles from './login.less'; | import styles from './login.less'; | ||||
import { history, useModel } from 'umi'; | import { history, useModel } from 'umi'; | ||||
import { MobileFilled, LockFilled } from '@ant-design/icons'; | import { MobileFilled, LockFilled } from '@ant-design/icons'; | ||||
import css from 'classnames'; | |||||
import { useCallback } from 'react'; | import { useCallback } from 'react'; | ||||
import { useEffect } from 'react'; | import { useEffect } from 'react'; | ||||
import { login } from '@/services/user'; | import { login } from '@/services/user'; | ||||
import { handleRequest, passwordReg } from '@/utils/tool'; | |||||
import { firstCharToUpperCase, handleRequest, passwordReg } from '@/utils/tool'; | |||||
import { useForm } from 'antd/lib/form/Form'; | import { useForm } from 'antd/lib/form/Form'; | ||||
import classNames from 'classnames'; | import classNames from 'classnames'; | ||||
import SmsInputer from './SmsInputer'; | import SmsInputer from './SmsInputer'; | ||||
@@ -17,6 +16,7 @@ import { isClient } from '@/services/system'; | |||||
import storage from '@/utils/storage'; | import storage from '@/utils/storage'; | ||||
import { useRef } from 'react'; | import { useRef } from 'react'; | ||||
import { useLayoutEffect } from 'react'; | import { useLayoutEffect } from 'react'; | ||||
import { fetchApi } from '@/utils/request'; | |||||
export default function Login() { | export default function Login() { | ||||
const [errText, setErrText] = useState(''); | const [errText, setErrText] = useState(''); | ||||
@@ -129,12 +129,19 @@ export default function Login() { | |||||
<RegisterModal | <RegisterModal | ||||
visible={regModalVisible} | visible={regModalVisible} | ||||
onCancel={() => setRegModalVisible(false)} | onCancel={() => setRegModalVisible(false)} | ||||
onFninsh={(nextAccount, nextPassword) => { | |||||
setAccount(nextAccount); | |||||
setPassword(nextPassword); | |||||
setRegModalVisible(false); | |||||
}} | |||||
/> | /> | ||||
</div> | </div> | ||||
); | ); | ||||
} | } | ||||
interface RegisterModalProps extends ModalProps {} | |||||
interface RegisterModalProps extends ModalProps { | |||||
onFninsh: (phone: string, password: string) => void; | |||||
} | |||||
const defaultValidateMessages = { | const defaultValidateMessages = { | ||||
required: '${label}不能为空', | required: '${label}不能为空', | ||||
@@ -146,7 +153,7 @@ const requiredRules: (...arg: Rule[]) => Rule[] = memoize((...otherRules) => [ | |||||
]); | ]); | ||||
function RegisterModal(props: RegisterModalProps) { | function RegisterModal(props: RegisterModalProps) { | ||||
const { className, ...restProps } = props; | |||||
const { className, onFninsh, ...restProps } = props; | |||||
const [form] = useForm(); | const [form] = useForm(); | ||||
useEffect(() => { | useEffect(() => { | ||||
if (props.visible) { | if (props.visible) { | ||||
@@ -157,7 +164,13 @@ function RegisterModal(props: RegisterModalProps) { | |||||
const onSubmit = useCallback(async () => { | const onSubmit = useCallback(async () => { | ||||
try { | try { | ||||
const fields = await form.validateFields(); | const fields = await form.validateFields(); | ||||
console.log(fields); | |||||
const params = firstCharToUpperCase(fields); | |||||
console.log(params); | |||||
const res = await fetchApi('company/registerCompany', params); | |||||
handleRequest(res).success(() => { | |||||
message.success('注册成功'); | |||||
onFninsh(fields.phone, fields.password); | |||||
}); | |||||
} catch (e) {} | } catch (e) {} | ||||
}, [form]); | }, [form]); | ||||
@@ -178,11 +191,11 @@ function RegisterModal(props: RegisterModalProps) { | |||||
validateMessages={defaultValidateMessages} | validateMessages={defaultValidateMessages} | ||||
requiredMark={false} | requiredMark={false} | ||||
> | > | ||||
<Form.Item name="companyName" label="公司名称" rules={requiredRules()}> | |||||
<Form.Item name="compAllName" label="公司名称" rules={requiredRules()}> | |||||
<Input /> | <Input /> | ||||
</Form.Item> | </Form.Item> | ||||
<Form.Item name="ccc" label="管理员" rules={requiredRules()}> | |||||
<Form.Item name="userName" label="管理员" rules={requiredRules()}> | |||||
<Input /> | <Input /> | ||||
</Form.Item> | </Form.Item> | ||||
@@ -219,7 +232,11 @@ function RegisterModal(props: RegisterModalProps) { | |||||
<Form.Item noStyle dependencies={['phone']}> | <Form.Item noStyle dependencies={['phone']}> | ||||
{() => ( | {() => ( | ||||
<Form.Item name="sms" label="验证码" rules={requiredRules()}> | |||||
<Form.Item | |||||
name="verificationCode" | |||||
label="验证码" | |||||
rules={requiredRules()} | |||||
> | |||||
<SmsInputer phone={form.getFieldValue('phone')} /> | <SmsInputer phone={form.getFieldValue('phone')} /> | ||||
</Form.Item> | </Form.Item> | ||||
)} | )} | ||||
@@ -1,6 +1,9 @@ | |||||
import { fetchLocalApi } from '@/utils/request'; | |||||
export const isClient = !!window.ipcRenderer; // process.env.IS_CLIENT; | export const isClient = !!window.ipcRenderer; // process.env.IS_CLIENT; | ||||
const safeCall = (f: (...args: any[]) => any) => (isClient ? f : () => {}); | |||||
const noop = () => {}; | |||||
const safeCall = <T>(f: T, repalceF = noop) => (isClient ? f : repalceF); | |||||
const ipcRenderer = window.ipcRenderer; | const ipcRenderer = window.ipcRenderer; | ||||
@@ -30,6 +33,11 @@ const system = { | |||||
ipcRenderer.invoke('storage:remove', { key }); | ipcRenderer.invoke('storage:remove', { key }); | ||||
}), | }), | ||||
}, | }, | ||||
// 发往网关的请求 | |||||
login: safeCall((userId: string, userPhone: string) => { | |||||
return fetchLocalApi<null>('login', { userId, userPhone }); | |||||
}), | |||||
}; | }; | ||||
export default system; | export default system; |
@@ -3,6 +3,7 @@ import { fetchApi } from '@/utils/request'; | |||||
import storage from '@/utils/storage'; | import storage from '@/utils/storage'; | ||||
import { errorReponse, firstCharToLowerCase, isReqSuccess } from '@/utils/tool'; | import { errorReponse, firstCharToLowerCase, isReqSuccess } from '@/utils/tool'; | ||||
import { propertyOf } from 'lodash'; | import { propertyOf } from 'lodash'; | ||||
import system, { isClient } from './system'; | |||||
export async function queryCurrent() { | export async function queryCurrent() { | ||||
const accountId = storage.get('accountId'); | const accountId = storage.get('accountId'); | ||||
@@ -16,7 +17,7 @@ export async function queryCurrent() { | |||||
} | } | ||||
export async function login(account: string, password: string) { | export async function login(account: string, password: string) { | ||||
const res = await fetchApi( | |||||
const res = await fetchApi<DATA.User>( | |||||
'authentication/login', | 'authentication/login', | ||||
{ UserName: account, Password: password }, | { UserName: account, Password: password }, | ||||
{ silent: true }, | { silent: true }, | ||||
@@ -32,6 +33,13 @@ export async function login(account: string, password: string) { | |||||
return errorReponse('该账号没有访问权限'); | return errorReponse('该账号没有访问权限'); | ||||
} | } | ||||
if (isClient) { | |||||
const systemLoginRes = await system.login(res.data.id, res.data.phone); | |||||
if (!isReqSuccess(systemLoginRes)) { | |||||
return errorReponse('本地网管通讯失败'); | |||||
} | |||||
} | |||||
// const companyInfoRes = await fetchApi('company/queryFrontDeskCompanyById', { id: userData.companyId }, { silent: true }); | // const companyInfoRes = await fetchApi('company/queryFrontDeskCompanyById', { id: userData.companyId }, { silent: true }); | ||||
// if (!isReqSuccess(companyInfoRes)) { | // if (!isReqSuccess(companyInfoRes)) { | ||||
// return companyInfoRes; | // return companyInfoRes; | ||||
@@ -1,5 +1,15 @@ | |||||
const pmsServiceMap = ['template', 'project', 'folder', 'file', 'templateCompany', 'projectLinkInvite', 'lockingmsg'] | |||||
.reduce((h: { [key: string]: 'pms' | undefined }, str) => (h[str] = 'pms', h), {}); | |||||
const pmsServiceMap = [ | |||||
'template', | |||||
'project', | |||||
'folder', | |||||
'file', | |||||
'templateCompany', | |||||
'projectLinkInvite', | |||||
'lockingmsg', | |||||
].reduce( | |||||
(h: { [key: string]: 'pms' | undefined }, str) => ((h[str] = 'pms'), h), | |||||
{}, | |||||
); | |||||
const postRequestMap = [ | const postRequestMap = [ | ||||
'authentication/login', | 'authentication/login', | ||||
@@ -10,6 +20,8 @@ const postRequestMap = [ | |||||
'company/updateCompanyById', | 'company/updateCompanyById', | ||||
'company/link/addCompanyLink', | 'company/link/addCompanyLink', | ||||
'company/link/updateCompanyLink', | 'company/link/updateCompanyLink', | ||||
'company/sendVerificationCode', | |||||
'company/registerCompany', | |||||
'dept/addDept', | 'dept/addDept', | ||||
'dept/updateDept', | 'dept/updateDept', | ||||
'user/addUser', | 'user/addUser', | ||||
@@ -22,32 +34,36 @@ const postRequestMap = [ | |||||
'template/addTemplateNodeModelFile', | 'template/addTemplateNodeModelFile', | ||||
'template/createNestedRelevance', | 'template/createNestedRelevance', | ||||
'template/connectNestTemplateFolder', | 'template/connectNestTemplateFolder', | ||||
"folder/createSubfolder", | |||||
"project/createProject", | |||||
"project/editProject", | |||||
"project/assignedWork", | |||||
"file/addArchMilesStone", | |||||
"file/addFile", | |||||
"file/updateFile", | |||||
"file/fileCoordinationChange", | |||||
"file/setShareFile", | |||||
"operation/record", | |||||
"file/updateProjArchiveHistory", | |||||
"templateCompany/addTemplateCompany", | |||||
"project/addProjectGobalConfig", | |||||
"project/linkProject", | |||||
'folder/createSubfolder', | |||||
'project/createProject', | |||||
'project/editProject', | |||||
'project/assignedWork', | |||||
'file/addArchMilesStone', | |||||
'file/addFile', | |||||
'file/updateFile', | |||||
'file/fileCoordinationChange', | |||||
'file/setShareFile', | |||||
'operation/record', | |||||
'file/updateProjArchiveHistory', | |||||
'templateCompany/addTemplateCompany', | |||||
'project/addProjectGobalConfig', | |||||
'project/linkProject', | |||||
'file/submitDeliverables', | 'file/submitDeliverables', | ||||
'lockingmsg/markRead', | 'lockingmsg/markRead', | ||||
'file/removeFromRecycleBin', | 'file/removeFromRecycleBin', | ||||
'file/batchAddFile', | 'file/batchAddFile', | ||||
].reduce((h: { [key: string]: 'POST' | 'GET' }, str) => (h[str] = 'POST', h), {}); | |||||
].reduce( | |||||
(h: { [key: string]: 'POST' | 'GET' }, str) => ((h[str] = 'POST'), h), | |||||
{}, | |||||
); | |||||
export function parseRequest(path: string): ['POST' | 'GET', string] { | export function parseRequest(path: string): ['POST' | 'GET', string] { | ||||
const [service] = path.split('/'); | const [service] = path.split('/'); | ||||
const prefix = pmsServiceMap[service] || 'cms'; | const prefix = pmsServiceMap[service] || 'cms'; | ||||
const fullpath = `api/${prefix}/${service === 'authentication' ? '' : 'v1/'}${path}`; | |||||
const fullpath = `api/${prefix}/${ | |||||
service === 'authentication' ? '' : 'v1/' | |||||
}${path}`; | |||||
const method = postRequestMap[path] || 'GET'; | const method = postRequestMap[path] || 'GET'; | ||||
return [method, fullpath]; | return [method, fullpath]; | ||||
} | |||||
} |