uniNav.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. import { methods, baseConfig, Global } from '../helpers/config';
  2. import { noop, formatURLQuery } from '../helpers/util';
  3. let stop = null;
  4. /**
  5. * @param {Object} finalRoute 格式化后的路由跳转规则
  6. * @param {Object} NAVTYPE 需要调用的跳转方法
  7. */
  8. const uniPushTo = function (finalRoute, NAVTYPE) {
  9. return new Promise((resolve) => {
  10. const query = formatURLQuery(`?${finalRoute.uniRoute.query}`);
  11. const { APP } = baseConfig;
  12. const { url } = finalRoute.uniRoute;
  13. stop = setTimeout(() => {
  14. resolve(url);
  15. resolve = noop; // 执行完了就没了 确保不会被下一次执行
  16. Global.LockStatus = false; // 跳转完成解锁状态
  17. }, APP.switchPageOutTime);
  18. uni[methods[NAVTYPE]]({
  19. url: url + query,
  20. ...finalRoute.route.animation,
  21. complete: () => {
  22. clearTimeout(stop);
  23. resolve(url);
  24. resolve = noop; // 执行完了就没了 确保不会被下一次执行
  25. Global.LockStatus = false; // 跳转完成解锁状态
  26. },
  27. }, true); // 这里传递true 主要是兼容重写 uni.switchTab
  28. });
  29. };
  30. export default uniPushTo;