-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
155 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import MDFComponent from './factory'; | ||
import MetaConfig from './metaConfig'; | ||
export {MDFComponent, MetaConfig} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,40 @@ | ||
// const metaConfig = { | ||
// setConfig: function (data) { | ||
// console.log('metaConfig-------', data); | ||
// } | ||
// } | ||
function metaConfig (data) { | ||
console.log('metaConfig-------', data); | ||
// import React from 'react'; | ||
|
||
export default function MetaConfig (metaInfo = {}) { | ||
const { name, api } = metaInfo | ||
console.log('name', name, 'api', api); | ||
return function (targetComponent, name, descriptor) { | ||
console.log(targetComponent, name, descriptor) | ||
const {defaultProps, propTypes} = aynalyProps(api) | ||
targetComponent.defaultProps = defaultProps; | ||
targetComponent.propTypes = propTypes; | ||
} | ||
} | ||
/** | ||
* 解析api,将默认的属性同步到类上 | ||
* @param {array} api | ||
* api 中每个元素item说明 | ||
* { | ||
* name: 字段属性名, | ||
* type: 属性类型,[array, bool, func, number, string, element, node ] | ||
* defaultValue: 默认值, | ||
* isMust: 是否必填, | ||
* desc: 属性描述 | ||
* } | ||
*/ | ||
function aynalyProps (api = []) { | ||
const defaultProps = {}; | ||
const propTypes = {}; | ||
api.forEach(item => { | ||
const name = item?.name | ||
if (name) { | ||
const { type, defaultValue } = item; | ||
if (defaultValue || defaultValue == 0) | ||
defaultProps[name] = defaultValue | ||
if (type) { | ||
propTypes[name] = type | ||
} | ||
} | ||
}) | ||
return {defaultProps, propTypes}; | ||
} | ||
export default metaConfig |
Binary file not shown.