mini-login.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. <view class="input-box">
  11. <image class="left"
  12. src="../../static/components-icons/user.png">
  13. </image>
  14. <input placeholder="请输入手机号" />
  15. <image class="right"
  16. src="../../static/components-icons/pull-down.png">
  17. </image>
  18. </view>
  19. <view class="input-box">
  20. <image class="left"
  21. src="../../static/components-icons/password.png">
  22. </image>
  23. <input placeholder="请输入密码" password="true" />
  24. <image class="right"
  25. src="../../static/components-icons/eyes.png">
  26. </image>
  27. </view>
  28. <view class="btn">登录</view>
  29. <view class="other">
  30. <text>修改密码</text>
  31. <text @click="getUserInfo" style="color:#4169E1;">
  32. 微信一键登录
  33. </text>
  34. </view>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import {mapMutations, mapState} from 'vuex'
  40. export default {
  41. name:"mini-login",
  42. data() {
  43. return {
  44. };
  45. },
  46. computed:{
  47. },
  48. methods:{
  49. ...mapMutations('m_parent',['updateParentInfo','updateToken']),
  50. //取得用户授权获取用户信息
  51. getUserInfo(){
  52. uni.getUserProfile({
  53. desc:'获取您的昵称,头像,地区信息',
  54. success: infoRes => {
  55. if(infoRes.errMsg === 'getUserProfile:ok'){
  56. this.updateParentInfo(infoRes.userInfo)
  57. console.log(infoRes)
  58. this.getToken(infoRes)
  59. }else{
  60. uni.$showMsg('授权失败')
  61. }
  62. },
  63. fail: err => {
  64. console.log('getUserInfo-error', JSON.stringify(err));
  65. }
  66. });
  67. },
  68. //调用登录接口换取token
  69. async getToken(info){
  70. //调用login()拿到code用于换取token
  71. const [err,res] = await uni.login().catch(err => err)
  72. console.log(res)
  73. //判断调用是否成功
  74. if (err || res.errMsg !== 'login:ok') return uni.$showMsg('登录失败!')
  75. //准备换取token参数
  76. const query = {
  77. code: res.code,
  78. encryptedData: info.encryptedData,
  79. iv: info.iv,
  80. rawData: info.rawData,
  81. signature: info.signature
  82. }
  83. console.log(query)
  84. //传入后台换取token
  85. const {data:loginResult} = await uni.$http.post('https://api-hmugo-web.itheima.net/api/public/v1/users/wxlogin',query)
  86. if(loginResult.meta.status !== 200) return uni.$showMsg('登录失败!')
  87. uni.$showMsg('登录成功')
  88. //更新vuex中token
  89. this.updateToken(loginResult.message.token)
  90. }
  91. },
  92. }
  93. </script>
  94. <style lang="scss">
  95. //登录页面
  96. .content {
  97. width: 100vw;
  98. height: 100vh;
  99. background-color: #ffffff;
  100. z-index: 999;
  101. .tips {
  102. padding-top: 200rpx;
  103. padding-left: 80rpx;
  104. display: flex;
  105. flex-direction: column;
  106. .title {
  107. line-height: 70rpx;
  108. font-weight: bold;
  109. font-size: 50rpx;
  110. }
  111. .subtitle {
  112. line-height: 70rpx;
  113. font-size: 35rpx;
  114. font-weight: bold;
  115. color: #b0b0b1;
  116. }
  117. }
  118. .bg {
  119. position: fixed;
  120. top: -250rpx;
  121. right: -250rpx;
  122. width: 600rpx;
  123. height: 600rpx;
  124. border-radius: 100%;
  125. background-color: #4169E1;
  126. z-index: 2
  127. }
  128. .bg2 {
  129. position: fixed;
  130. top: -150rpx;
  131. right: -300rpx;
  132. width: 600rpx;
  133. height: 600rpx;
  134. border-radius: 100%;
  135. background-color: #00baef;
  136. z-index: 1;
  137. }
  138. .form-box {
  139. padding-top: 180rpx;
  140. padding-left: 70rpx;
  141. width: 610rpx;
  142. .input-box {
  143. margin: 40rpx 0;
  144. display: flex;
  145. justify-content: flex-start;
  146. align-items: center;
  147. height: 100rpx;
  148. background-color: #f5f5f5;
  149. border-radius: 100rpx;
  150. width: 100%;
  151. input {
  152. flex: 1;
  153. height: 100%;
  154. font-size: 30rpx;
  155. }
  156. .left {
  157. padding: 0 30rpx;
  158. width: 35rpx;
  159. height: 35rpx;
  160. }
  161. .right {
  162. padding: 0 30rpx;
  163. width: 40rpx;
  164. height: 40rpx;
  165. }
  166. }
  167. .btn {
  168. display: flex;
  169. justify-content: center;
  170. align-items: center;
  171. width: 100%;
  172. height: 100rpx;
  173. border-radius: 100rpx;
  174. color: #FFFFFF;
  175. background: linear-gradient(to right, #506AE7, #ade8f9);
  176. text-shadow: 1px 1px 1px rgba(255,255,255, .1);
  177. box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
  178. }
  179. .other {
  180. display: flex;
  181. justify-content: space-between;
  182. text {
  183. line-height: 80rpx;
  184. font-size: 28rpx;
  185. }
  186. }
  187. }
  188. }
  189. </style>