index.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. // const URL = 'https://chtech.ncjti.edu.cn/testingServer/carbook/appopenid.action'
  13. // 本地地址
  14. // const URL = 'http://192.168.161.170:8088/carBook/appopenid.action'
  15. onLoad(() => {
  16. loginFilter()
  17. })
  18. // 获取用户card_number
  19. const loginFilter = () => {
  20. const card_number = uni.getStorageSync('bus_card_number')
  21. if (!card_number) {
  22. const card_number = getQueryString('card_number')
  23. if (!card_number) {
  24. getCardnumberURL()
  25. } else {
  26. uni.setStorageSync('bus_card_number', card_number)
  27. getUserInfo()
  28. }
  29. } else {
  30. getUserInfo()
  31. }
  32. }
  33. // 获取用户信息
  34. const getUserInfo = async () => {
  35. const card_number = uni.getStorageSync('bus_card_number')
  36. const res = await myRequest({
  37. url: '/appget_user.action',
  38. data: {
  39. card_number
  40. }
  41. })
  42. // console.log(res);
  43. uni.setStorageSync('bus-userInfo', JSON.stringify(res.data))
  44. // 判断用户权限
  45. if (res.data && res.data.user_zz === '教师') {
  46. uni.switchTab({
  47. url: '/pages/home/home'
  48. })
  49. } else if (res.data && res.data.user_zz === '车队长') {
  50. uni.reLaunch({
  51. url: '/pages/record/record'
  52. })
  53. } else if (res.data && res.data.user_zz === '司机') {
  54. uni.reLaunch({
  55. url: '/pages/recordDriver/recordDriver'
  56. })
  57. }
  58. }
  59. // 跳转授权页面
  60. const getCardnumberURL = () => {
  61. 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}`
  62. }
  63. </script>