use-async.ts 1019 B

12345678910111213141516171819202122232425262728293031323334
  1. import { isReactive, isRef, onMounted } from 'vue'
  2. import { RouterView, useRoute, useRouter } from 'vue-router'
  3. import { Searchs } from '@/utils/searchs'
  4. function setLoading(loading: any, val: any) {
  5. if (loading != undefined && isRef(loading)) {
  6. loading.value = val
  7. } else if (loading != undefined && isReactive(loading)) {
  8. loading.loading = val
  9. }
  10. }
  11. export const useAsync = async (func: Promise<any>, loading: any): Promise<any> => {
  12. setLoading(loading, true)
  13. return await func.finally(() => setLoading(loading, false))
  14. }
  15. export const getTabsCache = (callBack: Function) => {
  16. const route = useRoute()
  17. const searchs = new Searchs(route.path)
  18. const active = searchs.get(route.path)
  19. onMounted(() => {
  20. callBack(active)
  21. })
  22. }
  23. export const setTabsCaches = (current: any, key = 'current', routes: any) => {
  24. const searchs = new Searchs(routes.path)
  25. searchs.update({ [key]: current }, undefined, 'form')
  26. const active = searchs.get(routes.path)
  27. console.log(active, 'setTabsCaches')
  28. }