login2.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <view class="container">
  3. <!-- 图片区域 -->
  4. <img class="img" src="@/static/images/1.png" />
  5. <!-- 文字区域 -->
  6. <view class="title">在校生活、高效管理</view>
  7. <view class="text">辅助老师进行教务工作,家长全面了解在校活动,保障孩子在校安全</view>
  8. <!-- 按钮区域 -->
  9. <button class="btn fast" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">快捷登录</button>
  10. <view class="btn other" @click="handleOther">其他登录</view>
  11. </view>
  12. </template>
  13. <script setup>
  14. import { myRequest } from '@/utils/api.js'
  15. import { decryptDes } from '@/utils/des.js'
  16. // 点击快捷登录按钮回调
  17. const getPhoneNumber = (e) => {
  18. // console.log(e.detail.code)
  19. getPhone(e.detail.code)
  20. }
  21. // 获取用户手机号码
  22. const getPhone = async (code) => {
  23. const res = await myRequest({
  24. url: '/wanzai/api/wechat/getWechatPhone',
  25. data: {
  26. code
  27. }
  28. })
  29. // console.log(res)
  30. const result = JSON.parse(decryptDes(res.data))
  31. // console.log(result)
  32. let phone = JSON.parse(result).phone
  33. // console.log(phone)
  34. handleLogin(phone)
  35. }
  36. // 登录按钮回调
  37. const handleLogin = (phone) => {
  38. uni.login({
  39. success: (res) => {
  40. // console.log(res)
  41. getBind(res.code, phone)
  42. }
  43. })
  44. }
  45. const getBind = async (wxcode, phone) => {
  46. const res = await myRequest({
  47. url: '/wanzai/api/wechat/vertifyMessage',
  48. data: {
  49. phone,
  50. wxcode,
  51. loginType: 2
  52. }
  53. })
  54. // console.log(res)
  55. const msg = JSON.parse(decryptDes(res.data))
  56. // console.log(msg)
  57. uni.setStorageSync('allData', msg)
  58. if (msg.user.length > 1) {
  59. let info = encodeURIComponent(JSON.stringify(msg))
  60. uni.redirectTo({
  61. url: `/pages/switch/switch?info=${info}`
  62. })
  63. } else {
  64. // 1 代表家长 2 代表学生 3 代表老师
  65. uni.setStorageSync('token', msg.token)
  66. uni.setStorageSync('userhead', msg.user[0].userhead)
  67. uni.setStorageSync('userInfo', msg.user[0])
  68. uni.redirectTo({
  69. url: '/pages/home/home'
  70. })
  71. }
  72. }
  73. // 点击其他登录按钮回调
  74. const handleOther = () => {
  75. uni.navigateTo({
  76. url: '/pages/login/login'
  77. })
  78. }
  79. </script>
  80. <style lang="scss" scoped>
  81. .container {
  82. display: flex;
  83. flex-direction: column;
  84. align-items: center;
  85. min-height: 100vh;
  86. background-color: #f8f8fa;
  87. .img {
  88. margin-top: 44rpx;
  89. width: 515rpx;
  90. height: 515rpx;
  91. }
  92. .title {
  93. width: 515rpx;
  94. font-size: 32rpx;
  95. font-weight: bold;
  96. text-align: center;
  97. }
  98. .text {
  99. margin-top: 20rpx;
  100. width: 515rpx;
  101. font-size: 28rpx;
  102. color: #808080;
  103. text-align: center;
  104. line-height: 40rpx;
  105. }
  106. .btn {
  107. display: flex;
  108. justify-content: center;
  109. align-items: center;
  110. width: 670rpx;
  111. height: 100rpx;
  112. font-size: 32rpx;
  113. border-radius: 8rpx;
  114. }
  115. .fast {
  116. margin-top: 80rpx;
  117. color: #fff;
  118. background-color: #0061ff;
  119. }
  120. .other {
  121. margin-top: 50rpx;
  122. border: 2rpx solid #000;
  123. }
  124. }
  125. </style>