mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-09 20:26:16 -08:00
update
This commit is contained in:
1 parent
c8bcec1716
commit
86e4c68391
6 files changed
+100
-30
No files matched your search
@@ -69,6 +69,9 @@ export function deepMerge(...sources) {
|
||||
}
|
||||
returnValue = [...returnValue, ...source];
|
||||
} else if (isObject(source)) {
|
||||
if (source instanceof Element) {
|
||||
return source;
|
||||
}
|
||||
for (const key in source) {
|
||||
if (source.hasOwnProperty(key)) {
|
||||
let value = source[key];
|
||||
|
||||
+19
-10
@@ -3,28 +3,37 @@ import scheme from './scheme';
|
||||
|
||||
export default function validOption(option, param = scheme, path = ['option']) {
|
||||
Object.keys(option).some(key => {
|
||||
if (!param[key]) {
|
||||
const paramObj = param[key];
|
||||
|
||||
if (!paramObj) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const value = option[key];
|
||||
const type = getType(value);
|
||||
const requiredType = param[key].type;
|
||||
const isRequired = param[key].required;
|
||||
const requiredChild = param[key].child;
|
||||
const paramType = paramObj.type;
|
||||
const paramRequired = paramObj.required;
|
||||
const paramChild = paramObj.child;
|
||||
const paramValidator = paramObj.validator;
|
||||
|
||||
if (type === 'object' && requiredChild) {
|
||||
validOption(value, requiredChild, path.concat(key));
|
||||
if (type === 'object' && paramChild) {
|
||||
validOption(value, paramChild, path.concat(key));
|
||||
}
|
||||
|
||||
if (type === 'array' && requiredChild) {
|
||||
if (type === 'array' && paramChild) {
|
||||
value.forEach((item, index) => {
|
||||
validOption(item, requiredChild, path.concat(`${key}[${index}]`));
|
||||
validOption(item, paramChild, path.concat(`${key}[${index}]`));
|
||||
});
|
||||
}
|
||||
|
||||
errorHandle(!isRequired || value, `'${path.join('.')}.${key}' is required`);
|
||||
errorHandle(requiredType === type, `'${path.join('.')}.${key}' require '${requiredType}' type, but got '${type}'`);
|
||||
if (paramValidator) {
|
||||
const result = paramValidator(key, value, type, path);
|
||||
errorHandle(result.handle, result.msg);
|
||||
} else {
|
||||
errorHandle(!paramRequired || value, `'${path.join('.')}.${key}' is required`);
|
||||
errorHandle(paramType === type, `'${path.join('.')}.${key}' require '${paramType}' type, but got '${type}'`);
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
@@ -1,7 +1,29 @@
|
||||
const validElement = (key, value, type, path) => {
|
||||
let handle = false;
|
||||
let msg = `${path.join('.')}.${key} require 'string' or 'Element' type, but got '${type}'`;
|
||||
|
||||
if (type === 'string') {
|
||||
if (type.trim() === '') {
|
||||
handle = false;
|
||||
msg = `${path.join('.')}.${key} can not be empty'`;
|
||||
} else {
|
||||
handle = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (value instanceof Element) {
|
||||
handle = true;
|
||||
}
|
||||
|
||||
return {
|
||||
handle: handle,
|
||||
msg: msg
|
||||
};
|
||||
};
|
||||
|
||||
export default {
|
||||
container: {
|
||||
type: 'string',
|
||||
required: true
|
||||
validator: validElement
|
||||
},
|
||||
url: {
|
||||
type: 'string',
|
||||
@@ -55,7 +77,7 @@ export default {
|
||||
type: 'number'
|
||||
},
|
||||
html: {
|
||||
type: 'string'
|
||||
validator: validElement
|
||||
},
|
||||
style: {
|
||||
type: 'object'
|
||||
@@ -69,7 +91,7 @@ export default {
|
||||
type: 'string'
|
||||
},
|
||||
html: {
|
||||
type: 'string'
|
||||
validator: validElement
|
||||
},
|
||||
click: {
|
||||
type: 'function'
|
||||
|
||||
Reference in new issue
Block a user