login.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. <u--form labelPosition="left" :model="formList" :rules="rules" ref="uForm">
  10. <u-form-item label="账号" prop="account" borderBottom ref="item1">
  11. <u--input v-model="formList.account" border="none" placeholder="请输入账号"></u--input>
  12. </u-form-item>
  13. <u-form-item label="密码" prop="password" borderBottom ref="item1">
  14. <u--input v-model="formList.password" type="password" border="none" placeholder="请填写密码"></u--input>
  15. </u-form-item>
  16. </u--form>
  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. rules: {
  49. account: {
  50. type: 'string',
  51. required: true,
  52. message: '请填写账号',
  53. trigger: ['blur']
  54. },
  55. password: {
  56. type: 'string',
  57. required: true,
  58. message: '请填写密码',
  59. trigger: ['blur']
  60. },
  61. },
  62. }
  63. },
  64. computed: {
  65. disabled() {
  66. if (this.formList.account == '' || this.formList.password == '') {
  67. return true;
  68. } else {
  69. return false;
  70. }
  71. }
  72. },
  73. // beforeCreate() {
  74. // var token = this.$cache.getToken()
  75. // if (token) {
  76. // uni.redirectTo({
  77. // url: '/pages/indexRouter'
  78. // })
  79. // }
  80. // },
  81. methods: {
  82. checkboxChange() {
  83. if (this.checked) {
  84. this.checked = false
  85. } else {
  86. this.checked = true
  87. this.hintShow = false
  88. }
  89. },
  90. getLogin() {
  91. if (!this.checked) {
  92. this.hintShow = true
  93. } else {
  94. uni.showLoading({
  95. title: '登录中...'
  96. });
  97. this.$api.post('/api/login', {
  98. type: 1,
  99. mobile: true,
  100. username: this.formList.account,
  101. password: this.formList.password
  102. }).then((res) => {
  103. if (res.code == 200) {
  104. this.$cache.setToken(res.token)
  105. this.getUserInfo()
  106. } else {
  107. uni.showToast({
  108. title: res.data.msg,
  109. icon: 'none'
  110. });
  111. }
  112. uni.hideLoading();
  113. })
  114. }
  115. },
  116. getUserInfo() {
  117. this.$api.get('/api/user/profile').then(res => {
  118. if (res.code == 200) {
  119. this.userInfo = res.data.user
  120. this.$cache.setCache('userInfo', this.userInfo)
  121. uni.redirectTo({
  122. url: '/pages/indexRouter'
  123. })
  124. } else {
  125. uni.showToast({
  126. title: '当前用户不存在',
  127. icon: 'none'
  128. });
  129. }
  130. })
  131. }
  132. }
  133. }
  134. </script>
  135. <style lang="scss" scoped>
  136. .welcome_title {
  137. font-size: 46rpx;
  138. font-weight: 600;
  139. margin-bottom: 60rpx;
  140. margin-top: 10rpx;
  141. }
  142. .card_head_logo {
  143. margin-top: 50rpx;
  144. display: flex;
  145. flex-direction: column;
  146. justify-content: center;
  147. align-items: center;
  148. }
  149. .card_login {
  150. padding: 20rpx 40rpx;
  151. }
  152. .mine_image {
  153. width: 100rpx;
  154. height: 100rpx;
  155. }
  156. .card_hint {
  157. margin-top: 100rpx;
  158. display: flex;
  159. align-items: flex-start;
  160. }
  161. .agreement_title {
  162. font-size: 26rpx;
  163. color: #333;
  164. }
  165. .protocol_title {
  166. color: #1177ff;
  167. }
  168. .card_btn {
  169. margin-top: 20rpx;
  170. }
  171. .card_checkbox {
  172. margin-top: 5rpx;
  173. position: relative;
  174. cursor: pointer;
  175. }
  176. .message {
  177. display: none;
  178. position: absolute;
  179. padding: 5px 8px;
  180. border: 1px solid #494949;
  181. border-radius: 9px;
  182. top: -36px;
  183. font-size: 12px;
  184. width: 110px;
  185. background: #494949;
  186. color: #fff;
  187. left: -6px;
  188. }
  189. .message::after {
  190. content: '';
  191. position: absolute;
  192. left: 8px;
  193. top: 100%;
  194. border: 8px solid transparent;
  195. border-top: 6px solid #494949;
  196. margin-left: -2px;
  197. }
  198. </style>