login.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <!-- 登录注册 -->
  3. <view>
  4. <view class="card_login">
  5. <view class="card_head_logo">
  6. <image class="mine_image" src="../static/logo.png" mode=""></image>
  7. <view class="welcome_title">欢迎登录宝智达气瓶</view>
  8. </view>
  9. <view class="login_input_box">
  10. <u--input v-model="formList.account" fontSize="18px" placeholder="请输入账号" border="bottom"
  11. clearable></u--input>
  12. </view>
  13. <view class="login_input_box">
  14. <u--input v-model="formList.password" fontSize="18px" placeholder="请输入密码" password border="bottom"
  15. clearable></u--input>
  16. </view>
  17. <view class="card_hint">
  18. <view class="card_checkbox">
  19. <u-checkbox-group @change="checkboxChange">
  20. <u-checkbox name="asgas" shape="circle"></u-checkbox>
  21. </u-checkbox-group>
  22. <span class="message" :style="{display:hintShow ? 'block' : 'none'}">
  23. 请先阅读并同意协议
  24. </span>
  25. </view>
  26. <view class="agreement_title">我已阅读并同意<span class="protocol_title">《用户协议》</span>、<span
  27. class="protocol_title">《隐私政策》</span>,
  28. 并授权宝智达气瓶使用该宝智达气瓶账号信息(如昵称、头像、收货地址)进行统一管理
  29. </view>
  30. </view>
  31. <view class="card_btn">
  32. <u-button type="primary" :disabled="disabled" text="登录" @click="getLogin"></u-button>
  33. </view>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. export default {
  39. data() {
  40. return {
  41. formList: {
  42. account: '',
  43. password: '',
  44. },
  45. checked: false,
  46. hintShow: false,
  47. userInfo: {},
  48. }
  49. },
  50. computed: {
  51. disabled() {
  52. if (this.formList.account == '' || this.formList.password == '') {
  53. return true;
  54. } else {
  55. return false;
  56. }
  57. }
  58. },
  59. // beforeCreate() {
  60. // var token = this.$cache.getToken()
  61. // if (token) {
  62. // uni.redirectTo({
  63. // url: '/pages/indexRouter'
  64. // })
  65. // }
  66. // },
  67. methods: {
  68. checkboxChange() {
  69. if (this.checked) {
  70. this.checked = false
  71. } else {
  72. this.checked = true
  73. this.hintShow = false
  74. }
  75. },
  76. getLogin() {
  77. if (!this.checked) {
  78. this.hintShow = true
  79. } else {
  80. uni.showLoading({
  81. title: '登录中...'
  82. });
  83. this.$api.post('/api/login', {
  84. type: 1,
  85. mobile: true,
  86. username: this.formList.account,
  87. password: this.formList.password
  88. }).then((res) => {
  89. if (res.code == 200) {
  90. this.$cache.setToken(res.token)
  91. this.getUserInfo()
  92. } else {
  93. uni.showToast({
  94. title: res.data.msg,
  95. icon: 'none'
  96. });
  97. }
  98. uni.hideLoading();
  99. })
  100. }
  101. },
  102. getUserInfo() {
  103. this.$api.get('/api/user/profile').then(res => {
  104. if (res.code == 200) {
  105. this.userInfo = res.data.user
  106. this.$cache.setCache('userInfo', this.userInfo)
  107. uni.redirectTo({
  108. url: '/pages/indexRouter'
  109. })
  110. } else {
  111. uni.showToast({
  112. title: '当前用户不存在',
  113. icon: 'none'
  114. });
  115. }
  116. })
  117. }
  118. }
  119. }
  120. </script>
  121. <style lang="scss" scoped>
  122. .welcome_title {
  123. font-size: 46rpx;
  124. font-weight: 600;
  125. margin-bottom: 60rpx;
  126. margin-top: 10rpx;
  127. }
  128. .card_head_logo {
  129. margin-top: 50rpx;
  130. display: flex;
  131. flex-direction: column;
  132. justify-content: center;
  133. align-items: center;
  134. }
  135. .card_login {
  136. padding: 20rpx 40rpx;
  137. }
  138. .mine_image {
  139. width: 100rpx;
  140. height: 100rpx;
  141. }
  142. .login_input_box {
  143. margin-bottom: 30rpx;
  144. }
  145. .card_hint {
  146. margin-top: 100rpx;
  147. display: flex;
  148. align-items: flex-start;
  149. }
  150. .agreement_title {
  151. font-size: 30rpx;
  152. color: #333;
  153. }
  154. .protocol_title {
  155. color: #1177ff;
  156. }
  157. .card_btn {
  158. margin-top: 20rpx;
  159. }
  160. .card_checkbox {
  161. margin-top: 5rpx;
  162. position: relative;
  163. cursor: pointer;
  164. }
  165. .message {
  166. display: none;
  167. position: absolute;
  168. padding: 5px 8px;
  169. border: 1px solid #494949;
  170. border-radius: 9px;
  171. top: -36px;
  172. font-size: 12px;
  173. width: 110px;
  174. background: #494949;
  175. color: #fff;
  176. left: -6px;
  177. }
  178. .message::after {
  179. content: '';
  180. position: absolute;
  181. left: 8px;
  182. top: 100%;
  183. border: 8px solid transparent;
  184. border-top: 6px solid #494949;
  185. margin-left: -2px;
  186. }
  187. </style>