You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import computedBehavior from './computedBehavior'
  2. import relationsBehavior from './relationsBehavior'
  3. import safeAreaBehavior from './safeAreaBehavior'
  4. import safeSetDataBehavior from './safeSetDataBehavior'
  5. import funcBehavior from './funcBehavior'
  6. import compareVersion from './compareVersion'
  7. const { platform, SDKVersion } = wx.getSystemInfoSync()
  8. const libVersion = '2.6.6'
  9. // check SDKVersion
  10. if (platform === 'devtools' && compareVersion(SDKVersion, libVersion) < 0) {
  11. if (wx && wx.showModal) {
  12. wx.showModal({
  13. title: '提示',
  14. content: `当前基础库版本(${SDKVersion})过低,无法使用 Wux Weapp 组件库,请更新基础库版本 >=${libVersion} 后重试。`,
  15. })
  16. }
  17. }
  18. const baseComponent = (options = {}) => {
  19. // add default externalClasses
  20. options.externalClasses = [
  21. 'wux-class',
  22. 'wux-hover-class',
  23. ...(options.externalClasses = options.externalClasses || []),
  24. ]
  25. // add default behaviors
  26. options.behaviors = [
  27. relationsBehavior,
  28. safeSetDataBehavior,
  29. ...(options.behaviors = options.behaviors || []),
  30. computedBehavior, // make sure it's triggered
  31. ]
  32. // use safeArea
  33. if (options.useSafeArea) {
  34. options.behaviors = [...options.behaviors, safeAreaBehavior]
  35. delete options.useSafeArea
  36. }
  37. // use func
  38. if (options.useFunc) {
  39. options.behaviors = [...options.behaviors, funcBehavior]
  40. delete options.useFunc
  41. }
  42. // use field
  43. if (options.useField) {
  44. options.behaviors = [...options.behaviors, 'wx://form-field']
  45. delete options.useField
  46. }
  47. // use field button
  48. if (options.useFieldButton) {
  49. options.behaviors = [...options.behaviors, 'wx://form-field-button']
  50. delete options.useFieldButton
  51. }
  52. // use export
  53. if (options.useExport) {
  54. options.behaviors = [...options.behaviors, 'wx://component-export']
  55. options.methods = {
  56. ['export'] () {
  57. return this
  58. },
  59. ...options.methods,
  60. }
  61. options['export'] = options.methods['export']
  62. delete options.useExport
  63. }
  64. // add default options
  65. options.options = {
  66. multipleSlots: true,
  67. addGlobalClass: true,
  68. ...options.options,
  69. }
  70. // 属性的类型(可以指定多个)
  71. options.properties && Object.keys(options.properties).forEach((propKey) => {
  72. const prop = options.properties[propKey]
  73. if (Array.isArray(prop.type)) {
  74. prop.optionalTypes = prop.type
  75. }
  76. })
  77. return Component(options)
  78. }
  79. export default baseComponent