component-util.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // 从scheme获取组件props
  2. export const generateProps = (componentScheme) => {
  3. if (componentScheme.propsScheme) {
  4. const props = {}
  5. Object.keys(componentScheme.propsScheme).forEach(propKey => {
  6. const propScheme = componentScheme.propsScheme[propKey]
  7. if (!propScheme.attr) {
  8. const prop = {}
  9. const { type, default: defaultValue, options, validate } = propScheme
  10. if (type) prop.type = type
  11. prop.default = defaultValue
  12. if (options && validate) prop.validate = (val) => options.includes(val)
  13. props[propKey] = prop
  14. }
  15. })
  16. return props
  17. } else {
  18. return {}
  19. }
  20. }
  21. // 从scheme获取组件emits
  22. export const generateEmits = (componentScheme) => {
  23. if (componentScheme.eventsScheme) {
  24. return Object.keys(componentScheme.eventsScheme).reduce((acc, emitKey) => {
  25. acc[emitKey] = {}
  26. // acc[emitKey] = (val) => {
  27. // console.log(emitKey, val)
  28. // return true
  29. // }
  30. return acc
  31. }, {})
  32. } else {
  33. return []
  34. }
  35. }