Skip to content

Commit 6a0caee

Browse files
author
sunshine824
committed
添加工具库
1 parent 2a2394f commit 6a0caee

File tree

3 files changed

+157
-24
lines changed

3 files changed

+157
-24
lines changed

src/types/interfaces.d.ts

+64-24
Original file line numberDiff line numberDiff line change
@@ -8,47 +8,87 @@
88
declare namespace StoreState {
99
// 接口返回结构
1010
export interface Result {
11-
code: number;
12-
data: any;
13-
status: boolean;
14-
msg: string;
11+
code: number
12+
data: any
13+
status: boolean
14+
msg: string
1515
}
1616

1717
// 请求参数结构
1818
export interface FetchParams {
19-
url: string;
20-
data: object | string;
21-
[propName: string]: any;
19+
url: string
20+
data: object | string
21+
[propName: string]: any
2222
}
2323

2424
// 权限返回实体
2525
export interface Role {
26-
icon?: string;
27-
list?: Role[];
28-
menuId?: number;
29-
name: string;
30-
perms?: string;
31-
requestPath?: string;
32-
url: string;
33-
[propName: string]: any;
26+
icon?: string
27+
list?: Role[]
28+
menuId?: number
29+
name: string
30+
perms?: string
31+
requestPath?: string
32+
url: string
33+
[propName: string]: any
3434
}
3535

3636
// layout布局
3737
export interface Layout {
3838
labelCol: {
39-
span: number;
40-
};
39+
span: number
40+
}
4141
wrapperCol: {
42-
span: number;
43-
};
42+
span: number
43+
}
4444
}
4545

4646
// 分页参数
4747
export interface Pagination {
48-
current?: number;
49-
position?: string;
50-
pageSize?: number;
51-
total?: number;
52-
showTotal?: (total: number, range: [number, number]) => any;
48+
current?: number
49+
position?: string
50+
pageSize?: number
51+
total?: number
52+
showQuickJumper?: boolean
53+
showTotal?: (total: number, range: [number, number]) => any
54+
}
55+
56+
// 上传文件
57+
export interface FileItem {
58+
uid: string
59+
name?: string
60+
status?: string
61+
response?: string
62+
url?: string
63+
type?: string
64+
size: number
65+
originFileObj: any
66+
}
67+
68+
export interface FileInfo {
69+
file: FileItem
70+
fileList: FileItem[]
71+
}
72+
73+
// 资源类型
74+
export interface ResourceTypes {
75+
'1': string
76+
'2': string
77+
'3': string
78+
[key: string]: string
79+
}
80+
81+
// 列表mixin
82+
export interface TableMixinOptions {
83+
queryTableApi: ({}) => any
84+
deleteApi: ({}) => any
85+
}
86+
87+
// 列表查询参数
88+
export interface TableQueryOptions {
89+
orgId?: string
90+
pageNo: number
91+
pageSize: number
92+
[propName: string]: any
5393
}
5494
}

src/utils/const.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// 定义分页类
2+
export class Pagination {
3+
private Page: StoreState.Pagination = {
4+
position: 'bottom',
5+
showQuickJumper: true,
6+
current: 1,
7+
pageSize: 10,
8+
total: 0,
9+
showTotal: (total: number) => `总 ${total} 条`,
10+
}
11+
12+
constructor(params?: StoreState.Pagination) {
13+
Object.assign(this.Page, params)
14+
}
15+
16+
init() {
17+
return this.Page
18+
}
19+
}
20+
21+
// modal公共属性
22+
export const modalProps = {
23+
maskClosable: false,
24+
}

src/utils/validate.ts

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* @Description: 验证库
3+
* @Author: chenxin
4+
* @Date: 2020-09-28 16:13:12
5+
* @LastEditors: Please set LastEditors
6+
* @LastEditTime: 2020-11-16 23:18:30
7+
*/
8+
9+
// 手机号验证
10+
export const validateMobile = (value: string) =>
11+
/^[1][3,4,5,7,8,9][0-9]{9}$/.test(value)
12+
13+
// 身份证验证
14+
export const validateCard = (value: string) =>
15+
/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(value)
16+
17+
// 验证年龄
18+
export const validateAge = (value: string) =>
19+
/^(([0-9]|[1-9][1-9]|1[0-7][0-9])(\\.[0-9]+)?|180)$/.test(value)
20+
21+
// 微信号验证
22+
export const validatWeChat = (value: string) =>
23+
/^[a-zA-Z][a-zA-Z\d_-]{5,19}$/.test(value)
24+
25+
// 中文验证
26+
export const validateEnName = (value: string) =>
27+
/^[\u4e00-\u9fa5]{0,10}$/.test(value)
28+
29+
// 验证IP
30+
export const validateIP = (value: string) =>
31+
/^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$/.test(
32+
value,
33+
)
34+
35+
// 验证端口 为正整数,值范围1-65535
36+
export const validatePort = (value: string) =>
37+
/(^[1-9]\d{0,3}$)|(^[1-5]\d{4}$)|(^6[0-4]\d{3}$)|(^65[0-4]\d{2}$)|(^655[0-2]\d$)|(^6553[0-5]$)/.test(
38+
value,
39+
)
40+
41+
// 服务地址限定条件 英文、数字、:、/、.、@、_、#、*,长度为1-256
42+
export const validateAddress = (value: string) =>
43+
/^[A-Za-z0-9:/@._#*]{1,256}$/.test(value)
44+
45+
// 验证1到99999999正整数
46+
export const validateRate = (value: string) => /^[1-9][0-9]{0,7}$/.test(value)
47+
48+
// 经度验证
49+
export const validateLon = (value: string) =>
50+
/^[\-\+]?(0(\.\d{1,10})?|([1-9](\d)?)(\.\d{1,10})?|1[0-7]\d{1}(\.\d{1,10})?|180\.0{1,10})$/.test(
51+
value,
52+
)
53+
54+
// 纬度验证
55+
export const validateLat = (value: string) =>
56+
/^[\-\+]?((0|([1-8]\d?))(\.\d{1,10})?|90(\.0{1,10})?)$/.test(value)
57+
58+
// 邮箱验证
59+
export const validateEmail = (value: string) =>
60+
/^[A-Za-z0-9]+([_\.][A-Za-z0-9]+)*@([A-Za-z0-9\-]+\.)+[A-Za-z]{2,6}$/.test(
61+
value,
62+
)
63+
64+
// 正整数
65+
export const validatePort100 = (value: string) => /^[1-9]\d*$/.test(value)
66+
67+
// 非英文数字验证
68+
export const validateNotEnglishAndNumbers = (value: string) =>
69+
/^[^\d]*$|^[^a-zA-Z]*$|[^\da-zA-Z]/.test(value)

0 commit comments

Comments
 (0)