index.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 = uni.getStorageSync('bus_card_number')
  21. if (!card_number) {
  22. const card_number = getQueryString('card_number')
  23. if (!card_number) {
  24. // 兼容小程序
  25. const type = getQueryString('type')
  26. if (type === 'weixin') {
  27. // 跳转回小程序页面
  28. jWeixin.miniProgram.reLaunch({ url: '/pages/index/index' })
  29. } else {
  30. getCardnumberURL()
  31. }
  32. } else {
  33. uni.setStorageSync('bus_card_number', card_number)
  34. getUserInfo()
  35. }
  36. } else {
  37. getUserInfo()
  38. }
  39. }
  40. // 获取用户信息
  41. const getUserInfo = async () => {
  42. const card_number = uni.getStorageSync('bus_card_number')
  43. const res = await myRequest({
  44. url: '/appget_user.action',
  45. data: {
  46. card_number
  47. }
  48. })
  49. // console.log(res);
  50. uni.setStorageSync('bus-userInfo', JSON.stringify(res.data))
  51. // 判断用户权限
  52. if (res.data.user_zz === '教师' || res.data.user_zz === '临时人员') {
  53. uni.switchTab({
  54. url: '/pages/home/home'
  55. })
  56. } else if (res.data.user_zz === '车队长') {
  57. uni.reLaunch({
  58. url: '/pages/record/record'
  59. })
  60. } else if (res.data.user_zz === '司机') {
  61. uni.reLaunch({
  62. url: '/pages/recordDriver/recordDriver'
  63. })
  64. } else {
  65. uni.reLaunch({
  66. url: '/pages/404/404'
  67. })
  68. }
  69. }
  70. // 跳转授权页面
  71. const getCardnumberURL = () => {
  72. 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}`
  73. }
  74. </script>