login.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. //登录页面
  96. .content {
  97. width: 100vw;
  98. height: 100vh;
  99. background-color: #fafafa;
  100. .tips {
  101. padding-top: 200rpx;
  102. padding-left: 80rpx;
  103. display: flex;
  104. flex-direction: column;
  105. z-index: 99;
  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: #b0b0b1;
  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: 480rpx;
  146. width: 600rpx;
  147. height: 600rpx;
  148. border-radius: 100%;
  149. background-color: #FFC600;
  150. z-index: 4;
  151. }
  152. .form-box {
  153. padding-top: 250rpx;
  154. padding-left: 70rpx;
  155. width: 610rpx;
  156. .btn {
  157. display: flex;
  158. justify-content: center;
  159. align-items: center;
  160. width: 100%;
  161. height: 100rpx;
  162. border-radius: 100rpx;
  163. border: none;
  164. color: #FFFFFF;
  165. font-weight: bold;
  166. background: linear-gradient(to right, #506AE7, #87CEFA);
  167. box-shadow: 0 10rpx 20rpx rgba(0, 0, 0, 0.2);
  168. margin-top: 60rpx;
  169. z-index: 99;
  170. }
  171. .other {
  172. display: flex;
  173. justify-content: space-between;
  174. z-index: 99;
  175. text {
  176. line-height: 80rpx;
  177. font-size: 28rpx;
  178. z-index: 99;
  179. }
  180. .other-text-left {
  181. margin-left: 4rpx;
  182. margin-top: 20rpx;
  183. color: #FFFFFF;
  184. font-weight: bold;
  185. }
  186. .other-text-right {
  187. margin-right: 4rpx;
  188. margin-top: 20rpx;
  189. font-weight: bold;
  190. }
  191. }
  192. }
  193. }
  194. .ocean {
  195. display: flex;
  196. margin-top: -600rpx;
  197. margin-left: -520rpx;
  198. width: 1800rpx;
  199. height: 1800rpx;
  200. background-color: #4169E1;
  201. border-radius: 50%;
  202. &::before,
  203. &::after {
  204. content: "";
  205. position: absolute;
  206. margin-top: 870rpx;
  207. width: 1600rpx;
  208. height: 1600rpx;
  209. top: 0;
  210. left: 50%;
  211. border-radius: 43%;
  212. background-color: #FFFFFF;
  213. transform: translate(-50%, -70%) rotate(0);
  214. animation: rotate 6s linear infinite;
  215. z-index: 2;
  216. }
  217. &::after {
  218. border-radius: 46%;
  219. background-color: #FFFFFF;
  220. opacity: 0.7;
  221. transform: translate(-50%, -70%) rotate(0);
  222. animation: rotate 10s linear -5s infinite;
  223. z-index: 3;
  224. }
  225. &::after {
  226. border-radius: 40%;
  227. background-color: #FFFFFF;
  228. opacity: 0.5;
  229. transform: translate(-50%, -70%) rotate(0);
  230. animation: rotate 10s linear -5s infinite;
  231. z-index: 3;
  232. }
  233. }
  234. @keyframes rotate {
  235. 50% {
  236. transform: translate(-50%, -73%) rotate(180deg);
  237. }
  238. 100% {
  239. transform: translate(-50%, -70%) rotate(360deg);
  240. }
  241. }
  242. </style>