瀏覽代碼

'添加手机号校验函数和密验证函数'

main
郑州 3 年之前
父節點
當前提交
f9e495931f
共有 1 個檔案被更改,包括 43 行新增18 行删除
  1. +43
    -18
      src/utils/tool.ts

+ 43
- 18
src/utils/tool.ts 查看文件

@@ -1,54 +1,79 @@
export function firstCharToLowerCase(obj: any) {
return Object.entries(obj).reduce((o: { [key: string]: any }, [key, value]) => {
o[`${key[0].toLocaleLowerCase()}${key.slice(1)}`] = value;
return o;
},{});
return Object.entries(obj).reduce(
(o: { [key: string]: any }, [key, value]) => {
o[`${key[0].toLocaleLowerCase()}${key.slice(1)}`] = value;
return o;
},
{},
);
}

export function firstCharToUpperCase(obj) {
return Object.entries(obj).reduce((o: { [key: string]: any }, [key, value]) => {
o[`${key[0].toLocaleUpperCase()}${key.slice(1)}`] = value;
return o;
},{});
return Object.entries(obj).reduce(
(o: { [key: string]: any }, [key, value]) => {
o[`${key[0].toLocaleUpperCase()}${key.slice(1)}`] = value;
return o;
},
{},
);
}

export const isReqSuccess = (res: any) => res.code === 0 || res.Code === 0;


class RequestHandler {
constructor(public response: API.ResponseData<any>) {
this.response = response;
}
success(f: () => void) {
const res = this.response;
if (!res.success) { return this; }
if (!isReqSuccess(res)) { return this; }
if (!res.success) {
return this;
}
if (!isReqSuccess(res)) {
return this;
}
f();
return this;
}
error(f: () => void) {
const res = this.response;
if (!res.success) { return this; }
if (isReqSuccess(res)) { return this; }
if (!res.success) {
return this;
}
if (isReqSuccess(res)) {
return this;
}
f();
return this;
}
httpError(f: () => void) {
const res = this.response;
if (res.success) { return this; }
if (res.success) {
return this;
}
f();
return this;
}
}

export const handleRequest = (res: API.ResponseData<any>) => new RequestHandler(res);
export const handleRequest = (res: API.ResponseData<any>) =>
new RequestHandler(res);

export function errorReponse(message: string, code = 'err'): API.ResponseData<null> {
export function errorReponse(
message: string,
code = 'err',
): API.ResponseData<null> {
return {
code,
data: null,
success: true,
requestIsSuccess: false,
message,
}
}
};
}

export const isValidPhone = (phone: string) =>
new RegExp(/^1\d{10}$/).test(phone);
export const passwordReg = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[\S]{8,16}$/;
export const isValidPassword = (maybePassword: string) =>
new RegExp(passwordReg).test(maybePassword);

Loading…
取消
儲存