useModal.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. currentTabBar?.setData({ show: false });
  12. }
  13. // 显示TabBar
  14. const showBar = () => {
  15. // 打开tabBar
  16. const currentPage = getCurrentPages()
  17. if (!currentPage) {
  18. return
  19. }
  20. const currentTabBar = currentPage[0]?.getTabBar?.();
  21. currentTabBar?.setData({ show: true });
  22. }
  23. // 打开授权弹框
  24. export function showAuthModal(type = 'login') {
  25. if (modal.auth !== '') {
  26. // 注意:延迟修改,保证下面的 closeAuthModal 先执行掉
  27. setTimeout(() => {
  28. hideBar()
  29. modal.$patch((state) => {
  30. state.auth = type
  31. })
  32. }, 500)
  33. closeAuthModal()
  34. } else {
  35. hideBar()
  36. modal.$patch((state) => {
  37. state.auth = type
  38. })
  39. }
  40. }
  41. // 关闭授权弹框
  42. export function closeAuthModal() {
  43. showBar()
  44. modal.$patch((state) => {
  45. state.auth = ''
  46. })
  47. }
  48. // 打开分享弹框
  49. export function showShareModal() {
  50. hideBar()
  51. modal.$patch((state) => {
  52. state.share = true
  53. })
  54. }
  55. // 关闭分享弹框
  56. export function closeShareModal() {
  57. showBar()
  58. modal.$patch((state) => {
  59. state.share = false
  60. })
  61. }