passwordLogin.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <template>
  2. <view>
  3. <view style="height: 90rpx;"></view>
  4. <view style="padding-left: 30rpx;">
  5. <u-icon name="close" color="#666" size="24" @click="backto()"
  6. style="width: 40rpx;height: 40rpx;"></u-icon>
  7. </view>
  8. <view style="height: 260rpx;"></view>
  9. <view class="detext">登录即可体验完整功能</view>
  10. <veiw class="log">
  11. <view class="form-items">
  12. <u-icon name="account" color="#666" size="24" ></u-icon>
  13. <input
  14. type="number"
  15. style="flex: 1;margin-left: 16rpx;"
  16. v-model="phone"
  17. placeholder="请输入手机"
  18. maxlength="11"/>
  19. </view>
  20. <view class="form-items">
  21. <u-icon name="lock" color="#666" size="24" ></u-icon>
  22. <input
  23. type="password"
  24. style="flex: 1;margin-left: 16rpx;"
  25. v-model="password"
  26. placeholder="请输入密码"
  27. maxlength="11"/>
  28. </view>
  29. <view class="submitlog" @click="submit()">登录</view>
  30. <view class="forget">
  31. <view @click="navTo('/pages/auth/register')">注册账号</view>
  32. <view @click="navTo('/pages/auth/forgetPassword')">忘记密码</view>
  33. </view>
  34. </veiw>
  35. <view class="tips">
  36. <checkbox :checked="isAgreement" @click="handleAgreement()" color='#fff'
  37. activeBackgroundColor='#018C39 ' borderColor='#EDEEEF' activeBorderColor='#EDEEEF'/>
  38. <view @click="handleAgreement()">您同意并接受</view>
  39. <view class="btn" @click="openH5('/h5/userAgreement')">《用户协议》</view>
  40. <view class="btn" @click="openH5('/h5/privacyPolicy')">《隐私保护》</view>
  41. </view>
  42. <!-- 第三方登录 -->
  43. <view @click="handleWechatLogin()" class="wechat-btn">
  44. <image src="/static/images/wechat.png" style="width: 80rpx; height: 80rpx;"></image>
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. import {login} from '@/api/user.js'
  50. export default {
  51. data() {
  52. return {
  53. phone:'',
  54. password:'',
  55. isAgreement:false,
  56. loginType:1,
  57. registrationID: '',
  58. }
  59. },
  60. watch: {
  61. isAgreement: {
  62. immediate: true,
  63. handler(value) {
  64. // #ifdef APP-PLUS
  65. if(value && !this.registrationID) {
  66. this.getRegistrationID()
  67. }
  68. // #endif
  69. }
  70. }
  71. },
  72. methods: {
  73. async getRegistrationID() {
  74. try {
  75. this.registrationID = await this.$getRegistrationID();
  76. console.log('推送ID:', this.registrationID);
  77. } catch (err) {
  78. this.registrationID = ''
  79. console.error('获取registrationID失败:', err);
  80. }
  81. },
  82. // 校验手机号
  83. validatePhone() {
  84. return /^1[3-9]\d{9}$/.test(this.phone);
  85. },
  86. // 跳转页面
  87. navTo(url){
  88. uni.navigateTo({
  89. url: url
  90. })
  91. },
  92. backto(){
  93. uni.navigateBack({
  94. url:-1
  95. })
  96. },
  97. handleAgreement(){
  98. this.isAgreement=!this.isAgreement;
  99. },
  100. openH5(url){
  101. var requestPath = uni.getStorageSync('requestPath');
  102. uni.setStorageSync('url',requestPath+url);
  103. uni.navigateTo({
  104. url: '../home/h5'
  105. })
  106. },
  107. handleWechatLogin(){
  108. //微信登录
  109. this.$showLoginPage("weixin");
  110. },
  111. submit(){
  112. if (!this.phone) {
  113. uni.showToast({ title: '请输入手机号', icon: 'none' });
  114. return;
  115. }
  116. if (!this.validatePhone()) {
  117. uni.showToast({ title: '手机号格式错误', icon: 'none' });
  118. return;
  119. }
  120. if (!this.password) {
  121. uni.showToast({ title: '请输入密码', icon: 'none' });
  122. return;
  123. }
  124. if(!this.isAgreement){
  125. uni.showToast({
  126. icon:'none',
  127. title: "请先同意协议后再登录",
  128. });
  129. return false;
  130. }
  131. const data={
  132. phone:this.phone,
  133. password:this.password,
  134. loginType:this.loginType,
  135. jpushId: this.registrationID,
  136. }
  137. login(data).then(res=>{
  138. if(res.code==200){
  139. uni.switchTab({
  140. url:'/pages/home/index'
  141. })
  142. uni.showToast({
  143. icon:'none',
  144. title: '登录成功',
  145. });
  146. uni.setStorageSync('AppToken', res.token);
  147. uni.setStorageSync('userInfo', JSON.stringify(res.user));
  148. }else{
  149. uni.showToast({
  150. icon:'none',
  151. title: res.msg,
  152. });
  153. }
  154. })
  155. }
  156. }
  157. }
  158. </script>
  159. <style lang="scss" scoped>
  160. .detext{
  161. font-size: 40rpx;
  162. font-weight: bold;
  163. text-align: center;
  164. margin-bottom: 40rpx;
  165. }
  166. .log{
  167. background: #fff ;
  168. width: calc(100% - 20rpx);
  169. margin: 10rpx ;
  170. padding: 20rpx 0;
  171. border-radius: 20rpx;
  172. display: flex;
  173. flex-direction: column;
  174. .form-items{
  175. background: #fff ;
  176. display: flex;
  177. justify-content: flex-start;
  178. align-items: center;
  179. padding: 28rpx 0;
  180. margin: 0 20rpx;
  181. border-bottom: #eee solid 2rpx;
  182. }
  183. }
  184. .submitlog{
  185. background: linear-gradient(135deg, #38e663 0%, #018C39 100%);
  186. border-radius: 80rpx;
  187. color: #fff;
  188. margin: 0 auto;
  189. width: 80%;
  190. padding: 20rpx 0;
  191. text-align: center;
  192. margin-top: 40rpx;
  193. }
  194. .forget{
  195. display: flex;
  196. justify-content: space-between;
  197. align-items: center;
  198. padding: 0 20rpx;
  199. font-size: 24rpx;
  200. color: #38e663 ;
  201. margin: 20rpx 0;
  202. }
  203. .tips{
  204. margin-top: 30rpx;
  205. display: flex;
  206. justify-content: center;
  207. align-items: center;
  208. font-size: 28rpx;
  209. color: #000;
  210. .btn{
  211. color: #018C39;
  212. }
  213. }
  214. /deep/ .uni-checkbox-input {
  215. border-radius: 50% !important;
  216. }
  217. .wechat-btn {
  218. margin-top: 100rpx !important;
  219. margin: 0 auto;
  220. width: fit-content;
  221. padding: 16rpx;
  222. display: flex;
  223. align-items: center;
  224. border-radius: 50%;
  225. border: 2rpx solid #28c445;
  226. }
  227. </style>