login.vue 4.4 KB

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