1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- import computedBehavior from './computedBehavior'
- import relationsBehavior from './relationsBehavior'
- import safeSetDataBehavior from './safeSetDataBehavior'
- import funcBehavior from './funcBehavior'
- const baseComponent = (options = {}) => {
- // add default externalClasses
- options.externalClasses = [
- 'wux-class',
- 'wux-hover-class',
- ...(options.externalClasses = options.externalClasses || []),
- ]
- // add default behaviors
- options.behaviors = [
- relationsBehavior,
- computedBehavior,
- safeSetDataBehavior,
- ...(options.behaviors = options.behaviors || []),
- ]
- // use func
- if (options.useFunc) {
- options.behaviors = [...options.behaviors, funcBehavior]
- delete options.useFunc
- }
- // use field
- if (options.useField) {
- options.behaviors = [...options.behaviors, 'wx://form-field']
- delete options.useField
- }
- // use export
- if (options.useExport) {
- options.behaviors = [...options.behaviors, 'wx://component-export']
- options.methods = {
- export () {
- return this
- },
- ...options.methods,
- }
- delete options.useExport
- }
- // add default options
- options.options = {
- multipleSlots: true,
- addGlobalClass: true,
- ...options.options,
- }
- return Component(options)
- }
- export default baseComponent
|