index.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * Wux Weapp 3.8.7
  3. * 一套组件化、可复用、易扩展的微信小程序 UI 组件库
  4. * https://github.com/wux-weapp/wux-weapp#readme
  5. *
  6. * Copyright 2017-2021 skyvow
  7. *
  8. * Released under the MIT License
  9. *
  10. * Released on: 2021-4-12
  11. */
  12. import $wuxCountDown from './countdown/index'
  13. import $wuxCountUp from './countup/index'
  14. /**
  15. * 使用选择器选择组件实例节点,返回匹配到的第一个组件实例对象
  16. * @param {String} selector 节点选择器
  17. * @param {Object} ctx 页面栈或组件的实例,默认为当前页面栈实例
  18. */
  19. export const getCtx = (selector, ctx = getCurrentPages()[getCurrentPages().length - 1]) => {
  20. const componentCtx = ctx.selectComponent(selector)
  21. if (!componentCtx) {
  22. throw new Error('无法找到对应的组件,请按文档说明使用组件')
  23. }
  24. return componentCtx
  25. }
  26. const version = '3.8.7'
  27. const $wuxActionSheet = (selector = '#wux-actionsheet', ctx) => getCtx(selector, ctx)
  28. const $wuxBackdrop = (selector = '#wux-backdrop', ctx) => getCtx(selector, ctx)
  29. const $wuxCalendar = (selector = '#wux-calendar', ctx) => getCtx(selector, ctx)
  30. const $wuxDialog = (selector = '#wux-dialog', ctx) => getCtx(selector, ctx)
  31. const $wuxForm = (selector = '#wux-form', ctx) => getCtx(selector, ctx)
  32. const $wuxGallery = (selector = '#wux-gallery', ctx) => getCtx(selector, ctx)
  33. const $wuxKeyBoard = (selector = '#wux-keyboard', ctx) => getCtx(selector, ctx)
  34. const $wuxLoading = (selector = '#wux-loading', ctx) => getCtx(selector, ctx)
  35. const $wuxNotification = (selector = '#wux-notification', ctx) => getCtx(selector, ctx)
  36. const $startWuxRefresher = (selector = '#wux-refresher', ctx) => getCtx(selector, ctx).triggerRefresh()
  37. const $stopWuxRefresher = (selector = '#wux-refresher', ctx) => getCtx(selector, ctx).finishPullToRefresh()
  38. const $stopWuxLoader = (selector = '#wux-refresher', ctx, isEnd) => getCtx(selector, ctx).finishLoadmore(isEnd)
  39. const $wuxSelect = (selector = '#wux-select', ctx) => getCtx(selector, ctx)
  40. const $wuxToast = (selector = '#wux-toast', ctx) => getCtx(selector, ctx)
  41. const $wuxToptips = (selector = '#wux-toptips', ctx) => getCtx(selector, ctx)
  42. export {
  43. version,
  44. $wuxCountDown,
  45. $wuxCountUp,
  46. $wuxActionSheet,
  47. $wuxBackdrop,
  48. $wuxCalendar,
  49. $wuxDialog,
  50. $wuxForm,
  51. $wuxGallery,
  52. $wuxKeyBoard,
  53. $wuxLoading,
  54. $wuxNotification,
  55. $startWuxRefresher,
  56. $stopWuxRefresher,
  57. $stopWuxLoader,
  58. $wuxSelect,
  59. $wuxToast,
  60. $wuxToptips
  61. }