useCatalogue.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import {
  2. reactive,
  3. toRefs
  4. } from "vue";
  5. import {
  6. catchError,
  7. getDataFromStr
  8. } from "@/utils/common.js"
  9. import * as httpCatalogue from "@/api/catalogue.js"
  10. import cacheManager from "@/utils/cacheManager";
  11. import {
  12. onLoad
  13. } from "@dcloudio/uni-app";
  14. import {getUserIdentity} from "@/utils/common.js"
  15. export function useCatalogue() {
  16. const data = reactive({
  17. levelId: null,
  18. subjectId: null
  19. })
  20. const userCode = getUserIdentity();
  21. onLoad(({subjectId,levelId}) => {
  22. if (userCode !== 'Visitor') {
  23. const auth = cacheManager.get('auth');
  24. const { levelId:levelId, subjectId:subjectId } = auth
  25. data.subjectId = subjectId || null;
  26. data.levelId = getDataFromStr(levelId)[0] || null;
  27. } else {
  28. data.subjectId = subjectId || null;
  29. data.levelId = levelId || null;
  30. }
  31. });
  32. async function getCatalogue() {
  33. return await catchError(httpCatalogue.getCatalogue({
  34. subjectId: +data.subjectId,
  35. levelId: +data.levelId
  36. }));
  37. }
  38. return {
  39. ...toRefs(data),
  40. // 获取章节数据
  41. getCatalogue
  42. }
  43. }