baseComponent.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import computedBehavior from './computedBehavior'
  2. import relationsBehavior from './relationsBehavior'
  3. import safeSetDataBehavior from './safeSetDataBehavior'
  4. import funcBehavior from './funcBehavior'
  5. const baseComponent = (options = {}) => {
  6. // add default externalClasses
  7. options.externalClasses = [
  8. 'wux-class',
  9. 'wux-hover-class',
  10. ...(options.externalClasses = options.externalClasses || []),
  11. ]
  12. // add default behaviors
  13. options.behaviors = [
  14. relationsBehavior,
  15. computedBehavior,
  16. safeSetDataBehavior,
  17. ...(options.behaviors = options.behaviors || []),
  18. ]
  19. // use func
  20. if (options.useFunc) {
  21. options.behaviors = [...options.behaviors, funcBehavior]
  22. delete options.useFunc
  23. }
  24. // use field
  25. if (options.useField) {
  26. options.behaviors = [...options.behaviors, 'wx://form-field']
  27. delete options.useField
  28. }
  29. // use export
  30. if (options.useExport) {
  31. options.behaviors = [...options.behaviors, 'wx://component-export']
  32. options.methods = {
  33. export () {
  34. return this
  35. },
  36. ...options.methods,
  37. }
  38. delete options.useExport
  39. }
  40. // add default options
  41. options.options = {
  42. multipleSlots: true,
  43. addGlobalClass: true,
  44. ...options.options,
  45. }
  46. return Component(options)
  47. }
  48. export default baseComponent