调整参数验证

This commit is contained in:
Harvey Zack committed 2018-10-30 16:28:36 +08:00
1 parent af82edb847
commit 6e4087a080
11 files changed
+365 -364

No files matched your search

+83
View File
@@ -0,0 +1,83 @@
import validElement from './validElement';
export default {
container: {
validator: validElement,
required: true
},
url: {
type: 'string',
required: true
},
volume: 'number',
thumbnails: {
type: 'object',
child: {
url: 'string',
number: 'number',
width: 'number',
height: 'number',
column: 'number'
}
},
screenshot: 'boolean',
autoplay: 'boolean',
playbackRate: 'boolean',
aspectRatio: 'boolean',
loop: 'boolean',
type: 'string',
mimeCodec: 'string',
layers: {
type: 'array',
child: {
name: 'string',
index: 'number',
html: {
validator: validElement
},
style: 'object'
}
},
contextmenu: {
type: 'array',
child: {
name: 'string',
html: {
validator: validElement
},
click: 'function'
}
},
loading: 'string',
theme: 'string',
hotkey: 'boolean',
subtitle: {
type: 'object',
child: {
url: 'string',
style: 'object'
}
},
controls: {
type: 'array',
child: {
option: {
type: 'object',
child: {
disable: 'boolean',
position: 'boolean',
index: 'number'
}
}
}
},
highlight: {
type: 'array',
child: {
time: 'number',
text: 'string'
}
},
moreVideoAttr: 'object',
lang: 'string'
};
+17
View File
@@ -0,0 +1,17 @@
import { ArtPlayerError } from '../utils';
export default function validElement(paths, value, type) {
if (type === 'string') {
if (value.trim() === '') {
throw new ArtPlayerError(`${paths.join('.')} can not be empty'`);
} else {
return true;
}
}
if (value instanceof Element) {
return true;
}
throw new ArtPlayerError(`${paths.join('.')} require 'string' or 'Element' type, but got '${type}'`);
}