login.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <template>
  2. <view>
  3. <!-- 登录 -->
  4. <view class="content">
  5. <view class="bg1"></view>
  6. <view class="bg2"></view>
  7. <view class="bg3"></view>
  8. <view class="tips">
  9. <text class="title">登录</text>
  10. <text class="subtitle">欢迎来到醍摩豆家长</text>
  11. </view>
  12. <view class="form-box">
  13. <button @click="$noMultipleClicks(getUserInfo)" class="btn" plain="true">微信一键登录</button>
  14. <view class="other">
  15. <text class="other-text-left">账号密码登录</text>
  16. <text class="other-text-right" style="color:#4169E1;">
  17. 忘记密码
  18. </text>
  19. </view>
  20. </view>
  21. </view>
  22. <!-- 动画 -->
  23. <view class="ocean"></view>
  24. </view>
  25. </template>
  26. <script>
  27. import {
  28. mapMutations,
  29. mapState
  30. } from 'vuex';
  31. export default {
  32. data() {
  33. return {
  34. query: {},
  35. //是否正在点击
  36. noClick: true
  37. };
  38. },
  39. computed: {
  40. ...mapState('m_parent', ['token'])
  41. },
  42. onLoad() {
  43. },
  44. onShow() {
  45. this.getCode()
  46. },
  47. methods: {
  48. ...mapMutations('m_parent', ['updateParentInfo', 'updateToken']),
  49. //换取code方法
  50. async getCode() {
  51. //调用login()拿到code用于换取token
  52. let [err, res] = await uni.login().catch(err => err)
  53. //判断调用是否成功
  54. if (err || res.errMsg !== 'login:ok') return uni.$showMsg('登录失败!')
  55. //准备换取token参数
  56. this.query = {
  57. js_code: res.code
  58. }
  59. },
  60. //调用登录接口换取token
  61. async getToken() {
  62. //传入后台换取token
  63. const loginResult = await uni.$http.post('https://test.teammodel.cn/aclassone/get-miniapp-userinfo',
  64. this.query)
  65. if (loginResult.statusCode !== 200) return uni.$showMsg('登录失败!')
  66. uni.$showMsg('登录成功')
  67. //更新vuex中token
  68. console.log(loginResult.data.miniappData);
  69. this.updateToken(loginResult.data.miniappData)
  70. },
  71. //获取用户信息事件
  72. async getUserInfo() {
  73. await uni.getUserProfile({
  74. desc: '获取您的基本信息',
  75. success: infoRes => {
  76. if (infoRes.errMsg === 'getUserProfile:ok') {
  77. this.getToken()
  78. this.updateParentInfo(infoRes.userInfo)
  79. uni.redirectTo({
  80. url: '/subpkg/guide/guide'
  81. })
  82. } else {
  83. uni.$showMsg('获取不到您的信息!')
  84. }
  85. },
  86. fail: err => {
  87. uni.$showMsg('拒绝授权获取不到您的基本信息!')
  88. }
  89. });
  90. },
  91. },
  92. }
  93. </script>
  94. <style lang="scss">
  95. @import '@/subpkg/common/ocean.scss';
  96. //登录页面
  97. .content {
  98. width: 100vw;
  99. height: 100vh;
  100. background-color: #FFFFFF;
  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. z-index: 99;
  111. }
  112. .subtitle {
  113. line-height: 70rpx;
  114. font-size: 35rpx;
  115. font-weight: bold;
  116. color: $color-subtitle;
  117. z-index: 99;
  118. }
  119. }
  120. .bg1 {
  121. position: fixed;
  122. top: -250rpx;
  123. right: -280rpx;
  124. width: 650rpx;
  125. height: 650rpx;
  126. border-radius: 100%;
  127. background-color: #4169E1;
  128. margin-right: 20rpx;
  129. z-index: 5;
  130. }
  131. .bg2 {
  132. position: fixed;
  133. top: -100rpx;
  134. right: -320rpx;
  135. width: 630rpx;
  136. height: 630rpx;
  137. border-radius: 100%;
  138. margin-top: 40rpx;
  139. background-color: #ff5959;
  140. z-index: 4;
  141. }
  142. .bg3 {
  143. position: fixed;
  144. top: 500rpx;
  145. right: 450rpx;
  146. width: 600rpx;
  147. height: 600rpx;
  148. border-radius: 100%;
  149. background-color: #FFC600;
  150. z-index: 4;
  151. }
  152. .form-box {
  153. margin-top: 400rpx;
  154. width: 100%;
  155. .btn {
  156. line-height: 100rpx;
  157. height: 100rpx;
  158. width: 80%;
  159. font-weight: bold;
  160. font-size: 36rpx;
  161. color: #FFFFFF;
  162. border-radius: 100rpx;
  163. position: relative;
  164. margin: 0 auto;
  165. border: none;
  166. background: linear-gradient(to right, #506AE7, #87CEFA);
  167. box-shadow: 0 10rpx 20rpx rgba(0, 0, 0, 0.1);
  168. z-index: 99;
  169. }
  170. //字体按钮
  171. .other {
  172. display: flex;
  173. justify-content: space-between;
  174. position: relative;
  175. margin: 0 auto;
  176. width: 80%;
  177. text {
  178. line-height: 80rpx;
  179. font-size: 28rpx;
  180. z-index: 99;
  181. }
  182. .other-text-left {
  183. margin-left: 4rpx;
  184. margin-top: 20rpx;
  185. color: #FFFFFF;
  186. font-weight: bold;
  187. }
  188. .other-text-right {
  189. margin-right: 4rpx;
  190. margin-top: 20rpx;
  191. font-weight: bold;
  192. }
  193. }
  194. }
  195. }
  196. </style>