select.js 701 B

123456789101112131415161718192021222324252627282930313233
  1. function getCtx(selector) {
  2. const pages = getCurrentPages();
  3. const ctx = pages[pages.length - 1];
  4. const componentCtx = ctx.selectComponent(selector);
  5. if (!componentCtx) {
  6. console.error('无法找到对应的组件,请按文档说明使用组件');
  7. return null;
  8. }
  9. return componentCtx;
  10. }
  11. // 调用showToast
  12. function selectToast(options) {
  13. const { selector = '#toast' } = options;
  14. const ctx = getCtx(selector);
  15. ctx.handleShow(options);
  16. }
  17. // 调用showMessage
  18. function selectMessage(options) {
  19. const { selector = '#message' } = options;
  20. const ctx = getCtx(selector);
  21. ctx.handleShow(options);
  22. }
  23. module.exports = {
  24. $Toast: selectToast,
  25. $Message: selectMessage
  26. };