微信小程序,访客邀约
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 

62 rindas
2.1 KiB

  1. import { NavigateType, Router, Route as TaroJsRoute, NavigateOptions } from "tarojs-router-next";
  2. import { getCurrentInstance } from '@tarojs/taro'
  3. import { Session } from "./session";
  4. if (!Session.has('prevent-double-click')) {
  5. Session.set('prevent-double-click', Math.floor(Date.now()/100))
  6. }
  7. export class Route {
  8. static redirectTo = (route: TaroJsRoute, options?: NavigateOptions, withoutPreventDoubleClick?: boolean) => {
  9. if (!withoutPreventDoubleClick && !Route.preventDoubleClick()) return
  10. if (Route.isTabBar(route.url)) {
  11. Router.navigate( route, {...options, ...{ type: NavigateType.switchTab }} )
  12. }
  13. else {
  14. Router.navigate( route, {...options, ...{ type: NavigateType.redirectTo }} )
  15. }
  16. }
  17. static navigateTo = (route: TaroJsRoute, options?: NavigateOptions, withoutPreventDoubleClick?: boolean) => {
  18. if (!withoutPreventDoubleClick && !Route.preventDoubleClick()) return
  19. if (Route.isTabBar(route.url)) {
  20. Router.navigate( route, {...options, ...{ type: NavigateType.switchTab }} )
  21. }
  22. else {
  23. Router.navigate( route, {...options, ...{ type: NavigateType.navigateTo }} )
  24. }
  25. }
  26. static reLaunch = (route: TaroJsRoute, options?: NavigateOptions, withoutPreventDoubleClick?: boolean) => {
  27. if (!withoutPreventDoubleClick && !Route.preventDoubleClick()) return
  28. if (Route.isTabBar(route.url)) {
  29. Router.navigate( route, {...options, ...{ type: NavigateType.switchTab }} )
  30. }
  31. else {
  32. Router.navigate( route, {...options, ...{ type: NavigateType.reLaunch }} )
  33. }
  34. }
  35. static preventDoubleClick() {
  36. const currentTime = Math.floor(Date.now()/100)
  37. if ((currentTime - Session.get('prevent-double-click')) < 10 ) return false
  38. Session.set('prevent-double-click', currentTime)
  39. return true
  40. }
  41. static isTabBar = (url) => {
  42. // @ts-ignore
  43. const tabBarList = getCurrentInstance().app?.config.tabBar.list;
  44. if (tabBarList == undefined) return false
  45. for (let item of tabBarList) {
  46. if (url.match("/"+item.pagePath)) {
  47. return true;
  48. }
  49. }
  50. return false
  51. }
  52. static getRequest = () => {
  53. return getCurrentInstance().router!.params
  54. }
  55. }