12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- import {
- reactive,
- toRefs
- } from "vue";
- import {
- catchError
- } from "@/utils/common.js"
- import * as httpCatalogue from "@/api/catalogue.js"
- import cacheManager from "@/utils/cacheManager";
- import {
- onLoad
- } from "@dcloudio/uni-app";
- import {getUserIdentity} from "@/utils/common.js"
-
- export function useCatalogue() {
- const data = reactive({
- levelId: null,
- subjectId: null
- })
-
- const userCode = getUserIdentity();
- onLoad(({subjectId,levelId}) => {
- if (userCode !== 'Visitor') {
- const auth = cacheManager.get('auth');
- const { levelId:levelId, subjectId:subjectId } = auth
- data.subjectId = subjectId || null;
- data.levelId = levelId || null;
- } else {
- data.subjectId = subjectId || null;
- data.levelId = levelId || null;
- }
- });
- async function getCatalogue() {
- return await catchError(httpCatalogue.getCatalogue({
- subjectId: +data.subjectId,
- levelId: +data.levelId
- }));
- }
- return {
- ...toRefs(data),
- // 获取章节数据
- getCatalogue
- }
- }
|