auth.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template>
  2. <view style="display: flex;align-items: center;justify-content: center;height: 100vh;">
  3. <!-- <image src="../../static/logo.png" style="width: 90px;height:80px"></image> -->
  4. <tn-loading mode="circle" size="60"></tn-loading>
  5. </view>
  6. </template>
  7. <script>
  8. import request from '../../utils/request'
  9. export default {
  10. data() {
  11. return {
  12. }
  13. },
  14. onLoad(options) {
  15. let that = this;
  16. uni.login({
  17. success(res) {
  18. console.error(res);
  19. that.loginByCode(res.code);
  20. },
  21. fail(res) {
  22. console.error(res);
  23. uni.hideLoading();
  24. }
  25. });
  26. },
  27. methods: {
  28. loginByCode(frontId) {
  29. const that = this;
  30. uni.setStorageSync('loginStatus', 'false');
  31. wx.getUserInfo({
  32. success: function(res) {
  33. console.error(res);
  34. request.post("/slbMpAutoLogin", {
  35. code:frontId,
  36. appType:'ma',
  37. encryptedData:res.encryptedData,
  38. iv: res.iv
  39. }, {
  40. login: false,
  41. warn:false,
  42. loading:false
  43. }).then(res2=>{
  44. console.error(res2);
  45. if(res2.success){
  46. //登录成功
  47. uni.setStorageSync('loginStatus', 'true');
  48. uni.setStorageSync('userMap', JSON.stringify(res2.resultMap));
  49. uni.setStorageSync('userNo', res2.resultMap.accountName);
  50. that.getUserInfo();
  51. }else{
  52. console.error(12345);
  53. uni.setStorageSync('loginStatus', 'false');
  54. uni.removeStorageSync('userMap');
  55. uni.removeStorageSync('userNo');
  56. uni.removeStorageSync('userInfo');
  57. uni.redirectTo({
  58. url:'/pages/index/index'
  59. })
  60. //登录失败,
  61. // uni.login({
  62. // success(res) {
  63. // console.error(res);
  64. // that.getOpenId(res.code);
  65. // },
  66. // fail(res) {
  67. // console.error(res);
  68. // uni.hideLoading();
  69. // }
  70. // });
  71. }
  72. console.error(res2);
  73. });
  74. }
  75. })
  76. },
  77. getUserInfo() {
  78. let that = this;
  79. request.post('/slbWxma/getPersonlInfo', {
  80. }).then(res => {
  81. console.warn(res);
  82. if(res.success){
  83. that.personInfo = res.resultMap.userInfo||{};
  84. uni.setStorageSync('userInfo', JSON.stringify(res.resultMap.userInfo));
  85. uni.redirectTo({
  86. url:'/pages/index/index'
  87. })
  88. }
  89. console.warn(res);
  90. })
  91. },
  92. }
  93. }
  94. </script>
  95. <style>
  96. </style>