notify.js 865 B

1234567891011121314151617181920212223242526272829
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var utils_1 = require("../common/utils");
  4. var defaultOptions = {
  5. selector: '#van-notify',
  6. duration: 3000
  7. };
  8. function parseOptions(text) {
  9. return utils_1.isObj(text) ? text : { text: text };
  10. }
  11. function getContext() {
  12. var pages = getCurrentPages();
  13. return pages[pages.length - 1];
  14. }
  15. function Notify(options) {
  16. options = Object.assign({}, defaultOptions, parseOptions(options));
  17. var context = options.context || getContext();
  18. var notify = context.selectComponent(options.selector);
  19. delete options.context;
  20. delete options.selector;
  21. if (notify) {
  22. notify.set(options);
  23. notify.show();
  24. }
  25. else {
  26. console.warn('未找到 van-notify 节点,请确认 selector 及 context 是否正确');
  27. }
  28. }
  29. exports.default = Notify;