login.vue 5.2 KB

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