el-plus-crud 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/.eslintignore +18 -0
  2. package/.eslintrc.js +78 -0
  3. package/.lintstagedrc +3 -0
  4. package/.prettierrc.js +39 -0
  5. package/CHANGELOG.md +5 -0
  6. package/LICENSE +21 -0
  7. package/README.md +15 -0
  8. package/example/App.vue +79 -0
  9. package/example/assets/vue.svg +1 -0
  10. package/example/main.js +18 -0
  11. package/example/style.css +5 -0
  12. package/index.html +13 -0
  13. package/lib/components/el-plus-form/ElPlusForm.vue +744 -0
  14. package/lib/components/el-plus-form/ElPlusFormDialog.vue +107 -0
  15. package/lib/components/el-plus-form/components/ElPlusFormAutocomplete.vue +49 -0
  16. package/lib/components/el-plus-form/components/ElPlusFormBtn.vue +96 -0
  17. package/lib/components/el-plus-form/components/ElPlusFormBtns.vue +133 -0
  18. package/lib/components/el-plus-form/components/ElPlusFormCascader.vue +38 -0
  19. package/lib/components/el-plus-form/components/ElPlusFormCascaderPanel.vue +51 -0
  20. package/lib/components/el-plus-form/components/ElPlusFormCheckbox.vue +42 -0
  21. package/lib/components/el-plus-form/components/ElPlusFormCheckboxButton.vue +42 -0
  22. package/lib/components/el-plus-form/components/ElPlusFormColor.vue +38 -0
  23. package/lib/components/el-plus-form/components/ElPlusFormDate.vue +37 -0
  24. package/lib/components/el-plus-form/components/ElPlusFormDaterange.vue +44 -0
  25. package/lib/components/el-plus-form/components/ElPlusFormDatetime.vue +38 -0
  26. package/lib/components/el-plus-form/components/ElPlusFormFile.vue +47 -0
  27. package/lib/components/el-plus-form/components/ElPlusFormImage.vue +113 -0
  28. package/lib/components/el-plus-form/components/ElPlusFormInput.vue +56 -0
  29. package/lib/components/el-plus-form/components/ElPlusFormLink.vue +271 -0
  30. package/lib/components/el-plus-form/components/ElPlusFormNbinput.vue +51 -0
  31. package/lib/components/el-plus-form/components/ElPlusFormNumber.vue +107 -0
  32. package/lib/components/el-plus-form/components/ElPlusFormPassword.vue +39 -0
  33. package/lib/components/el-plus-form/components/ElPlusFormRadio.vue +42 -0
  34. package/lib/components/el-plus-form/components/ElPlusFormRate.vue +38 -0
  35. package/lib/components/el-plus-form/components/ElPlusFormSelect.vue +149 -0
  36. package/lib/components/el-plus-form/components/ElPlusFormSlider.vue +38 -0
  37. package/lib/components/el-plus-form/components/ElPlusFormStatus.vue +67 -0
  38. package/lib/components/el-plus-form/components/ElPlusFormSwitch.vue +38 -0
  39. package/lib/components/el-plus-form/components/ElPlusFormTag.vue +78 -0
  40. package/lib/components/el-plus-form/components/ElPlusFormText.vue +115 -0
  41. package/lib/components/el-plus-form/components/ElPlusFormTextarea.vue +45 -0
  42. package/lib/components/el-plus-form/components/ElPlusFormTransfer.vue +44 -0
  43. package/lib/components/el-plus-form/components/ElPlusFormTree.vue +53 -0
  44. package/lib/components/el-plus-form/components/ElPlusFormTreeSelect.vue +36 -0
  45. package/lib/components/el-plus-form/components/components/IconSelectorList.vue +92 -0
  46. package/lib/components/el-plus-form/components/components/file-icons/FileIcons.vue +135 -0
  47. package/lib/components/el-plus-form/components/components/file-icons/data/index.ts +27 -0
  48. package/lib/components/el-plus-form/components/components/file-icons/images/doc.svg +13 -0
  49. package/lib/components/el-plus-form/components/components/file-icons/images/file.svg +19 -0
  50. package/lib/components/el-plus-form/components/components/file-icons/images/jpg.svg +14 -0
  51. package/lib/components/el-plus-form/components/components/file-icons/images/pdf.svg +13 -0
  52. package/lib/components/el-plus-form/components/components/file-icons/images/png.svg +13 -0
  53. package/lib/components/el-plus-form/components/components/file-icons/images/ppt.svg +13 -0
  54. package/lib/components/el-plus-form/components/components/file-icons/images/xls.svg +13 -0
  55. package/lib/components/el-plus-form/components/index.ts +17 -0
  56. package/lib/components/el-plus-form/data/file.ts +74 -0
  57. package/lib/components/el-plus-form/images/icon/excel.png +0 -0
  58. package/lib/components/el-plus-form/images/icon/file.png +0 -0
  59. package/lib/components/el-plus-form/images/icon/pdf.png +0 -0
  60. package/lib/components/el-plus-form/images/icon/ppt.png +0 -0
  61. package/lib/components/el-plus-form/images/icon/txt.png +0 -0
  62. package/lib/components/el-plus-form/images/icon/word.png +0 -0
  63. package/lib/components/el-plus-form/images/icon/zip.png +0 -0
  64. package/lib/components/el-plus-form/mixins/index.ts +113 -0
  65. package/lib/components/el-plus-form/util/index.ts +266 -0
  66. package/lib/components/el-plus-form/util/validate.ts +310 -0
  67. package/lib/components/el-plus-table/ElPlusTable.vue +723 -0
  68. package/lib/components/el-plus-table/components/columnItem.vue +185 -0
  69. package/lib/components/el-plus-table/components/header.vue +185 -0
  70. package/lib/components/el-plus-table/components/settingColumn.vue +168 -0
  71. package/lib/components/el-plus-table/components/statisticInfo.vue +47 -0
  72. package/lib/components/el-plus-table/util/index.ts +123 -0
  73. package/lib/config/form.ts +12 -0
  74. package/lib/config/index.ts +9 -0
  75. package/lib/index.ts +29 -0
  76. package/package.json +65 -0
  77. package/public/vite.svg +1 -0
  78. package/tsconfig.json +68 -0
  79. package/types/axios.d.ts +13 -0
  80. package/types/formList.d.ts +365 -0
  81. package/types/global.d.ts +145 -0
  82. package/types/layout.d.ts +57 -0
  83. package/types/mitt.d.ts +38 -0
  84. package/types/pinia.d.ts +149 -0
  85. package/types/views.d.ts +329 -0
  86. package/vite.config.ts +68 -0
