index.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. getInfo()
  28. } else {
  29. loginFilter()
  30. }
  31. })
  32. // 获取用户token
  33. const loginFilter = () => {
  34. const token = getQueryString('token')
  35. pageValue.value = getQueryString('urlstr')
  36. type.value = getQueryString('type')
  37. // console.log(pageValue.value)
  38. // console.log(type.value)
  39. if (!token) {
  40. getCardnumberURL()
  41. } else {
  42. uni.setStorageSync('token', token)
  43. uni.setStorageSync('urlstr', pageValue.value)
  44. // console.log(type.value)
  45. if (type.value == 1) {
  46. getInfo()
  47. } else if (type.value == 2) {
  48. // 不是学生的话跳转登录页面
  49. if (pageValue.value == 'false') {
  50. uni.clearStorageSync()
  51. uni.reLaunch({
  52. url: '/pages/404/404?message=暂无页面'
  53. })
  54. } else {
  55. uni.reLaunch({
  56. url: `/pages/login/login?pageValue=${pageValue.value}`
  57. })
  58. }
  59. }
  60. }
  61. }
  62. // 获取信息
  63. const getInfo = async () => {
  64. const res = await getInfoByTokenReq()
  65. // console.log(res)
  66. if (res.code == 200) {
  67. uni.setStorageSync('studentInfo', res.data)
  68. uni.setStorageSync('TOKEN', res.data.token)
  69. // 是学生的话如何跳转
  70. goPage()
  71. }
  72. }
  73. const goPage = () => {
  74. if (pageValue.value == 1) {
  75. const studentInfo = uni.getStorageSync('studentInfo')
  76. if (studentInfo.fillStatus == '已填报') {
  77. uni.reLaunch({
  78. url: '/pages/myMsg/myMsg'
  79. })
  80. } else {
  81. uni.reLaunch({
  82. url: '/pages/read/read'
  83. })
  84. }
  85. } else if (pageValue.value == 2 || pageValue.value == 3) {
  86. let { isPay } = uni.getStorageSync('studentInfo')
  87. if (isPay == 0) {
  88. // uni.clearStorageSync()
  89. uni.reLaunch({
  90. url: `/pages/404/404?message=请先完成缴费&pageValue=${pageValue.value}`
  91. })
  92. } else if (isPay == 1) {
  93. if (pageValue.value == 2) {
  94. uni.reLaunch({
  95. url: '/pages/select/select'
  96. })
  97. } else {
  98. uni.reLaunch({
  99. url: '/pages/subscribe/subscribe'
  100. })
  101. }
  102. } else {
  103. uni.showToast({
  104. title: '暂无缴费信息',
  105. icon: 'none'
  106. })
  107. }
  108. } else {
  109. uni.clearStorageSync()
  110. uni.reLaunch({
  111. url: '/pages/404/404?message=暂无页面'
  112. })
  113. }
  114. }
  115. // 跳转授权页面
  116. const getCardnumberURL = () => {
  117. let URL_param = URL + '?urlstr=' + pageValue.value
  118. 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}`
  119. }
  120. </script>
  121. <style lang="scss" scoped></style>