123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- import { defineStore } from 'pinia'
- import { systemStudent, systemUserGetInfo } from '@/api/modules/global'
- import { systemSubjectList } from '@/api/modules/study'
- import router from '@/router'
- export const useAppStore = defineStore('app', {
- state: () => ({
- userInfo: null,
- studentInfo: null,
- categoryMenus: [],
- subjectMap: new Map(),
- }),
- getters: {},
- actions: {
- initUserInfo() {
- return new Promise((resolve, reject) => {
- systemUserGetInfo()
- .then(({ data: userData }: any) => {
- this.userInfo = userData.user
- systemStudent(this.userInfo?.userId).then(
- ({ data: studentData }: any) => {
- this.studentInfo = studentData
- systemSubjectList({
- pageNum: 1,
- pageSize: 10,
- category: this.studentInfo?.grade,
- }).then(({ rows }: any) => {
- const categoryMenus: any = []
- const map = new Map()
- rows.forEach((su) => {
- map.set(su.subjectId, su.subject)
- const menu1 = {
- path: '/' + su.subjectId,
- name: su.subjectId,
- component: () =>
- import('@/views/study/subject/index.vue'),
- meta: {
- subjectId: su.subjectId,
- isMenu: true,
- fa: 'fa-book',
- res: su,
- title: su.subject,
- },
- }
- const menu2 = {
- path: menu1.path + '/question',
- name: menu1.name + 'question',
- component: () =>
- import('@/views/study/subject/question/index.vue'),
- meta: {
- subjectId: su.subjectId,
- res: su,
- title: su.subject,
- root: menu1.name,
- },
- }
- const menu3 = {
- path: menu1.path + '/plan',
- name: menu1.name + 'plan',
- component: () =>
- import('@/views/study/subject/question/plan.vue'),
- meta: {
- subjectId: su.subjectId,
- res: su,
- title: su.subject,
- root: menu1.name,
- },
- }
- categoryMenus.push(menu1)
- categoryMenus.push(menu2)
- categoryMenus.push(menu3)
- })
- this.subjectMap = map
- categoryMenus.forEach((v) => {
- router.addRoute(v)
- })
- this.categoryMenus = categoryMenus
- resolve(this.userInfo)
- })
- },
- )
- })
- .catch((e) => {
- reject(e)
- })
- })
- },
- loadingStart() {
- const l = document.getElementById('loader')
- if (l) {
- l.style.display = 'flex'
- }
- },
- loadingEnd() {
- const l = document.getElementById('loader')
- if (l) {
- l.style.display = 'none'
- }
- },
- },
- })
|