preload.js 749 B

12345678910111213141516171819202122232425262728293031
  1. document.addEventListener('UniAppJSBridgeReady', function () {
  2. uni.webView.postMessage({
  3. data: {
  4. action: 'setPlatform'
  5. }
  6. });
  7. window.backup = (from) => {
  8. if (from === 'backbutton') {
  9. const routes = getCurrentPages();
  10. const route = routes[routes.length - 1].route;
  11. if ([
  12. 'pagesMain/pages/index/index',
  13. 'pagesMain/pages/volunteer/volunteer',
  14. 'pagesMain/pages/me/me'
  15. ].includes(route)) {
  16. uni.webView.postMessage({
  17. data: {
  18. action: 'quit'
  19. }
  20. });
  21. } else {
  22. uni.navigateBack();
  23. }
  24. }
  25. };
  26. // 默认为h5平台
  27. window.platform = 'h5';
  28. window.setPlatform = (platform) => {
  29. window.platform = platform;
  30. };
  31. });