@@ -0,0 +1,113 @@
1
+ export interface IMixinsProps {
2
+ modelValue?: any
3
+ field: string
4
+ rowIndex?: number
5
+ loading?: boolean
6
+ desc: { [key: string]: any }
7
+ formData: { [key: string]: any }
8
+ isMobile?: boolean
9
+ defineEmits?: any
10
+ }
11
+
12
+ /**
13
+ * 获取属性
14
+ * @param props
15
+ * @param customAttrs
16
+ * @returns
17
+ */
18
+ export const getAttrs = async (props: IMixinsProps, customAttrs?: { [key: string]: any }) => {
19
+ // 合并属性
20
+ const attrs = Object.assign({}, customAttrs, props.desc?._attrs, props.desc?.attrs, getPlaceholder(props.desc))
21
+
22
+ // 处理多选
23
+ if (props.desc.multiple) {
24
+ attrs.multiple = true
25
+ attrs.showCheckbox = true
26
+ if (['select'].indexOf(props.desc.type) >= 0) {
27
+ attrs.collapseTags = props.desc.attrs?.collapseTags ?? false
28
+ attrs.collapseTagsTooltip = props.desc.attrs?.collapseTagsTooltip ?? false
29
+ }
30
+ }
31
+
32
+ // if (['area'].indexOf(props.desc.type) >= 0) {
33
+ // delete attrs.options
34
+ // }
35
+
36
+ // 处理下elType
37
+ if (props.desc.elType) {
38
+ if (typeof props.desc.elType === 'function') {
39
+ attrs.type = props.desc.elType(props.formData)
40
+ } else {
41
+ attrs.type = props.desc.elType
42
+ }
43
+ }
44
+ return attrs
45
+ }
46
+
47
+ /**
48
+ * 获取事件
49
+ * @returns
50
+ */
51
+ export const getEvents = (props: IMixinsProps) => {
52
+ const tempOn = {} as any
53
+ if (props.desc?.on) {
54
+ Object.keys(props.desc.on).map((key: string) => {
55
+ tempOn[key] = (val: any) => {
56
+ props.desc.on[key](props.formData, props.rowIndex, val)
57
+ }
58
+ })
59
+ }
60
+ return tempOn
61
+ }
62
+
63
+ /**
64
+ * 根据类型获取属性 placeholder
65
+ * @param desc
66
+ * @returns
67
+ */
68
+ function getPlaceholder(desc: { [key: string]: any }) {
69
+ if (!desc || !desc.type) return ''
70
+ switch (desc.type) {
71
+ case 'input':
72
+ case 'nbinput':
73
+ case 'password':
74
+ case 'number':
75
+ case 'validCode':
76
+ case 'tag':
77
+ return { placeholder: desc?.placeholder || '请输入' + desc?._label }
78
+ case 'switch':
79
+ return {}
80
+ case 'area':
81
+ case 'select':
82
+ case 'category':
83
+ case 'cascader':
84
+ return { placeholder: desc?.placeholder || '请选择' + (desc.remote ? (desc.initLoad !== false ? '(默认查10个,其余请输入搜索)' : '或输入进行搜索') : desc?._label) }
85
+ case 'data':
86
+ case 'datetime':
87
+ case 'datas':
88
+ return { placeholder: '选择日期' }
89
+ case 'daterange':
90
+ case 'datetimerange':
91
+ case 'timerange':
92
+ case 'monthrange':
93
+ return {
94
+ startPlaceholder: '开始日期',
95
+ endPlaceholder: '结束日期'
96
+ }
97
+ case 'dates':
98
+ return { placeholder: '选择一个或多个日期' }
99
+ case 'month':
100
+ return { placeholder: '选择月' }
101
+ case 'time':
102
+ case 'timsPicker':
103
+ return { placeholder: '请选择时间' }
104
+ case 'week':
105
+ return { placeholder: '请选择周' }
106
+ case 'year':
107
+ return { placeholder: '请选择年' }
108
+ case 'upimg':
109
+ return { placeholder: '请上传' }
110
+ case 'upfile':
111
+ return { placeholder: '点击上传' }
112
+ }
113
+ }
@@ -0,0 +1,266 @@
1
+ // 是否定义
2
+ export function isDef(val: any) {
3
+ return !isUnDef(val)
4
+ }
5
+
6
+ // 是否没定义
7
+ export function isUnDef(val: any) {
8
+ return val === null || val === undefined
9
+ }
10
+
11
+ // 判断是否为函数
12
+ export function isFunction(val: any) {
13
+ return typeof val === 'function'
14
+ }
15
+
16
+ /**
17
+ * 获取随机字符串
18
+ * @returns {string}
19
+ */
20
+ export function getUID(): string {
21
+ let str = ''
22
+ const arr = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('')
23
+ for (let i = 0; i < 32; i++) {
24
+ let index = Math.floor(arr.length * Math.random())
25
+ if (index < 0) index = 0
26
+ str += arr[index]
27
+ }
28
+ return str
29
+ }
30
+
31
+ /**
32
+ * 判断是否是移动端
33
+ */
34
+ export function isMobile() {
35
+ if (navigator.userAgent.match(/('phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone')/i)) {
36
+ return true
37
+ } else {
38
+ return false
39
+ }
40
+ }
41
+
42
+ // 判断类型
43
+ export function is(val: any, type: any) {
44
+ const typeArr = Array.isArray(type) ? type : [type]
45
+ const valType = Object.prototype.toString.call(val)
46
+ return typeArr.some((type) => `[object ${type}]` === valType)
47
+ }
48
+
49
+ // 获取 display: none 的节点宽度和高度
50
+ export function getSize(elem: any) {
51
+ const noneNodes: any[] = []
52
+ const nodeStyle: any[] = []
53
+
54
+ getNoneNode(elem) // 获取多层display:none;的元素
55
+ setNodeStyle()
56
+ const width = elem.clientWidth
57
+ const height = elem.clientHeight
58
+ resumeNodeStyle()
59
+
60
+ return {
61
+ width: width,
62
+ height: height
63
+ }
64
+
65
+ function getNoneNode(node: any) {
66
+ const display = getStyles(node).getPropertyValue('display')
67
+ const tagName = node.nodeName.toLowerCase()
68
+ if (display !== 'none' && tagName !== 'body') {
69
+ getNoneNode(node.parentNode)
70
+ } else {
71
+ noneNodes.push(node)
72
+ if (tagName !== 'body') getNoneNode(node.parentNode)
73
+ }
74
+ }
75
+
76
+ // 这方法才能获取最终是否有display属性设置,不能style.display。
77
+ function getStyles(elem: any) {
78
+ // Support: IE<=11+, Firefox<=30+ (#15098, #14150)
79
+ // IE throws on elements created in popups
80
+ // FF meanwhile throws on frame elements through "defaultView.getComputedStyle"
81
+ let view = elem.ownerDocument.defaultView
82
+
83
+ if (!view || !view.opener) {
84
+ view = window
85
+ }
86
+ return view.getComputedStyle(elem)
87
+ }
88
+
89
+ function setNodeStyle() {
90
+ let i = 0
91
+ for (; i < noneNodes.length; i++) {
92
+ const visibility = noneNodes[i].style.visibility
93
+ const display = noneNodes[i].style.display
94
+ const style = noneNodes[i].getAttribute('style')
95
+ // 覆盖其他display样式
96
+ noneNodes[i].setAttribute('style', 'visibility:hidden;display:block !important;' + style)
97
+ nodeStyle[i] = {
98
+ visibility: visibility,
99
+ display: display
100
+ }
101
+ }
102
+ }
103
+
104
+ function resumeNodeStyle() {
105
+ let i = 0
106
+ for (; i < noneNodes.length; i++) {
107
+ noneNodes[i].style.visibility = nodeStyle[i].visibility
108
+ noneNodes[i].style.display = nodeStyle[i].display
109
+ }
110
+ }
111
+ }
112
+
113
+ // 如果 value 不是数组, 那么强制转为数组
114
+ // 空转为空数组 undefined | null | '' => []
115
+ // 1 => [1], false => [false], {} => [{}]
116
+ export function castArray(value: any) {
117
+ if (Array.isArray(value)) {
118
+ return value
119
+ } else if (value === undefined || value === null || value === '') {
120
+ return []
121
+ } else {
122
+ return value.split(',')
123
+ }
124
+ }
125
+ // 数据转移为cascade的category
126
+ export function castCategory(value: any, formData: any) {
127
+ if (Array.isArray(value)) {
128
+ return value
129
+ } else {
130
+ const tempList = []
131
+ if (formData.categoryId1) tempList.push(formData.categoryId1)
132
+ if (formData.categoryId2) tempList.push(formData.categoryId2)
133
+ if (formData.categoryId3) tempList.push(formData.categoryId3)
134
+ return tempList
135
+ }
136
+ }
137
+ // 如果 value 不是数组, 那么强制转为数组
138
+ export function castFileList(value: any) {
139
+ if (Array.isArray(value)) {
140
+ return value
141
+ } else if (value === undefined || value === null || value === '') {
142
+ return []
143
+ } else {
144
+ return value.split(',')
145
+ }
146
+ }
147
+ // 如果 value 不是字符串, 那么强制转为字符串
148
+ export function castString(value: any) {
149
+ if (typeof value === 'string') {
150
+ return value
151
+ } else if (value === undefined || value === null) {
152
+ return ''
153
+ } else if (value.toString) {
154
+ return value.toString()
155
+ } else {
156
+ return value + ''
157
+ }
158
+ }
159
+ // 如果 value 不是Boolean, 那么强制转为Boolean
160
+ export function castBoolean(value: any) {
161
+ if (typeof value === 'boolean') {
162
+ return value
163
+ } else {
164
+ return Boolean(value)
165
+ }
166
+ }
167
+ // 如果 value 不是Number, 那么强制转为Number
168
+ export function castNumber(value: any): number {
169
+ if (typeof value === 'number') {
170
+ return value
171
+ } else {
172
+ return Number(value) || 0
173
+ }
174
+ }
175
+
176
+ // 判断是否为空
177
+ // 空数组 / null / undefined / 空字符串
178
+ export function isEmpty(val: any) {
179
+ if (Array.isArray(val) && val.length === 0) {
180
+ return true
181
+ } else if (isUnDef(val)) {
182
+ return true
183
+ } else if (typeof val === 'string' && val === '') {
184
+ return true
185
+ } else {
186
+ return false
187
+ }
188
+ }
189
+
190
+ /**
191
+ * 格式化表单字段
192
+ * @param formData
193
+ * @param formDesc
194
+ */
195
+ export function valueFormat(formData: any, formDesc: any) {
196
+ for (const field in formData) {
197
+ const formItem = formDesc[field]
198
+ if (formItem && formItem.valueFormat) {
199
+ if (typeof formItem.valueFormat === 'function') {
200
+ formData[field] = formItem.valueFormat(formData[field], formData)
201
+ }
202
+ switch (formItem.valueFormat) {
203
+ case 'arrayToStr':
204
+ formData[field] = arrayToStr(formData[field])
205
+ break
206
+ default:
207
+ throw Error('无效的 valueFormat 类型')
208
+ }
209
+ }
210
+ }
211
+ }
212
+
213
+ /**
214
+ *
215
+ * @param val 数组转字符串
216
+ */
217
+ export function arrayToStr(val: any) {
218
+ if (Array.isArray(val)) {
219
+ return val.join(',')
220
+ } else {
221
+ return val + ''
222
+ }
223
+ }
224
+
225
+ // 默认起止时间
226
+ const maxMinTime = new Date('2010-01-01 00:00:00')
227
+ const maxMaxTime = new Date('2040-01-01 00:00:00')
228
+
229
+ /**
230
+ * 获取可用的时间
231
+ */
232
+ export const getEnabledDate = (date: Date, startTime: number, endTime: number) => {}
233
+
234
+ /**
235
+ * 裁剪长度
236
+ * @param str
237
+ * @param len
238
+ * @param isTransHz 是否转换汉字长度为2个英文字母长度
239
+ */
240
+ export const cutString = (str: string = '', len: number, isTransHz: boolean = false) => {
241
+ if (!str) return ''
242
+ const length = isTransHz ? getStrLength(str) : str.length
243
+ if (length > len) {
244
+ return str.substring(0, len - 2) + '...' + str.substring(len - 2, len)
245
+ }
246
+ return str
247
+ }
248
+
249
+ /**
250
+ * 获取字符串长度
251
+ * @type {(p1?:*)}
252
+ */
253
+ export const getStrLength = (str: any) => {
254
+ // <summary>获得字符串实际长度,中文2,英文1</summary>
255
+ // <param name='str'>要获得长度的字符串</param>
256
+ if (!str) return 0
257
+ let realLength = 0
258
+ const len = str.length
259
+ let charCode = -1
260
+ for (let i = 0; i < len; i++) {
261
+ charCode = str.charCodeAt(i)
262
+ if (charCode >= 0 && charCode <= 128) realLength += 1
263
+ else realLength += 2
264
+ }
265
+ return realLength
266
+ }
@@ -0,0 +1,310 @@
1
+ /**
2
+ * 获取通用的校验规则
3
+ */
4
+
5
+ /**
6
+ * 不能为空
7
+ */
8
+ export const notNull = [{ required: true, trigger: 'blur', validator: validateInputNotNull }]
9
+
10
+ /**
11
+ * 不能全是空格
12
+ */
13
+ export const notAllBlank = [{ required: true, trigger: 'blur', validator: validateInputNotAllBlank }]
14
+
15
+ /**
16
+ * 必须是数字
17
+ */
18
+ export const number = [{ type: 'number', message: '请填入数字!' }]
19
+
20
+ /**
21
+ * 校验验证码
22
+ */
23
+ export const vCode = [{ required: true, trigger: 'blur', validator: validateValidateCode }]
24
+
25
+ /**
26
+ * 校验邮箱
27
+ */
28
+ export const email = [{ trigger: 'blur', validator: validateEmail }]
29
+
30
+ /**
31
+ * 校验手机号
32
+ */
33
+ export const phone = [{ required: true, trigger: 'blur', validator: validatePhone }]
34
+
35
+ /**
36
+ * 校验密码
37
+ */
38
+ export const password = [{ required: true, trigger: 'blur', validator: validatePassword }]
39
+
40
+ /**
41
+ * 校验密码
42
+ */
43
+ export const password2 = [{ trigger: 'blur', validator: validatePassword }]
44
+
45
+ /**
46
+ * 校验账户
47
+ */
48
+ export const account = [{ required: true, trigger: 'blur', validator: validateAccount }]
49
+
50
+ /**
51
+ * 校验英文字母加数字
52
+ */
53
+ export const wordnum = [{ trigger: 'blur', validator: validateWordNumber }]
54
+ export const wordnum2 = [{ required: true, trigger: 'blur', validator: validateWordNumber }]
55
+
56
+ /**
57
+ * 必须是数字且不为空
58
+ */
59
+ export const numberNotNull = [
60
+ { required: true, message: '不能为空!', trigger: 'blur' },
61
+ { type: 'number', message: '请填入数字!' }
62
+ ]
63
+
64
+ /**
65
+ * 正整数
66
+ */
67
+ export const zhengZhengShu = [{ required: true, trigger: 'blur', validator: validateZhengZhengShu }]
68
+
69
+ /**
70
+ * Double类型
71
+ */
72
+ export const double = [{ required: true, trigger: 'blur', validator: validateDouble }]
73
+ /**
74
+ * Double类型且必填
75
+ */
76
+ export const double2 = [{ trigger: 'blur', validator: validateDouble }]
77
+
78
+ /**
79
+ * 选择
80
+ */
81
+ export const select = [{ required: true, trigger: 'change', validator: validateSelect }]
82
+
83
+ /**
84
+ * 级联选择
85
+ * @type {[*]}
86
+ */
87
+ export const cascader = [{ required: true, trigger: 'change', validator: validateSelect }]
88
+
89
+ /**
90
+ * 必须上传
91
+ */
92
+ export const upload = [{ required: true, trigger: 'change', validator: validateUpload }]
93
+
94
+ /**
95
+ * 文本域
96
+ */
97
+ export const textarea = [{ required: true, trigger: 'change', validator: validateTextarea }]
98
+
99
+ /**
100
+ * 正整数校验
101
+ * @param rule
102
+ * @param value
103
+ * @param callback
104
+ */
105
+ function validateZhengZhengShu(rule: any, value: any, callback?: any) {
106
+ if (!/^[1-9]\d*$/.test(value * 1 + '')) {
107
+ callback(new Error('请输入正整数!'))
108
+ } else {
109
+ callback()
110
+ }
111
+ }
112
+
113
+ /**
114
+ * 选择
115
+ * @param rule
116
+ * @param value
117
+ * @param callback
118
+ */
119
+ function validateValidateCode(rule: any, value: any, callback?: any) {
120
+ if (value.length !== 4) {
121
+ callback(new Error('验证码必须是4位!'))
122
+ } else {
123
+ callback()
124
+ }
125
+ }
126
+
127
+ /**
128
+ * 选择
129
+ * @param rule
130
+ * @param value
131
+ * @param callback
132
+ */
133
+ function validateInputNotNull(rule: any, value: any, callback?: any) {
134
+ if (typeof value === 'undefined' || value === '' || value === null) {
135
+ callback(new Error('此项必填!'))
136
+ } else {
137
+ callback()
138
+ }
139
+ }
140
+
141
+ /**
142
+ * 不能全是空格
143
+ * @param rule
144
+ * @param value
145
+ * @param callback
146
+ */
147
+ function validateInputNotAllBlank(rule: any, value: any, callback?: any) {
148
+ if (typeof value === 'undefined' || value === '' || value === null) {
149
+ callback(new Error('此项必填!'))
150
+ } else {
151
+ if (typeof value === 'number') {
152
+ value = value + ''
153
+ }
154
+ if (typeof value === 'string' && value.match(/^[ ]*$/)) {
155
+ callback(new Error('不能全是空格!'))
156
+ } else {
157
+ callback()
158
+ }
159
+ }
160
+ }
161
+
162
+ /**
163
+ * 选择
164
+ * @param rule
165
+ * @param value
166
+ * @param callback
167
+ */
168
+ function validateSelect(rule: any, value: any, callback?: any) {
169
+ if (value === null || typeof value === 'undefined' || value === '' || value.length <= 0) {
170
+ callback(new Error('请选择!'))
171
+ } else {
172
+ callback()
173
+ }
174
+ }
175
+
176
+ /**
177
+ * 上传
178
+ * @param rule
179
+ * @param value
180
+ * @param callback
181
+ */
182
+ function validateUpload(rule: any, value: any, callback?: any) {
183
+ if (value === null || typeof value === 'undefined' || value === '' || value.length <= 0) {
184
+ callback(new Error('请上传!'))
185
+ } else {
186
+ callback()
187
+ }
188
+ }
189
+
190
+ /**
191
+ * 文本域
192
+ * @param rule
193
+ * @param value
194
+ * @param callback
195
+ */
196
+ function validateTextarea(rule: any, value: any, callback?: any) {
197
+ if (typeof value === 'undefined' || value === '' || value === null) {
198
+ callback(new Error('此项必填!'))
199
+ } else if (!value.replace(/\n/g, '')) {
200
+ callback(new Error('不能全是换行!'))
201
+ } else if (typeof value === 'string' && value.replace(/\n/g, '').match(/^[ ]*$/)) {
202
+ callback(new Error('不能全是空格!'))
203
+ } else {
204
+ callback()
205
+ }
206
+ }
207
+
208
+ /**
209
+ * 小数校验规则
210
+ * @param rule
211
+ * @param value
212
+ * @param callback
213
+ */
214
+ function validateDouble(rule: any, value: any, callback?: any) {
215
+ if (!/^\d+(\.(\d{1}|\d{2}))?$/.test(value * 1 + '')) {
216
+ callback(new Error('小数格式错误(最多两位)!'))
217
+ } else {
218
+ callback()
219
+ }
220
+ }
221
+
222
+ /**
223
+ * 校验邮箱
224
+ * @param rule
225
+ * @param value
226
+ * @param callback
227
+ */
228
+ function validateEmail(rule: any, value: any, callback?: any) {
229
+ if (!value) {
230
+ callback(new Error('邮箱必填'))
231
+ } else if (!/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(value)) {
232
+ callback(new Error('邮箱格式错误!'))
233
+ } else {
234
+ callback()
235
+ }
236
+ }
237
+
238
+ /**
239
+ * 校验手机号
240
+ * @param rule
241
+ * @param value
242
+ * @param callback
243
+ */
244
+ function validatePhone(rule: any, value: any, callback?: any) {
245
+ if (!value) {
246
+ callback(new Error('手机号必填'))
247
+ } else if (!/^[1][3,4,5,6,7,8,9][0-9]{9}$/.test(value)) {
248
+ callback(new Error('手机号格式错误!'))
249
+ } else {
250
+ callback()
251
+ }
252
+ }
253
+
254
+ /**
255
+ * 校验密码
256
+ * @param rule
257
+ * @param value
258
+ * @param callback
259
+ */
260
+ export function validatePassword(rule: any, value: any, callback?: any) {
261
+ if (!value || !/^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_]+$)(?![a-z0-9]+$)(?![a-z\W_]+$)(?=.*[~!@#$%^&*])(?![0-9\W_]+$)[a-zA-Z0-9\W_]{8,32}$/.test(value)) {
262
+ callback(new Error('密码为8-32位字母大小写+特殊字符+数字!'))
263
+ } else {
264
+ callback()
265
+ }
266
+ }
267
+
268
+ /**
269
+ * 校验密码
270
+ * @param rule
271
+ * @param value
272
+ * @param callback
273
+ */
274
+ export function validatePassword2(rule: any, value: any, callback?: any) {
275
+ if (value && !/^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_]+$)(?![a-z0-9]+$)(?![a-z\W_]+$)(?=.*[~!@#$%^&*])(?![0-9\W_]+$)[a-zA-Z0-9\W_]{8,32}$/.test(value)) {
276
+ callback(new Error('密码为8-32位字母大小写+特殊字符+数字!'))
277
+ } else {
278
+ callback()
279
+ }
280
+ }
281
+
282
+ /**
283
+ * 校验账户
284
+ * @param rule
285
+ * @param value
286
+ * @param callback
287
+ */
288
+ function validateAccount(rule: any, value: any, callback?: any) {
289
+ if (typeof value === 'undefined' || value === '' || value === null) {
290
+ callback(new Error('此项必填!'))
291
+ } else if (value && !/^([a-z,A-z,0-9]){4,20}$/.test(value)) {
292
+ callback(new Error('账号为4-20位字母或数字!'))
293
+ } else {
294
+ callback()
295
+ }
296
+ }
297
+
298
+ /**
299
+ * 校验字母和数字组成
300
+ * @param rule
301
+ * @param value
302
+ * @param callback
303
+ */
304
+ function validateWordNumber(rule: any, value: any, callback?: any) {
305
+ if (value && !/^([a-z,A-z,0-9]){16,20}$/.test(value)) {
306
+ callback(new Error('请输入16-20位字母或数字!'))
307
+ } else {
308
+ callback()
309
+ }
310
+ }