dev_login.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <template>
  2. <div></div>
  3. </template>
  4. <script setup>
  5. import { useRoute, useRouter } from "vue-router";
  6. import { useStore } from "vuex";
  7. import { SET_TOKEN,SET_USER_ROLES,SET_USER_CUR_ROLE } from "@/store/modules/app/type";
  8. import { onMounted } from "vue";
  9. const router = useRouter();
  10. const route = useRoute();
  11. const store = useStore();
  12. let userId = route.query.userId;
  13. onMounted(async () => {
  14. const token = route.query.token
  15. const targetUrl = route.query.targetUrl ? route.query.targetUrl : '/home';
  16. if (!token) {
  17. const { data } = await VE_API.system.devLogin({ userId: userId });
  18. store.dispatch(`app/${SET_TOKEN}`, data.token);
  19. store.dispatch(`app/${SET_USER_ROLES}`, data.roles);
  20. store.dispatch(`app/${SET_USER_CUR_ROLE}`, data.roles[0] || 0);
  21. localStorage.setItem("localUserInfo", JSON.stringify(data));
  22. }
  23. // 存userId
  24. let pointXy = route.query.point.split(",")
  25. // 刷新后仍保留id和point
  26. localStorage.setItem("MINI_USER_ID", userId)
  27. if(route.query.roles){
  28. store.dispatch(`app/${SET_USER_ROLES}`,JSON.parse(route.query.roles));
  29. store.dispatch(`app/${SET_USER_CUR_ROLE}`, JSON.parse(route.query.roles)[0] || 0);
  30. }
  31. localStorage.setItem("MINI_USER_LOCATION", route.query.point)
  32. localStorage.setItem("MINI_USER_LOCATION_POINT", `POINT(${pointXy[0]} ${pointXy[1]})`)
  33. store.commit("home/SET_MINI_USER_LOCATION", route.query.point);
  34. store.commit("home/SET_MINI_USER_ID", userId);
  35. store.commit("home/SET_MINI_USER_LOCATION_POINT", `POINT(${pointXy[0]} ${pointXy[1]})`);
  36. router.push(`${targetUrl}?miniJson=${JSON.stringify(route.query)}`);
  37. })
  38. </script>
  39. <style scoped></style>