login.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <template>
  2. <view class="content">
  3. <view class="title-img">
  4. <image src="../../static/img/logo.png" mode=""></image>
  5. </view>
  6. <view class="title-LOGO">
  7. 艺绘
  8. </view>
  9. <view class="bg">
  10. <image src="../../static/img/pbbg.png" mode=""></image>
  11. </view>
  12. <view class="register-content">
  13. <view class="res-box">
  14. <image src="../../static/img/pb03.png" mode=""></image>
  15. <input class="input" type="number" v-model="phone" placeholder="请输入手机号">
  16. </view>
  17. <view class="res-box">
  18. <image src="../../static/img/pb02.png" mode=""></image>
  19. <input class="input" type="password" v-model="loginPass" placeholder="请输入密码">
  20. </view>
  21. <!-- <view class="res-box">
  22. <image src="../../static/public/pb01.png" mode=""></image>
  23. <input class="input" type="number" v-model="code" placeholder="请输入验证码">
  24. </view> -->
  25. </view>
  26. <view class="button" @click="registerTo">
  27. 登录
  28. </view>
  29. <view class="tishi">
  30. <view class="for-pass" @click="getNavto('/pages/set/changePass')">
  31. 忘记密码
  32. </view>
  33. <view class="ss">
  34. </view>
  35. <view class="for-phone" @click="getNavto('/pages/public/register')">
  36. 账号注册
  37. </view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. import {
  43. mapMutations
  44. } from 'vuex';
  45. import {
  46. getUserInfo
  47. } from '@/api/user.js';
  48. import {
  49. register,
  50. verify,
  51. login
  52. } from '@/api/login.js';
  53. export default {
  54. data() {
  55. return {
  56. phone: '', //用户
  57. loginPass: '', //密码
  58. payPass: '',
  59. invitation: '', //邀请码
  60. code: '', //验证码
  61. time: '', //保存倒计时对象
  62. countDown: 0 //倒计时
  63. };
  64. },
  65. onLoad() {
  66. // 获取扫码邀请人id
  67. this.invitation = uni.getStorageSync('spread') || '';
  68. },
  69. // computed: {
  70. // ...mapMutations('user', ['setUserInfo', 'login']),
  71. // },
  72. methods: {
  73. ...mapMutations('user', ['setUserInfo', 'login']),
  74. //跳转详情
  75. getNavto(url) {
  76. uni.navigateTo({
  77. url: url
  78. })
  79. },
  80. //登录
  81. registerTo() {
  82. let obj = this
  83. let jiaoyan = /^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/
  84. if (!jiaoyan.test(obj.phone)) {
  85. this.$api.msg('请输入正确的手机号!')
  86. return
  87. } else if (obj.phone == '') {
  88. this.$api.msg('请输入手机号')
  89. return
  90. } else if (obj.loginPass == '') {
  91. this.$api.msg('请输入密码')
  92. return
  93. } else {
  94. login({
  95. account: obj.phone,
  96. password: obj.loginPass
  97. }).then(res => {
  98. console.log(res, 'res');
  99. //传入账号密码之后,登录接口会返回给我一个登陆时间以及token,我把存到本地缓存里
  100. //然后获取用户信息接口,缓存接口给我的data,然后跳转至首页即可
  101. uni.setStorageSync('token', res.data.token)
  102. getUserInfo({}).then(res => {
  103. // console.log(res, 'res');
  104. obj.login(); //确认登录状态
  105. console.log(obj.login);
  106. console.log('18252757278','w');
  107. //用户数据获取到的用户信息存储到本地里
  108. obj.setUserInfo(res.data);
  109. let ur = uni.getStorageSync('present') || '/pages/index/index';
  110. uni.switchTab({
  111. url: '/pages/index/index',
  112. fail(e) {
  113. uni.navigateTo({
  114. url: ur,
  115. fail(e) {
  116. uni.navigateTo({
  117. url: '/pages/index/index',
  118. });
  119. }
  120. });
  121. }
  122. })
  123. })
  124. }).catch(function(e) {
  125. console.log(e);
  126. });
  127. }
  128. },
  129. }
  130. };
  131. </script>
  132. <style lang="scss">
  133. page,
  134. .content {
  135. min-height: 100%;
  136. background-color: #181818;
  137. .bg {
  138. width: 750rpx;
  139. height: 200rpx;
  140. image {
  141. width: 100%;
  142. height: 100%;
  143. }
  144. }
  145. .title-img {
  146. margin: 70rpx auto 0;
  147. width: 161px;
  148. height: 161px;
  149. border-radius: 50%;
  150. overflow: hidden;
  151. image {
  152. width: 100%;
  153. height: 100%;
  154. }
  155. }
  156. .title-LOGO {
  157. text-align: center;
  158. margin: 30rpx;
  159. font-size: 36px;
  160. font-family: PingFang SC;
  161. font-weight: 400;
  162. color: #FFFFFF;
  163. }
  164. .register-content {
  165. .res-box {
  166. height: 110rpx;
  167. align-items: center;
  168. display: flex;
  169. margin: 0 75rpx;
  170. border-bottom: #f3f3f3 solid 2rpx;
  171. image {
  172. width: 31rpx;
  173. height: 40rpx;
  174. }
  175. .input {
  176. flex-grow: 1;
  177. color: #9F570E;
  178. margin-left: 40rpx;
  179. }
  180. }
  181. }
  182. .button {
  183. margin: 40rpx auto;
  184. text-align: center;
  185. width: 452rpx;
  186. height: 90rpx;
  187. background: $bgBaseBg;
  188. border-radius: 45rpx;
  189. font-size: 34rpx;
  190. font-weight: 500;
  191. color: #9F570E;
  192. line-height: 90rpx;
  193. }
  194. .tishi {
  195. display: flex;
  196. align-items: center;
  197. justify-content: center;
  198. .for-pass {
  199. font-size: 28rpx;
  200. font-weight: 500;
  201. color: #FFFFFF;
  202. }
  203. .ss {
  204. height: 26rpx;
  205. width: 3rpx;
  206. background-color: #f3f3f3;
  207. margin: 0 10rpx;
  208. }
  209. .for-phone {
  210. font-size: 28rpx;
  211. font-weight: 500;
  212. color: #FFFFFF;
  213. }
  214. }
  215. }
  216. </style>