mini-login.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template>
  2. <view class="content">
  3. <view class="bg"></view>
  4. <view class="bg2"></view>
  5. <view class="tips">
  6. <text class="title">登录</text>
  7. <text class="subtitle">欢迎来到醍摩豆家长</text>
  8. </view>
  9. <view class="form-box">
  10. <button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" class="btn">微信一键登录</button>
  11. <view class="other">
  12. <text class="other-text-left">账号密码登录</text>
  13. <text class="other-text-right" style="color:#4169E1;">
  14. 忘记密码
  15. </text>
  16. </view>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. import {
  22. mapMutations,
  23. mapState
  24. } from 'vuex';
  25. import WXBizDataCrypt from "@/utils/WXBizDataCrypt.js";
  26. export default {
  27. name: "mini-login",
  28. data() {
  29. return {
  30. };
  31. },
  32. computed: {
  33. ...mapState('m_parent', ['token'])
  34. },
  35. onLoad() {
  36. },
  37. methods: {
  38. ...mapMutations('m_parent', ['updateParentInfo', 'updateToken', 'updateParentDetail']),
  39. //调用登录接口换取token
  40. async getToken() {
  41. //调用login()拿到code用于换取token
  42. let [err, res] = await uni.login().catch(err => err)
  43. //判断调用是否成功
  44. if (err || res.errMsg !== 'login:ok') return uni.$showMsg('登录失败!')
  45. //准备换取token参数
  46. let query = {
  47. js_code: res.code
  48. }
  49. //传入后台换取token
  50. const loginResult = await uni.$http.post('https://test.teammodel.cn/aclassone/get-miniapp-userinfo', query)
  51. if (loginResult.statusCode !== 200) return uni.$showMsg('登录失败!')
  52. uni.$showMsg('登录成功')
  53. //更新vuex中token
  54. console.log(loginResult.data.miniappData);
  55. this.updateToken(loginResult.data.miniappData)
  56. },
  57. //获取用户手机号
  58. async getPhoneNumber(e) {
  59. await this.getToken()
  60. if (e.detail.errMsg !== "getPhoneNumber:ok") {
  61. //用户决绝授权
  62. return uni.$showMsg('拒绝手机授权,获取不到您的信息!')
  63. } else {
  64. if (this.token) {
  65. let proof = await new WXBizDataCrypt('wx5705da8747c77cfe', this.token.session_key)
  66. let numData = await proof.decryptData(e.detail.encryptedData, e.detail.iv)
  67. console.log(numData.phoneNumber)
  68. // const parentDetailData = await uni.$http.post('',numData.phoneNumber)
  69. // this.updateParentDetail(parentDetailData)
  70. await uni.navigateTo({
  71. url: '/subpkg/guide/guide'
  72. })
  73. }
  74. }
  75. },
  76. },
  77. }
  78. </script>
  79. <style lang="scss">
  80. //登录页面
  81. .content {
  82. width: 100vw;
  83. height: 100vh;
  84. background-color: #fafafa;
  85. z-index: 999;
  86. .tips {
  87. padding-top: 200rpx;
  88. padding-left: 80rpx;
  89. display: flex;
  90. flex-direction: column;
  91. .title {
  92. line-height: 70rpx;
  93. font-weight: bold;
  94. font-size: 50rpx;
  95. }
  96. .subtitle {
  97. line-height: 70rpx;
  98. font-size: 35rpx;
  99. font-weight: bold;
  100. color: #b0b0b1;
  101. }
  102. }
  103. .bg {
  104. position: fixed;
  105. top: -250rpx;
  106. right: -250rpx;
  107. width: 600rpx;
  108. height: 600rpx;
  109. border-radius: 100%;
  110. background-color: #4169E1;
  111. z-index: 2
  112. }
  113. .bg2 {
  114. position: fixed;
  115. top: -150rpx;
  116. right: -300rpx;
  117. width: 600rpx;
  118. height: 600rpx;
  119. border-radius: 100%;
  120. background-color: #6495ed;
  121. z-index: 1;
  122. }
  123. .form-box {
  124. padding-top: 250rpx;
  125. padding-left: 70rpx;
  126. width: 610rpx;
  127. .input-box {
  128. margin: 40rpx 0;
  129. display: flex;
  130. justify-content: flex-start;
  131. align-items: center;
  132. height: 100rpx;
  133. background-color: #f5f5f5;
  134. border-radius: 100rpx;
  135. width: 100%;
  136. input {
  137. flex: 1;
  138. height: 100%;
  139. font-size: 30rpx;
  140. }
  141. .left {
  142. padding: 0 30rpx;
  143. width: 35rpx;
  144. height: 35rpx;
  145. }
  146. .right {
  147. padding: 0 30rpx;
  148. width: 40rpx;
  149. height: 40rpx;
  150. }
  151. }
  152. .btn {
  153. display: flex;
  154. justify-content: center;
  155. align-items: center;
  156. width: 100%;
  157. height: 100rpx;
  158. border-radius: 100rpx;
  159. color: #FFFFFF;
  160. background: linear-gradient(to right, #506AE7, #87CEFA);
  161. text-shadow: 1px 1px 1px rgba(255, 255, 255, 0.1);
  162. box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
  163. margin-top: 30px;
  164. }
  165. .other {
  166. display: flex;
  167. justify-content: space-between;
  168. text {
  169. line-height: 80rpx;
  170. font-size: 28rpx;
  171. }
  172. .other-text-left {
  173. margin-left: 2px;
  174. margin-top: 10px;
  175. }
  176. .other-text-right {
  177. margin-right: 2px;
  178. margin-top: 10px;
  179. }
  180. }
  181. }
  182. }
  183. </style>