login.vue 5.5 KB

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