Bladeren bron

'登录逻辑中接入本地网关登陆流程;完成企业注册的接口接入'

main
郑州 3 jaren geleden
bovenliggende
commit
d2305369d4
5 gewijzigde bestanden met toevoegingen van 85 en 38 verwijderingen
  1. +5
    -7
      src/pages/login/SmsInputer.tsx
  2. +26
    -9
      src/pages/login/index.tsx
  3. +9
    -1
      src/services/system.ts
  4. +9
    -1
      src/services/user.ts
  5. +36
    -20
      src/utils/request.config.ts

+ 5
- 7
src/pages/login/SmsInputer.tsx Bestand weergeven

@@ -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<null> = {
code: 0,
data: null,
requestIsSuccess: true,
success: true,
};
// 调用发送验证码的接口
const res = await fetchApi<null>('company/sendVerificationCode', {
Phone: phone,
});
handleRequest(res).error(() => {
message.error('验证码发送失败,请稍后再试');
setTickFlag(false);


+ 26
- 9
src/pages/login/index.tsx Bestand weergeven

@@ -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() {
<RegisterModal
visible={regModalVisible}
onCancel={() => setRegModalVisible(false)}
onFninsh={(nextAccount, nextPassword) => {
setAccount(nextAccount);
setPassword(nextPassword);
setRegModalVisible(false);
}}
/>
</div>
);
}

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}
>
<Form.Item name="companyName" label="公司名称" rules={requiredRules()}>
<Form.Item name="compAllName" label="公司名称" rules={requiredRules()}>
<Input />
</Form.Item>

<Form.Item name="ccc" label="管理员" rules={requiredRules()}>
<Form.Item name="userName" label="管理员" rules={requiredRules()}>
<Input />
</Form.Item>

@@ -219,7 +232,11 @@ function RegisterModal(props: RegisterModalProps) {

<Form.Item noStyle dependencies={['phone']}>
{() => (
<Form.Item name="sms" label="验证码" rules={requiredRules()}>
<Form.Item
name="verificationCode"
label="验证码"
rules={requiredRules()}
>
<SmsInputer phone={form.getFieldValue('phone')} />
</Form.Item>
)}


+ 9
- 1
src/services/system.ts Bestand weergeven

@@ -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 = <T>(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<null>('login', { userId, userPhone });
}),
};

export default system;

+ 9
- 1
src/services/user.ts Bestand weergeven

@@ -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<DATA.User>(
'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;


+ 36
- 20
src/utils/request.config.ts Bestand weergeven

@@ -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];
}
}

Laden…
Annuleren
Opslaan