1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- export const simpleRequired = (message = '请输入') => {
- return {
- required: true,
- message,
- transform(value) {
- if(null === value || undefined === value || '' === value) return value
- return value + '';
- },
- trigger: ['blur', 'change'],
- }
- }
- export const arrayRequired = (message = '必须项') => {
- return {
- required: true,
- message,
- transform(arr) {
- console.log('rrrrr',arr);
- if(null === arr || undefined === arr || '' === arr) return arr
- if(arr.length <= 0) return null
- return arr.toString()
- },
- trigger: ['blur', 'change'],
- }
- }
- export const defaultRequired = {
- required: true,
- message: '请输入',
- transform(value) {
- if(null === value || undefined === value || '' === value) return value
- return value + '';
- },
- trigger: ['blur', 'change'],
- }
- export const carNoRule = {
- min: 5,
- max: 8,
- message: '请输入正确的车牌号',
- }
- export const mobileRule = {
- pattern: /^1[3-9]\d{9}$/,
- transform(value) {
- return String(value);
- },
- message: '请输入正确的手机号',
- }
- export const idRule = {
- pattern: /^[1-9]\d{5}(18|19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}(\d|X|x)$/,
- transform(value) {
- return String(value);
- },
- message: '请输入正确的证件号',
- }
- export const mkRules = (fields, fun = simpleRequired) => {
- const ret = {}
- fields.forEach(d => {
- ret[d] = [fun()]
- })
- return ret
- }
|