useCatalogue.js 640 B

123456789101112131415161718192021222324252627282930313233343536
  1. import {
  2. reactive,
  3. toRefs
  4. } from "vue";
  5. import {
  6. catchError
  7. } from "@/utils/common.js"
  8. import * as httpCatalogue from "@/api/catalogue.js"
  9. import cacheManager from "@/utils/cacheManager";
  10. export function useCatalogue() {
  11. const auth = cacheManager.get('auth');
  12. const { cardId = null, nianji = null } = auth
  13. const data = reactive({
  14. xueke: null,
  15. nianji: null
  16. })
  17. data.nianji = nianji;
  18. data.xueke = cardId;
  19. async function getCatalogue() {
  20. return await catchError(httpCatalogue.getCatalogue({
  21. nianji: +data.nianji,
  22. cardId: +data.xueke
  23. }));
  24. }
  25. return {
  26. ...toRefs(data),
  27. // 获取章节数据
  28. getCatalogue
  29. }
  30. }