login2.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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)
  19. if (e.detail.code) {
  20. getPhone(e.detail.code)
  21. } else {
  22. uni.showToast({
  23. title: '授权失败,请选择其他方式登录',
  24. icon: 'none'
  25. })
  26. }
  27. }
  28. // 获取用户手机号码
  29. const getPhone = async (code) => {
  30. const res = await myRequest({
  31. url: '/wanzai/api/wechat/getWechatPhone',
  32. data: {
  33. code
  34. }
  35. })
  36. // console.log(res)
  37. const result = JSON.parse(decryptDes(res.data))
  38. // console.log(result)
  39. let phone = JSON.parse(result).phone
  40. // console.log(phone)
  41. handleLogin(phone)
  42. }
  43. // 登录按钮回调
  44. const handleLogin = (phone) => {
  45. uni.login({
  46. success: (res) => {
  47. // console.log(res)
  48. getBind(res.code, phone)
  49. }
  50. })
  51. }
  52. const getBind = async (wxcode, phone) => {
  53. const res = await myRequest({
  54. url: '/wanzai/api/wechat/vertifyMessage',
  55. data: {
  56. phone,
  57. wxcode,
  58. loginType: 2
  59. }
  60. })
  61. // console.log(res)
  62. const msg = JSON.parse(decryptDes(res.data))
  63. // console.log(msg)
  64. uni.setStorageSync('allData', msg)
  65. if (msg.user.length > 1) {
  66. let info = encodeURIComponent(JSON.stringify(msg))
  67. uni.reLaunch({
  68. url: `/pages/switch/switch?info=${info}`
  69. })
  70. } else {
  71. // 1 代表家长 2 代表学生 3 代表老师
  72. uni.setStorageSync('token', msg.token)
  73. uni.setStorageSync('userhead', msg.user[0].userhead)
  74. uni.setStorageSync('userInfo', msg.user[0])
  75. uni.reLaunch({
  76. url: '/pages/home/home'
  77. })
  78. }
  79. }
  80. // 点击其他登录按钮回调
  81. const handleOther = () => {
  82. uni.navigateTo({
  83. url: '/pages/login/login'
  84. })
  85. }
  86. </script>
  87. <style lang="scss" scoped>
  88. .container {
  89. display: flex;
  90. flex-direction: column;
  91. align-items: center;
  92. min-height: 100vh;
  93. background-color: #f8f8fa;
  94. .img {
  95. margin-top: 44rpx;
  96. width: 515rpx;
  97. height: 515rpx;
  98. }
  99. .title {
  100. width: 515rpx;
  101. font-size: 32rpx;
  102. font-weight: bold;
  103. text-align: center;
  104. }
  105. .text {
  106. margin-top: 20rpx;
  107. width: 515rpx;
  108. font-size: 28rpx;
  109. color: #808080;
  110. text-align: center;
  111. line-height: 40rpx;
  112. }
  113. .btn {
  114. display: flex;
  115. justify-content: center;
  116. align-items: center;
  117. width: 670rpx;
  118. height: 100rpx;
  119. font-size: 32rpx;
  120. border-radius: 8rpx;
  121. }
  122. .fast {
  123. margin-top: 80rpx;
  124. color: #fff;
  125. background-color: #0061ff;
  126. }
  127. .other {
  128. margin-top: 50rpx;
  129. border: 2rpx solid #000;
  130. }
  131. }
  132. </style>