TpLogin.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <script setup lang="ts">
  2. import {useRoute} from "vue-router";
  3. import {onMounted} from "vue";
  4. import {getCurrentUser, tpLoginApi} from "@/api/userApi.ts";
  5. import router from '../router/index';
  6. import {ElLoading, ElNotification} from "element-plus";
  7. import {useUserInfo} from "@/stores/userInfo.ts";
  8. const route = useRoute()
  9. const userInfo = useUserInfo();
  10. const tpToken = route.query.tpToken;
  11. const targetPath = route.query.targetPath;
  12. onMounted(() => {
  13. const loading = ElLoading.service({
  14. lock: true,
  15. text: '登录中...',
  16. background: 'rgba(0, 0, 0, 0.7)',
  17. })
  18. console.log(tpToken)
  19. if (tpToken == null) {
  20. router.push("/")
  21. }
  22. tpLoginApi({
  23. tpToken: tpToken + ""
  24. }).then(res => {
  25. console.log(res)
  26. if (res.data.code === 0) {
  27. userInfo.setToken(res.data.data.token + "", 'auth');
  28. const userType = res.data.data.userType;
  29. getCurrentUser().then((res) => {
  30. userInfo.dataFill(Object.assign({userType: userType}, res.data.data));
  31. if (targetPath) {
  32. router.push({path:targetPath+""})
  33. }else {
  34. if (userType == 0) router.push({path: '/train'});
  35. else if (userType == 1) router.push({path: '/TaskMng'});
  36. else {
  37. ElNotification({
  38. message: '无效用户',
  39. type: 'info',
  40. });
  41. }
  42. }
  43. }).finally(() => {
  44. loading.close()
  45. });
  46. }
  47. })
  48. })
  49. </script>
  50. <template>
  51. <!-- 登录中...-->
  52. </template>
  53. <style scoped>
  54. </style>