LoginFilter.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <template>
  2. <view>
  3. <!-- 登陆拦截页面 -->
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. data() {
  9. return {
  10. };
  11. },
  12. onLoad() {
  13. // let identity = uni.getStorageSync("identity");
  14. // let updataMsg = uni.getStorageSync("updataMsg");
  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 =
  25. `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`;
  26. if (error) {
  27. //微校服务器报错提示框
  28. uni.showToast({
  29. title: errorMsg,
  30. icon: "error",
  31. mask: true,
  32. duration: 1000,
  33. });
  34. } else if (!cardNumber) {
  35. window.location.href = weixinUrl;
  36. } else {
  37. uni.setStorageSync('token', cardNumber);
  38. uni.setStorageSync('identity', JSON.stringify(0)); //身份标识
  39. this.getDetailMess(); //获取学生详细信息
  40. }
  41. },
  42. //获取当前URL指定参数
  43. getQueryString(name) {
  44. let url = window.location.href; // 获取URL
  45. let pattern = new RegExp("[?&]" + name + "=([^&]+)", "i"); // 正则匹配URL
  46. let matcher = pattern.exec(url);
  47. if (matcher == null || matcher.length < 1) {
  48. return false;
  49. }
  50. return decodeURIComponent(matcher[1]); // 输出指定的参数值中文也可以
  51. },
  52. //换取详情信息
  53. async getDetailMess() {
  54. let res = await this.$myRequest({
  55. method: "post",
  56. url: `/student/queryByStudentId`,
  57. })
  58. // console.log(res)
  59. if (res.status == 200) {
  60. uni.setStorageSync('student', res.data);
  61. let updataMsg = uni.getStorageSync('updataMsg');
  62. if (updataMsg) {
  63. console.log("主页")
  64. uni.reLaunch({
  65. url: '../index/index'
  66. })
  67. } else {
  68. console.log("信息页")
  69. uni.reLaunch({
  70. url: '../personal-information/personal-information'
  71. })
  72. }
  73. }
  74. }
  75. }
  76. }
  77. </script>
  78. <style lang="scss"></style>