notify.js 760 B

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