qiyunfeng-create
2 天以前 5f00696dfb25bc90034448ceb634ed1ef256681a
src/views/personalCenter/index.vue
@@ -41,53 +41,58 @@
</template>
<script setup lang="ts">
import { ArrowRight } from '@element-plus/icons-vue'
import { menu } from './config.ts'
import { useRouter, onBeforeRouteUpdate } from 'vue-router'
import { ref, onMounted } from 'vue'
const router = useRouter()
const routerVal = router.currentRoute.value
const path = ref(routerVal.path)
const label = ref('')
const listMenu: any = ref([])
import { ArrowRight } from "@element-plus/icons-vue";
import { menu } from "./config.ts";
import { useRouter, onBeforeRouteUpdate } from "vue-router";
import { ref, onMounted, inject } from "vue";
const router = useRouter();
const routerVal = router.currentRoute.value;
const path = ref(routerVal.path);
const label = ref("");
const listMenu: any = ref([]);
const MG: any = inject("MG");
const config: any = inject("config");
onBeforeRouteUpdate(async (to, from) => {
  path.value = to.fullPath
})
  path.value = to.fullPath;
});
onMounted(() => {
  menu.forEach((item) => {
    if ('/' + item.path === path.value) {
      label.value = item.label
    if ("/" + item.path === path.value) {
      label.value = item.label;
    }
  })
  // const userCache: any = localStorage.getItem('jesk-userInfo')
  // const userInfo = JSON.parse(userCache)
  // if(!userInfo){
  //   router.push({
  //     path:'/'
  //   })
  //   return false;
  // }
  // if (userInfo.role == 'Teacher') {
  //   const data: any = menu.filter((item) => item.path != 'class')
  //   listMenu.value = data
  // } else {
  const data: any = menu.filter((item) => item.path != 'course')
  listMenu.value = data
  // }
})
  });
  const userCache: any = localStorage.getItem(config.userInfoKey);
  const userInfo = JSON.parse(userCache);
  if (!userInfo) {
    router.push({
      path: "/",
    });
    return false;
  }
  if (userInfo.role == "Teacher") {
    const data: any = menu.filter((item) => item.path != "myClass");
    listMenu.value = data;
  } else {
    const data: any = menu.filter((item) => item.path != "myCourse");
    listMenu.value = data;
  }
});
const goRouter = (item: any) => {
  // if (!localStorage.getItem('jsek-token') || localStorage.getItem('jsek-token') == null) {
  //   router.push({
  //     path: '/home',
  //     query: {
  //       showLogin: '1'
  //     }
  //   })
  // } else {
  label.value = item.label
  router.push({ path: item.path })
  // }
}
  if (
    !localStorage.getItem(config.tokenKey) ||
    localStorage.getItem(config.tokenKey) == null
  ) {
    router.push({
      path: "/home",
      query: {
        showLogin: "1",
      },
    });
  } else {
    label.value = item.label;
    router.push({ path: item.path });
  }
};
</script>
<style lang="less" scoped>
.breadcrumbBox {