diff --git a/src/pages/login/SmsInputer.tsx b/src/pages/login/SmsInputer.tsx index 1c5b56f..ca3bd75 100644 --- a/src/pages/login/SmsInputer.tsx +++ b/src/pages/login/SmsInputer.tsx @@ -6,6 +6,7 @@ import { throttle } from 'lodash'; import { handleRequest, isValidPhone } from '@/utils/tool'; import { useInterval } from 'ahooks'; import classNames from 'classnames'; +import { fetchApi } from '@/utils/request'; interface SmsInputerProps extends InputProps { phone?: string; @@ -24,13 +25,10 @@ export default function SmsInputer(props: SmsInputerProps) { return; } setTickFlag(true); - // todo: 调用发送验证码的接口 - const res: API.ResponseData = { - code: 0, - data: null, - requestIsSuccess: true, - success: true, - }; + // 调用发送验证码的接口 + const res = await fetchApi('company/sendVerificationCode', { + Phone: phone, + }); handleRequest(res).error(() => { message.error('验证码发送失败,请稍后再试'); setTickFlag(false); diff --git a/src/pages/login/index.tsx b/src/pages/login/index.tsx index 79fdee1..87eb64d 100644 --- a/src/pages/login/index.tsx +++ b/src/pages/login/index.tsx @@ -1,13 +1,12 @@ 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 { history, useModel } from 'umi'; import { MobileFilled, LockFilled } from '@ant-design/icons'; -import css from 'classnames'; import { useCallback } from 'react'; import { useEffect } from 'react'; 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 classNames from 'classnames'; import SmsInputer from './SmsInputer'; @@ -17,6 +16,7 @@ import { isClient } from '@/services/system'; import storage from '@/utils/storage'; import { useRef } from 'react'; import { useLayoutEffect } from 'react'; +import { fetchApi } from '@/utils/request'; export default function Login() { const [errText, setErrText] = useState(''); @@ -129,12 +129,19 @@ export default function Login() { setRegModalVisible(false)} + onFninsh={(nextAccount, nextPassword) => { + setAccount(nextAccount); + setPassword(nextPassword); + setRegModalVisible(false); + }} /> ); } -interface RegisterModalProps extends ModalProps {} +interface RegisterModalProps extends ModalProps { + onFninsh: (phone: string, password: string) => void; +} const defaultValidateMessages = { required: '${label}不能为空', @@ -146,7 +153,7 @@ const requiredRules: (...arg: Rule[]) => Rule[] = memoize((...otherRules) => [ ]); function RegisterModal(props: RegisterModalProps) { - const { className, ...restProps } = props; + const { className, onFninsh, ...restProps } = props; const [form] = useForm(); useEffect(() => { if (props.visible) { @@ -157,7 +164,13 @@ function RegisterModal(props: RegisterModalProps) { const onSubmit = useCallback(async () => { try { 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) {} }, [form]); @@ -178,11 +191,11 @@ function RegisterModal(props: RegisterModalProps) { validateMessages={defaultValidateMessages} requiredMark={false} > - + - + @@ -219,7 +232,11 @@ function RegisterModal(props: RegisterModalProps) { {() => ( - + )} diff --git a/src/services/system.ts b/src/services/system.ts index 8d228c7..727950c 100644 --- a/src/services/system.ts +++ b/src/services/system.ts @@ -1,6 +1,9 @@ +import { fetchLocalApi } from '@/utils/request'; + export const isClient = !!window.ipcRenderer; // process.env.IS_CLIENT; -const safeCall = (f: (...args: any[]) => any) => (isClient ? f : () => {}); +const noop = () => {}; +const safeCall = (f: T, repalceF = noop) => (isClient ? f : repalceF); const ipcRenderer = window.ipcRenderer; @@ -30,6 +33,11 @@ const system = { ipcRenderer.invoke('storage:remove', { key }); }), }, + + // 发往网关的请求 + login: safeCall((userId: string, userPhone: string) => { + return fetchLocalApi('login', { userId, userPhone }); + }), }; export default system; diff --git a/src/services/user.ts b/src/services/user.ts index ac3d2ab..2e68f73 100644 --- a/src/services/user.ts +++ b/src/services/user.ts @@ -3,6 +3,7 @@ import { fetchApi } from '@/utils/request'; import storage from '@/utils/storage'; import { errorReponse, firstCharToLowerCase, isReqSuccess } from '@/utils/tool'; import { propertyOf } from 'lodash'; +import system, { isClient } from './system'; export async function queryCurrent() { const accountId = storage.get('accountId'); @@ -16,7 +17,7 @@ export async function queryCurrent() { } export async function login(account: string, password: string) { - const res = await fetchApi( + const res = await fetchApi( 'authentication/login', { UserName: account, Password: password }, { silent: true }, @@ -32,6 +33,13 @@ export async function login(account: string, password: string) { 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 }); // if (!isReqSuccess(companyInfoRes)) { // return companyInfoRes; diff --git a/src/utils/request.config.ts b/src/utils/request.config.ts index 6c2a632..5c316d3 100644 --- a/src/utils/request.config.ts +++ b/src/utils/request.config.ts @@ -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 = [ 'authentication/login', @@ -10,6 +20,8 @@ const postRequestMap = [ 'company/updateCompanyById', 'company/link/addCompanyLink', 'company/link/updateCompanyLink', + 'company/sendVerificationCode', + 'company/registerCompany', 'dept/addDept', 'dept/updateDept', 'user/addUser', @@ -22,32 +34,36 @@ const postRequestMap = [ 'template/addTemplateNodeModelFile', 'template/createNestedRelevance', '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', 'lockingmsg/markRead', 'file/removeFromRecycleBin', '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] { const [service] = path.split('/'); 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'; return [method, fullpath]; -} \ No newline at end of file +}