index.vue 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <template>
  2. <view>
  3. <!-- 登陆拦截页面 -->
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. data() {
  9. return {}
  10. },
  11. onLoad() {
  12. // let identity = uni.getStorageSync("identity");
  13. // let updataMsg = uni.getStorageSync("updataMsg");
  14. console.log('dgfskjdblail验证')
  15. this.loginFilter() //获取token
  16. },
  17. methods: {
  18. //获取token
  19. loginFilter() {
  20. let cardNumber = this.getQueryString('cardNumber')
  21. let error = this.getQueryString('error')
  22. let errorMsg = this.getQueryString('errorMsg')
  23. //此为微校授权地址
  24. let weixinUrl = `https://open.wecard.qq.com/connect/oauth/authorize?app_key=EE28EE2C93296F4E&response_type=code&scope=snsapi_base&ocode=1015730314&redirect_uri=https://jtishfw.ncjti.edu.cn/baoxiu/repairApi/wx/getCardNumber&state=STATE`
  25. if (error) {
  26. //微校服务器报错提示框
  27. uni.showToast({
  28. title: errorMsg,
  29. icon: 'error',
  30. mask: true,
  31. duration: 1000,
  32. })
  33. } else if (!cardNumber) {
  34. window.location.href = weixinUrl
  35. } else {
  36. uni.setStorageSync('token', cardNumber)
  37. uni.setStorageSync('identity', JSON.stringify(0)) //身份标识
  38. this.getDetailMess() //获取学生详细信息
  39. }
  40. },
  41. //获取当前URL指定参数
  42. getQueryString(name) {
  43. let url = window.location.href // 获取URL
  44. let pattern = new RegExp('[?&]' + name + '=([^&]+)', 'i') // 正则匹配URL
  45. let matcher = pattern.exec(url)
  46. if (matcher == null || matcher.length < 1) {
  47. return false
  48. }
  49. return decodeURIComponent(matcher[1]) // 输出指定的参数值中文也可以
  50. },
  51. //换取详情信息
  52. async getDetailMess() {
  53. let res = await this.$myRequest({
  54. method: 'post',
  55. url: `/student/queryByStudentId`,
  56. })
  57. // console.log(res)
  58. if (res.status == 200) {
  59. uni.setStorageSync('student', res.data)
  60. let updataMsg = uni.getStorageSync('updataMsg')
  61. if (updataMsg) {
  62. console.log('主页')
  63. uni.reLaunch({
  64. url: '../home/home',
  65. })
  66. } else {
  67. console.log('信息页')
  68. uni.reLaunch({
  69. url: '../personal-information/personal-information',
  70. })
  71. }
  72. }
  73. },
  74. },
  75. }
  76. </script>
  77. <style lang="scss"></style>