mini-login.vue 5.2 KB

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