index.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <view>
  3. <!-- 授权页面 -->
  4. </view>
  5. </template>
  6. <script setup>
  7. import { onLoad } from '@dcloudio/uni-app'
  8. import { ref } from 'vue'
  9. import { getQueryString } from '@/utils/getParams.js'
  10. import { getInfoByTokenReq } from '@/api/index.js'
  11. const APPKEY = '9F3C6FD7E3D98CE0'
  12. const ocode = '1015730314'
  13. // 1:信息采集
  14. // 2:宿舍选取
  15. // 3:车辆预约
  16. const pageValue = ref()
  17. //1:学生 2:非学生
  18. const type = ref()
  19. // 线上地址
  20. // const URL = 'https://chtech.ncjti.edu.cn/welcome/welcome_api/welcome/api/home/Openid'
  21. // 本地地址
  22. const URL = 'http://192.168.161.221:8080/welcome/api/home/Openid'
  23. onLoad(() => {
  24. const studentInfo = uni.getStorageSync('studentInfo')
  25. if (studentInfo) {
  26. // pageValue.value = getQueryString('urlstr')
  27. // goPage()
  28. uni.reLaunch({
  29. url: '/pages/read/read'
  30. })
  31. } else {
  32. loginFilter()
  33. }
  34. })
  35. // 获取用户token
  36. const loginFilter = async () => {
  37. const token = getQueryString('token')
  38. // pageValue.value = getQueryString('urlstr')
  39. type.value = getQueryString('type')
  40. if (!token) {
  41. getCardnumberURL()
  42. } else {
  43. uni.setStorageSync('token', token)
  44. // console.log(pageValue.value)
  45. // console.log(type.value)
  46. if (type.value == 1) {
  47. // 获取信息
  48. const res = await getInfoByTokenReq()
  49. // console.log(res)
  50. if (res.code == 200) {
  51. uni.setStorageSync('studentInfo', res.data)
  52. uni.setStorageSync('TOKEN', res.data.token)
  53. // 是学生的话如何跳转
  54. // goPage()
  55. uni.reLaunch({
  56. url: '/pages/read/read'
  57. })
  58. }
  59. } else if (type.value == 2) {
  60. // 不是学生的话跳转登录页面
  61. // if (pageValue.value == 'false') {
  62. // uni.setStorageSync('token', '')
  63. // uni.reLaunch({
  64. // url: '/pages/404/404?message=暂无页面'
  65. // })
  66. // } else {
  67. // uni.reLaunch({
  68. // url: `/pages/login/login?pageValue=${pageValue.value}`
  69. // })
  70. // }
  71. uni.reLaunch({
  72. url: `/pages/login/login`
  73. })
  74. }
  75. }
  76. }
  77. const goPage = () => {
  78. if (pageValue.value == 1) {
  79. uni.reLaunch({
  80. url: '/pages/read/read'
  81. })
  82. } else if (pageValue.value == 2) {
  83. uni.reLaunch({
  84. url: '/pages/select/select'
  85. })
  86. } else if (pageValue.value == 3) {
  87. uni.reLaunch({
  88. url: '/pages/subscribe/subscribe'
  89. })
  90. } else {
  91. uni.setStorageSync('token', '')
  92. uni.setStorageSync('studentInfo', '')
  93. uni.reLaunch({
  94. url: '/pages/404/404?message=暂无页面'
  95. })
  96. }
  97. }
  98. // 跳转授权页面
  99. const getCardnumberURL = () => {
  100. let URL_param = URL + '?urlstr=' + pageValue.value
  101. window.location.href = `https://open.wecard.qq.com/connect/oauth/authorize?app_key=${APPKEY}&response_type=code&scope=snsapi_base&ocode=${ocode}&redirect_uri=${URL_param}&state=${URL_param}`
  102. }
  103. </script>
  104. <style lang="scss" scoped></style>