index.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <view><!-- 授权页面 --></view>
  3. </template>
  4. <script setup>
  5. import { onLoad } from '@dcloudio/uni-app'
  6. import { getQueryString } from '@/util/getParams.js'
  7. import { myRequest } from '@/util/api.js'
  8. const APPKEY = '4AA7B3944BDF3739'
  9. const ocode = '1015730314'
  10. // 线上地址
  11. const URL = 'https://chtech.ncjti.edu.cn/carstop/carbook/appopenid.action'
  12. // 测试地址
  13. // const URL = 'https://chtech.ncjti.edu.cn/testingServertomcat/carbook/appopenid.action'
  14. // 本地地址
  15. // const URL = 'http://192.168.161.220:8088/carBook/appopenid.action'
  16. onLoad(() => {
  17. loginFilter()
  18. })
  19. // 获取用户card_number
  20. const loginFilter = () => {
  21. const card_number = getQueryString('card_number')
  22. if (!card_number) {
  23. // 判断是否是从小程序进入
  24. const type = getQueryString('type')
  25. if (type === 'weixin') {
  26. // 跳转回小程序页面授权
  27. jWeixin.miniProgram.reLaunch({ url: '/pages/index/index' })
  28. } else {
  29. getCardnumberURL()
  30. }
  31. } else {
  32. uni.setStorageSync('bus_card_number', card_number)
  33. getUserInfo()
  34. }
  35. }
  36. // 获取用户信息
  37. const getUserInfo = async () => {
  38. const card_number = uni.getStorageSync('bus_card_number')
  39. const res = await myRequest({
  40. url: '/appget_user.action',
  41. data: {
  42. card_number
  43. }
  44. })
  45. // console.log(res);
  46. uni.setStorageSync('bus-userInfo', JSON.stringify(res.data))
  47. // 判断用户权限
  48. if (res.data.user_zz === '教师' || res.data.user_zz === '临时人员') {
  49. uni.switchTab({
  50. url: '/pages/home/home'
  51. })
  52. } else if (res.data.user_zz === '车队长') {
  53. uni.reLaunch({
  54. url: '/pages/record/record'
  55. })
  56. } else if (res.data.user_zz === '司机') {
  57. uni.reLaunch({
  58. url: '/pages/recordDriver/recordDriver'
  59. })
  60. } else {
  61. uni.reLaunch({
  62. url: '/pages/404/404'
  63. })
  64. }
  65. }
  66. // 跳转授权页面
  67. const getCardnumberURL = () => {
  68. 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}&state=${URL}`
  69. }
  70. </script>