useModal.js 1.2 KB

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