login-pwd.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template>
  2. <view class="flex-column" style="height: 100vh;">
  3. <up-navbar title="特困户看护" bgColor="transparent" leftIcon='' :title-style="{fontWeight:'bold'}">
  4. </up-navbar>
  5. <image src="/pages/subpack/static/images/logo-header-bg.png" style="width: 750rpx;height: 510rpx;"
  6. mode="aspectFill"></image>
  7. <view class="flex-column flex-1 bg-white px-5"
  8. style="margin-top: -50rpx;z-index: 9;border-radius: 48rpx 48rpx 0rpx 0rpx;padding-top: 48rpx;">
  9. <view class="flex-row align-center" style="margin-left: 18rpx;">
  10. <image src="/pages/subpack/static/images/login-phone-icon.png" style="width: 36rpx;height: 36rpx;"
  11. mode="aspectFill">
  12. </image>
  13. <text class="font-md ml-08" style="color: #002F61;">用户名</text>
  14. </view>
  15. <view class="flex-column justify-center mt-08 px-4"
  16. style="height: 88rpx;border-radius: 50rpx;background: rgba(215, 231, 255, 0.3);">
  17. <u-input placeholder="请输入用户名" v-model.trim="phone" border="none" :maxlength="11"
  18. :fontSize="16" clearable></u-input>
  19. </view>
  20. <view class="flex-row align-center" style="margin-left: 18rpx;margin-top: 36rpx;">
  21. <image class="ml-08" src="/pages/subpack/static/images/login-pwd-icon.png"
  22. style="width: 36rpx;height: 36rpx;" mode="aspectFill">
  23. </image>
  24. <text class="font-md ml-08" style="color: #002F61;">密码</text>
  25. </view>
  26. <view class="flex-row align-center justify-between mt-08 px-4"
  27. style="height: 88rpx;border-radius: 50rpx;background: rgba(215, 231, 255, 0.3);">
  28. <u-input placeholder="请输入密码" v-model.trim="password" :maxlength="16" border="none" :fontSize="16"
  29. :password="sawPwd"></u-input>
  30. <image
  31. :src="sawPwd?'/pages/subpack/static/images/eye-close.png':'/pages/subpack/static/images/saw-pwd.png'"
  32. style="width: 48rpx;height: 48rpx;margin-left: 20rpx;" mode="aspectFill" @click="sawPwd = !sawPwd">
  33. </image>
  34. </view>
  35. <view v-if="formType === 1" class="flex-row align-center" style="margin-top: 6rpx;">
  36. <image src="/pages/subpack/static/images/login-warn.png" style="width: 36rpx;height: 36rpx;"
  37. mode="aspectFill">
  38. </image>
  39. <text style="font-size: 22rpx;margin-left: 8rpx;">8-16位字符,必须包含大写字母、小写字母、数字以及特殊字符</text>
  40. </view>
  41. <view class="flex-column align-center" style="margin-top: 220rpx;">
  42. <view class="flex-row align-center justify-center w-100p"
  43. style="height: 88rpx;background: linear-gradient(100deg, #477EFF 11%, #3CE5FF 92%);box-shadow: 0px 6px 16px 0px rgba(71, 197, 255, 0.5);border-radius: 56px;"
  44. @click="checkForm">
  45. <text class="font-md text-white">{{formType === 1?'注册':'登录'}}</text>
  46. </view>
  47. <!-- <text class="font-md" style="margin-top: 68rpx;color: #4794FF;"
  48. @click="goRegister">{{formType === 1?'我有账号,去登录':'还没有账号,去注册'}}</text> -->
  49. </view>
  50. </view>
  51. </view>
  52. </template>
  53. <script>
  54. import {
  55. loginByPwdUrl,
  56. getUserInfoUrl
  57. } from '@/common/config/api.js'
  58. // import {
  59. // checkPwdPattern
  60. // } from '@/utils/common-utils.js'
  61. export default {
  62. data() {
  63. return {
  64. phone: '',
  65. sawPwd: true,
  66. password: '',
  67. // 0-登录 1-注册
  68. formType: 0
  69. }
  70. },
  71. methods: {
  72. checkForm() {
  73. if (!this.phone) {
  74. return uni.$u.toast('请输入用户名')
  75. }
  76. // if (!uni.$u.test.mobile(this.phone)) {
  77. // return uni.$u.toast('请输入正确的手机号码')
  78. // }
  79. // if (this.password.length < 8) {
  80. // return uni.$u.toast('请输入8-16位的密码')
  81. // }
  82. if (this.formType === 0) {
  83. return this.startLogin()
  84. }
  85. // if (!checkPwdPattern(this.password)) {
  86. // return uni.$u.toast('密码必须包含大写字母、小写字母、数字以及特殊字符')
  87. // }
  88. this.startRegister();
  89. },
  90. // 注册
  91. startRegister() {
  92. uni.showLoading({
  93. title: '注册中...'
  94. })
  95. registerUrl({
  96. // nickName: '用户' + this.phone.slice(-4),
  97. phoneNumber: this.phone,
  98. password: this.password
  99. })
  100. .then(res => {
  101. console.log('注册: ', res);
  102. uni.hideLoading();
  103. uni.$u.toast('注册成功,请登录');
  104. this.goRegister();
  105. })
  106. .catch(err => {
  107. console.log('err: ', err);
  108. uni.hideLoading();
  109. })
  110. },
  111. // 登录
  112. startLogin() {
  113. uni.showLoading({
  114. title: '登录中'
  115. })
  116. loginByPwdUrl({
  117. username: this.phone,
  118. password: this.password
  119. })
  120. .then(res => {
  121. console.log('登录: ', res);
  122. // proxy.$u.vuex('vuex_userId', res)
  123. // 获取用户信息
  124. this.$u.vuex('vuex_token', res.token);
  125. this.getUserInfo(res.token);
  126. })
  127. .catch(err => {
  128. uni.hideLoading();
  129. console.log('err: ', err);
  130. })
  131. },
  132. // 获取用户信息
  133. getUserInfo(userId) {
  134. getUserInfoUrl()
  135. .then(res => {
  136. console.log('用户信息: ', res);
  137. uni.hideLoading();
  138. let user = {
  139. avatar: '',
  140. nickName: res.user.nickName,
  141. phonenumber: res.user.phonenumber,
  142. roles: res.roles
  143. }
  144. this.$u.vuex('vuex_user', user);
  145. uni.switchTab({
  146. url: '/pages/tabbar/application/application'
  147. })
  148. })
  149. .catch(err => {
  150. console.log('err: ', err);
  151. uni.hideLoading();
  152. })
  153. },
  154. // 改变成注册
  155. goRegister() {
  156. if (this.formType === 0) {
  157. this.formType = 1;
  158. } else {
  159. this.formType = 0;
  160. }
  161. // 重置表单
  162. this.phone = '';
  163. this.password = '';
  164. this.sawPwd = true;
  165. }
  166. }
  167. }
  168. </script>
  169. <style>
  170. </style>