Commit 9e6b21f9 authored by 前端-许佳敏's avatar 前端-许佳敏

fix:开启强类型校验

parent 6de0cf40
const globalConfig = {
menu: {
logo: 'xxx',
title: 'xxx'
}
}
export default globalConfig
\ No newline at end of file
......@@ -4,6 +4,8 @@ import React from 'react'
import MobxProvider from './store'
import 'mobx-react-lite/batchingForReactDom'
import globalConfig from '../config/base.config'
let extraRoutes: never[] = []
/**
......@@ -69,7 +71,7 @@ let extraRoutes: never[] = []
* @param {*} container
* @returns
*/
export function rootContainer(container) {
export function rootContainer(container: any) {
return React.createElement(MobxProvider, null, container);
}
......@@ -95,4 +97,15 @@ export function rootContainer(container) {
// ],
// requestInterceptors: [],
// responseInterceptors: []
// }
\ No newline at end of file
// }
/**
* @description 初始化配置数据 https://umijs.org/zh-CN/plugins/plugin-initial-state#%E4%BB%8B%E7%BB%8D
* @author xjm
* @date 2020-06-10
* @export
*/
export async function getInitialState():Promise<{menu: {title: string, logo: string}}> {
return globalConfig
}
\ No newline at end of file
......@@ -2,20 +2,21 @@ export interface IRoutes {
routes: []
}
/**
* @todo
* @description 定义请求成功的接口模型
* @author xjm
* @date 2020-05-25
* @date 2020-06-01
* @export
* @interface IRequest
* @interface IRequestSuccess
* @template T data类型, 无法指定时可传入any
*/
export interface IRequest {
export interface IRequestSuccess<T> {
code: number,
data: T,
message: string,
time: number
}
/**
* @todo
* @description 定义请求失败时的接口模型
......@@ -24,6 +25,9 @@ export interface IRequest {
* @export
* @interface IRequestError
*/
export interface IRequestError {
export interface IRequestError extends Error {
data?: any,
message: string,
time?: number
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ import React, {Component} from 'react';
class Index extends Component<{}, {}> {
render() {
return <div>
index
</div>
......
......@@ -5,7 +5,7 @@ import { ExclamationCircleFilled } from '@ant-design/icons'
const LoginWrap: React.FC = () => {
const isValied = true
const finish = (value) => {
const finish = (value: any) => {
console.log(value)
}
return (
......
import React, { useState, useRef } from 'react'
import { Input, Form, Steps, Button, Row, Space } from 'antd'
import { Input, Form, Steps, Button, Row, Space, message } from 'antd'
import styles from './index.less'
import globalStyles from '@/global.less'
import cx from 'classnames'
import { FormPage } from 'god'
import { IFormControllers, IFormButtonTypes } from 'god/dist/src/form-page'
import { Link } from 'umi'
import { Link, useModel } from 'umi'
import ListCard from '@/components/ListCard'
import ButtonList from './components/ButtonList'
import { FormInstance } from 'antd/lib/form'
import { omit } from '@/utils'
import { postMemberRegister } from '@/services/member'
const Step = Steps.Step
......@@ -22,6 +24,7 @@ const registerForm: IFormControllers[] = [
{
type: 'Input',
name: 'phone',
span: 24,
inputProps: {
addonBefore: <div className={styles.formBefore}>+86</div>,
placeholder: '请输入你的手机号码',
......@@ -29,13 +32,15 @@ const registerForm: IFormControllers[] = [
},
{
type: 'Verification',
name: 'code',
name: 'smsCode',
span: 24,
inputProps: {
}
},
{
type: 'Input',
name: 'password',
span: 24,
inputProps: {
type: 'password',
placeholder: '设置你的密码',
......@@ -44,6 +49,7 @@ const registerForm: IFormControllers[] = [
{
type: 'Input',
name: 'confirmPassword',
span: 24,
inputProps: {
type: 'password',
placeholder: '请再次输入你的登录密码',
......@@ -52,6 +58,7 @@ const registerForm: IFormControllers[] = [
{
type: 'Input',
name: 'email',
span: 24,
inputProps: {
type: 'email',
placeholder: '请输入你的邮箱(选填)',
......@@ -75,8 +82,7 @@ const registerButtons: IFormButtonTypes[] = [
text: '同意协议并注册',
type: 'primary',
htmlType: 'submit',
block: true,
disabled: true,
block: true
}
]
......@@ -182,7 +188,7 @@ const form2: mixinForm[] = [
}
]
const UserRegistry = () => {
const [current, setCurrent] = useState(1)
const [current, setCurrent] = useState(0)
const [next, setNext] = useState(true)
const form1Ref = useRef<{action?: FormInstance}>({})
......@@ -197,6 +203,14 @@ const UserRegistry = () => {
console.log(values)
});
}
const handleSubmit = (values: any) => {
const params = omit(values, ['confirmPassword', 'readme'])
postMemberRegister(params).then(res => {
const { data } = res
message.success(data.id)
})
}
return (
<div className={cx(styles.register, globalStyles.lingxiBusinessContent1024)}>
<h3>欢迎您注册数商云账号</h3>
......@@ -209,7 +223,7 @@ const UserRegistry = () => {
{
current === 0 &&
<div className={styles.formBox}>
<FormPage renderFormLists={registerForm} renderButtonLists={registerButtons}>
<FormPage onSubmit={values => { handleSubmit(values) }} renderFormLists={registerForm} renderButtonLists={registerButtons}>
<Row justify='center' align='middle'>
已有平台账号?<Button type='link'>去登陆</Button>
</Row>
......
declare namespace API {
export interface currentUser {
name?: string;
age?: number;
}
}
\ No newline at end of file
import BaseService from "../baseService";
const mockData = () => {
return new Promise(resolve => {
setTimeout(() => {
resolve({
data: 10,
success: true
})
}, 2000)
})
}
class AccountController extends BaseService {
constructor() {
super()
}
async add() {
try {
const data = await mockData()
return data
} catch(err) {
return err
}
}
async delete() {
}
async update() {
}
async getList() {
}
}
export default new AccountController()
\ No newline at end of file
/**
* @todo
* @description 公共请求方法
* @author xjm
* @date 2020-05-25
* @class BaseService
*/
class BaseService {
protected success(data) {
return Promise.resolve(data)
}
protected error(err) {
return Promise.reject(err)
}
}
export default BaseService
\ No newline at end of file
// 用于表格数据时的模型定义
export interface ApiListData<T> {
data: T[],
totalCount: number
}
\ No newline at end of file
import AccountCtroller from './account'
const Services = {
AccountCtroller
}
export default Services
\ No newline at end of file
declare namespace MemberApi {
interface RegisterBasicModel {
phone: string;
smsCode: string;
password: string;
email: string;
}
interface RegisterBasicDTO {
id: number
}
}
\ No newline at end of file
import request from '@/utils/request';
const prefix = '/member/merchant'
/**
* @description 用户基础注册接口
* @param {MemberApi.RegisterBasicModel} params
*/
export async function postMemberRegister(params: MemberApi.RegisterBasicModel) {
return request<MemberApi.RegisterBasicDTO>('/member/register/basic', {
prefix,
params
})
}
......@@ -7,7 +7,16 @@ function isObject(obj: any) {
return Object.prototype.toString.call(obj) === '[object Object]'
}
export function omit(obj: any, arr: string[]) {
const tempObj = {...obj}
for (let i = 0; i < arr.length; i++) {
delete tempObj[arr[i]]
}
return tempObj
}
export default {
isArray,
isObject
isObject,
omit
}
\ No newline at end of file
import { extend } from 'umi-request';
import { extend, ResponseError, OnionOptions, RequestOptionsInit, ResponseInterceptor, OnionMiddleware, Context, RequestMethod } from 'umi-request';
import responseCode from '@/constants/responseCode'
import { IRequestError, IRequestSuccess } from '..';
import { message } from 'antd'
export type CtlType = 'none' | 'message'
// 根前缀请求路径
const basePrefix = '/api'
export interface IApiRequest extends RequestOptionsInit {
ctlType?: CtlType
// 可以用于扩展请求配置
extendsOptions?: RequestOptionsInit
}
/**
*
* umi-request文档 https://github.com/umijs/umi-request/blob/master/README_zh-CN.md
*
*/
type httpStatus = {
[key: number]: string
}
const errorMessage: httpStatus = {
400: "发出的请求有错误,服务器没有进行新建或修改数据的操作。",
401: "用户没有权限(令牌、用户名、密码错误)。",
403: "用户得到授权,但是访问是被禁止的。",
404: "发出的请求针对的是不存在的记录,服务器没有进行操作。",
406: "请求的格式不可得。",
410: "请求的资源被永久删除,且不会再得到的。",
422: "当创建一个对象时,发生一个验证错误。",
500: "服务器发生错误,请检查服务器。",
502: "网关错误。",
503: "服务不可用,服务器暂时过载或维护。",
504: "网关超时。",
};
const errorHandler = (error: ResponseError):IRequestError => {
const { response } = error
// http状态码非200的错误处理
const messageText = errorMessage[response.status]
if (response) {
message.error('http请求错误: ' + response.status + '->' + messageText, 3)
}
// throw可令响应promise走catch, 如需走resolve需直接return
throw {
message: messageText,
...error
}
}
const defaultHeaders = {
'Content-Type': 'Application/json'
}
/**
* 配置request请求时的默认参数, 底层使用fetch进行请求
*/
const request = extend({
const baseRequest = extend({
timeout: 30 * 1000,
headers: defaultHeaders,
credentials: 'include', // 默认请求是否带上cookie
errorHandler
});
// 请求拦截器
baseRequest.interceptors.request.use((url: string, options: RequestOptionsInit):{ url: string, options: RequestOptionsInit } => {
return {
// 前缀如果已经带上api, 跳过自动补前缀
url: url.startsWith('/api') ? url : basePrefix + url,
options,
};
});
// 响应拦截器
baseRequest.interceptors.response.use((response: Response, options: RequestOptionsInit) => {
return response;
});
export default request;
\ No newline at end of file
// 请求中间件
baseRequest.use(async (ctx: Context, next: () => void) => {
await next()
})
/**
* 公共请求层
*/
class ApiRequest {
createRequest <T>(url: string, options: IApiRequest = { ctlType: 'none' }): Promise<IRequestSuccess<T>> {
return new Promise((resolve, reject) => {
baseRequest<IRequestSuccess<T>>(url, options).then(res => {
if (res.code === 1000) {
options.ctlType === 'message' && message.success(res.message)
}
resolve(res)
}).catch((err: IRequestError) => {
// http错误处理, 直接透传
reject(err)
})
})
}
}
export default new ApiRequest().createRequest;
\ No newline at end of file
export function isString(str):str is string {
export function isString(str: any):str is string {
return typeof str === 'string'
}
\ No newline at end of file
......@@ -6,7 +6,6 @@
"moduleResolution": "node",
"importHelpers": true,
"jsx": "react",
"noImplicitAny": false,
"esModuleInterop": true,
"sourceMap": true,
"baseUrl": "./",
......
declare module '*.css';
declare module '*.less';
declare module "*.png";
declare module "classnames";
declare module '*.svg' {
export function ReactComponent(props: React.SVGProps<SVGSVGElement>): React.ReactElement
const url: string
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment