App.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <script setup>
  2. import { onMounted, ref } from 'vue'
  3. import { RouterLink, RouterView, useRoute } from 'vue-router'
  4. import Header from './views/header.vue';
  5. import axios from 'axios';
  6. import { userInfoStore } from './stores/counter'
  7. const route = useRoute()
  8. const store = userInfoStore()
  9. onMounted(() => {
  10. console.log(11, window.parent.location.href)
  11. // 通过 grant_code 获取登录信息
  12. let isGrantCode = getUrlParam(window.parent.location.href, 'grant_code')
  13. axios.defaults.headers = { 'content-type': 'application/json;charset=utf-8' }
  14. if (isGrantCode) {
  15. let params = {
  16. grantCode: isGrantCode,
  17. redirectUri: "https://cloud.cocorobo.cn/testapi"
  18. }
  19. axios.post('//cloud.cocorobo.cn/api/getAccessToken', JSON.stringify(params)).then(res => {
  20. console.log(res)
  21. let accessTokenParams = {
  22. accessToken: res.data.data.accessToken
  23. }
  24. axios.post('//cloud.cocorobo.cn/api/getUserInfo', JSON.stringify(accessTokenParams)).then(r => {
  25. console.log(r, r.data.code, r.data.data)
  26. if (r.data.code == 0) {
  27. store.user = r.data.data
  28. userInfo(r.data.data)
  29. } else {
  30. }
  31. })
  32. })
  33. }
  34. })
  35. const linkLogin = () => {
  36. window.location.href = `http://szedutest.changyan.cn/thirdauth/oauth2/authorize?service=initService&scope=all&response_type=code&app_id=94c720f0634b4bad890dc9223de01166&redirect_uri=https://cloud.cocorobo.cn/testapi`
  37. }
  38. // 同步登录信息
  39. const userInfo = (data) => {
  40. let userIdentity = 2
  41. if (data.currentRole == "areaAdministrator" || data.currentRole == "userAdministrator" || data.currentRole == "securityAuditor" || data.currentRole == "schoolAdministrator" || data.currentRole == "schoolSecurityAuditor" || data.currentRole == "teacher") {
  42. userIdentity = 1
  43. }
  44. let userGrand = ""
  45. if (data.childList && data.childList.length > 0) {
  46. userGrand = data.childList[0].gradeName + data.childList[0].className
  47. }
  48. top.U.A.Request("https://pbl.cocorobo.cn/api/pbl/batchRegistrationSzdjg", [data.userName, data.telephoneNumber + '@szdjg.com', '16ace517-b5c7-4168-a9bb-a9e0035df840', data.schoolName, data.telephoneNumber, userGrand, userIdentity,data.userId], function (res) {
  49. console.log('1111111111',res)
  50. }, [], { "type": "POST", "withCredentials": true });
  51. let params ={
  52. openid:data.userId
  53. }
  54. axios.post(`https://beta.api.cocorobo.cn/api/user`, qs.stringify(params)).then(res => {
  55. console.log(res,'222222222222')
  56. })
  57. }
  58. const getUrlParam = (urlStr, urlKey) => {
  59. const url = new URL(urlStr) // 字符串转换成url格式
  60. const paramsStr = url.search.slice(1) // 获取'?'后面的参数字符串
  61. const paramsArr = paramsStr.split('&') // 分割'&'字符 获得参数数组
  62. for (let i = 0; i < paramsArr.length; i++) {
  63. const tempArr = paramsArr[i].split('=')
  64. if (tempArr[0] === urlKey) {
  65. return tempArr[1]
  66. }
  67. }
  68. }
  69. </script>
  70. <template>
  71. <Header></Header>
  72. <!-- <keep-alive> -->
  73. <router-view></router-view>
  74. <!-- </keep-alive> -->
  75. </template>
  76. <style scoped></style>