index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <view class="login" :style="{ 'height': setHeight + 'px' }">
  3. <view class="logo">
  4. <image src="../../../static/images/logo.png"></image>
  5. <view>登录巴巴礼品网</view>
  6. </view>
  7. <div class="form">
  8. <form @submit.prevent="submit">
  9. <div class="item">
  10. <div class="acea-row row-middle">
  11. <image src="../../../static/images/phone_1.png"></image>
  12. <input type="text" placeholder="请输入绑定的手机号" placeholder-class="placeholder" v-model="userName" required />
  13. </div>
  14. </div>
  15. <div class="item">
  16. <div class="acea-row row-middle">
  17. <image src="../../../static/images/code_2.png"></image>
  18. <input type="password" placeholder="请输入登录密码" placeholder-class="placeholder" v-model="password" required />
  19. </div>
  20. </div>
  21. </form>
  22. <view class="goto">
  23. <navigator hover-class="none" url="/pages/users/retrievePassword/index">
  24. 忘记密码?
  25. </navigator>
  26. <navigator class="zhuce" hover-class="none" url="/pages/users/register/index">
  27. 注册账号
  28. </navigator>
  29. </view>
  30. <view class="btn" @click="submit">登录</view>
  31. <navigator class="return" hover-class="none" url="/pages/index/index" open-type='switchTab'>继续浏览<text class="iconfont icon-jiantou"></text></navigator>
  32. </div>
  33. </view>
  34. </template>
  35. <script>
  36. import {
  37. loginApi
  38. } from '@/api/api.js';
  39. const BACK_URL = "login_back_url";
  40. export default {
  41. data() {
  42. return {
  43. setHeight: 0,
  44. userName: '',
  45. password: ''
  46. }
  47. },
  48. mounted() {
  49. let that = this
  50. uni.getSystemInfo({
  51. success: function (res) {
  52. that.setHeight = res.windowHeight
  53. }
  54. })
  55. try {
  56. that.userName = uni.getStorageSync('account');
  57. that.password = uni.getStorageSync('password');
  58. } catch (e) {
  59. // error
  60. }
  61. },
  62. methods: {
  63. async submit() {
  64. let that = this;
  65. if (!that.userName) return that.$util.Tips({
  66. title: '请填写账号'
  67. });
  68. if (!/^[\w\d]{5,16}$/i.test(that.userName)) return that.$util.Tips({
  69. title: '请输入正确的账号'
  70. });
  71. if (!that.password) return that.$util.Tips({
  72. title: '请填写密码'
  73. });
  74. loginApi({
  75. check: true,
  76. userName: that.userName,
  77. passWord: that.password
  78. }).then(res => {
  79. that.$store.commit("LOGIN", {
  80. 'token': res.data.token,
  81. 'time': 2592000
  82. });
  83. try {
  84. uni.setStorageSync('account', that.userName);
  85. uni.setStorageSync('password', that.password);
  86. } catch {}
  87. that.$store.commit("UPDATE_USERINFO", res.data.user_info);
  88. const backUrl = that.$Cache.get(BACK_URL) || "/pages/index/index";
  89. that.$Cache.clear(BACK_URL);
  90. if (backUrl === '/pages/index/index' || backUrl === '/pages/users/purchase/index' || backUrl ===
  91. '/pages/my/index') {
  92. uni.switchTab({
  93. url: backUrl
  94. });
  95. } else {
  96. uni.switchTab({
  97. url: '/pages/index/index'
  98. });
  99. }
  100. }).catch(err => {
  101. that.$util.Tips({
  102. title: err
  103. });
  104. });
  105. }
  106. }
  107. }
  108. </script>
  109. <style scoped lang="scss">
  110. .login{
  111. padding-top: 200rpx;
  112. background: #fff;
  113. }
  114. .logo{
  115. text-align: center;
  116. image{
  117. width:140rpx;
  118. height:140rpx;
  119. }
  120. view{
  121. font-size: 32rpx;
  122. font-weight: 700;
  123. letter-spacing: 10rpx;
  124. color:#262626;
  125. }
  126. }
  127. .form{
  128. padding: 40rpx;
  129. .item {
  130. border-bottom: 1rpx solid #ededed;
  131. padding: 45rpx 0 20rpx 0;
  132. image{
  133. width:40rpx;
  134. height:40rpx;
  135. margin-right: 20rpx;
  136. }
  137. input{
  138. flex-grow: 1;
  139. }
  140. .placeholder{
  141. color:#ccc;
  142. }
  143. }
  144. .goto{
  145. display: flex;
  146. justify-content: space-between;
  147. margin-top: 45rpx;
  148. color:#666;
  149. .zhuce{
  150. color:#ff5c00;
  151. }
  152. }
  153. .btn{
  154. font-size: 35rpx;
  155. color: #fff;
  156. height: 86rpx;
  157. border-radius: 40rpx;
  158. background: linear-gradient(90deg,#f35447 0,#ff8e3c);
  159. text-align: center;
  160. line-height: 86rpx;
  161. margin-top: 70rpx;
  162. }
  163. .return{
  164. color:#666;
  165. text-align: right;
  166. margin-top: 30rpx;
  167. .iconfont{
  168. font-size: 23rpx;
  169. }
  170. }
  171. }
  172. </style>