useModal.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { modalStore } from '@/store/modal';
  2. const modal = modalStore()
  3. // 隐藏TabBar
  4. const hideBar = () => {
  5. // 关闭tabBar
  6. const currentPage = getCurrentPages()
  7. if (!currentPage) {
  8. return
  9. }
  10. const currentTabBar = currentPage[0]?.getTabBar?.();
  11. // console.log('打开了', currentTabBar)
  12. currentTabBar?.setData({ show: false });
  13. // uni.hideTabBar({
  14. // success: () => {},
  15. // fail: () => {} // 捕获报错,防止没有tabbar页面调用后控制台报错
  16. // })
  17. }
  18. // 显示TabBar
  19. const showBar = () => {
  20. // 打开tabBar
  21. const currentPage = getCurrentPages()
  22. if (!currentPage) {
  23. return
  24. }
  25. const currentTabBar = currentPage[0]?.getTabBar?.();
  26. // console.log('打开了', currentTabBar)
  27. currentTabBar?.setData({ show: true });
  28. // uni.showTabBar({
  29. // success: () => {},
  30. // fail: () => {} // 捕获报错,防止没有tabbar页面调用后控制台报错
  31. // })
  32. }
  33. // 打开授权弹框
  34. export function showAuthModal(type = 'login') {
  35. if (modal.auth !== '') {
  36. // 注意:延迟修改,保证下面的 closeAuthModal 先执行掉
  37. setTimeout(() => {
  38. hideBar()
  39. modal.$patch((state) => {
  40. state.auth = type
  41. })
  42. }, 500)
  43. closeAuthModal()
  44. } else {
  45. hideBar()
  46. modal.$patch((state) => {
  47. state.auth = type
  48. })
  49. }
  50. }
  51. // 关闭授权弹框
  52. export function closeAuthModal() {
  53. showBar()
  54. modal.$patch((state) => {
  55. state.auth = ''
  56. })
  57. }
  58. // 打开分享弹框
  59. export function showShareModal() {
  60. hideBar()
  61. modal.$patch((state) => {
  62. state.share = true
  63. })
  64. }
  65. // 关闭分享弹框
  66. export function closeShareModal() {
  67. showBar()
  68. modal.$patch((state) => {
  69. state.share = false
  70. })
  71. }