index.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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/testingServertomcat/carbook/appopenid.action'
  13. // 本地地址
  14. // const URL = 'http://192.168.161.220:8088/carBook/appopenid.action'
  15. onLoad(() => {
  16. loginFilter()
  17. })
  18. // 获取用户card_number
  19. const loginFilter = () => {
  20. const card_number = getQueryString('card_number')
  21. if (!card_number) {
  22. // 判断是否是从小程序进入
  23. const type = getQueryString('type')
  24. if (type === 'weixin') {
  25. // 跳转回小程序页面授权
  26. jWeixin.miniProgram.reLaunch({ url: '/pages/index/index' })
  27. } else {
  28. getCardnumberURL()
  29. }
  30. } else {
  31. uni.setStorageSync('bus_card_number', card_number)
  32. getUserInfo()
  33. }
  34. }
  35. // 获取用户信息
  36. const getUserInfo = async () => {
  37. const card_number = uni.getStorageSync('bus_card_number')
  38. const res = await myRequest({
  39. url: '/appget_user.action',
  40. data: {
  41. card_number
  42. }
  43. })
  44. // console.log(res);
  45. uni.setStorageSync('bus-userInfo', JSON.stringify(res.data))
  46. // 判断用户权限
  47. if (res.data.user_zz === '教师' || res.data.user_zz === '临时人员') {
  48. uni.switchTab({
  49. url: '/pages/home/home'
  50. })
  51. } else if (res.data.user_zz === '车队长') {
  52. uni.reLaunch({
  53. url: '/pages/record/record'
  54. })
  55. } else if (res.data.user_zz === '司机') {
  56. uni.reLaunch({
  57. url: '/pages/recordDriver/recordDriver'
  58. })
  59. } else {
  60. uni.reLaunch({
  61. url: '/pages/404/404'
  62. })
  63. }
  64. }
  65. // 跳转授权页面
  66. const getCardnumberURL = () => {
  67. 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}`
  68. }
  69. </script>