register.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <view style="padding-top: 40rpx;">
  3. <veiw class="log">
  4. <view class="form-items">
  5. <u-icon name="account" color="#666" size="24" ></u-icon>
  6. <input
  7. type="number"
  8. v-model="phone"
  9. style="flex: 1;margin-left: 16rpx;"
  10. placeholder="请输入手机"
  11. maxlength="11"/>
  12. </view>
  13. <view class="form-items">
  14. <u-icon name="lock" color="#666" size="24" ></u-icon>
  15. <input
  16. type="password"
  17. v-model="password"
  18. style="flex: 1;margin-left: 16rpx;"
  19. placeholder="密码(6-15个字符)"
  20. maxlength="15"/>
  21. </view>
  22. <view class="form-items">
  23. <u-icon name="lock" color="#666" size="24" ></u-icon>
  24. <input
  25. type="password"
  26. v-model="subpassword"
  27. style="flex: 1;margin-left: 16rpx;"
  28. placeholder="确认密码"
  29. maxlength="15"/>
  30. </view>
  31. <view class="submitlog" @click="submit()">注册</view>
  32. </veiw>
  33. <view class="tips">
  34. <checkbox :checked="isAgreement" @click="handleAgreement()" color='#fff'
  35. activeBackgroundColor='#018C39 ' borderColor='#EDEEEF' activeBorderColor='#EDEEEF'/>
  36. <view @click="handleAgreement()">您同意并接受</view>
  37. <view class="btn" @click="openH5('/h5/userAgreement')">《用户协议》</view>
  38. <view class="btn" @click="openH5('/h5/privacyPolicy')">《隐私保护》</view>
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. import {register} from '@/api/user.js'
  44. export default {
  45. data() {
  46. return {
  47. phone:'',
  48. password:'',
  49. subpassword:'',
  50. isAgreement:''
  51. }
  52. },
  53. methods: {
  54. handleAgreement(){
  55. this.isAgreement=!this.isAgreement;
  56. },
  57. openH5(url){
  58. var requestPath = uni.getStorageSync('requestPath');
  59. uni.setStorageSync('url',requestPath+url);
  60. uni.navigateTo({
  61. url: '../home/h5'
  62. })
  63. },
  64. // 校验手机号
  65. validatePhone() {
  66. return /^1[3-9]\d{9}$/.test(this.phone);
  67. },
  68. // 校验密码
  69. validatePassword() {
  70. return /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{6,}$/.test(this.password);
  71. },
  72. submit(){
  73. if (!this.phone) {
  74. uni.showToast({ title: '请输入手机号', icon: 'none' });
  75. return;
  76. }
  77. if (!this.validatePhone()) {
  78. uni.showToast({ title: '手机号格式错误', icon: 'none' });
  79. return;
  80. }
  81. if (!this.password) {
  82. uni.showToast({ title: '请输入密码', icon: 'none' });
  83. return;
  84. }
  85. if (!this.validatePassword()) {
  86. uni.showToast({ title: '密码格式错误', icon: 'none' });
  87. return;
  88. }
  89. if (!this.subpassword) {
  90. uni.showToast({ title: '请输入确认密码', icon: 'none' });
  91. return;
  92. }
  93. if (this.password!==this.subpassword) {
  94. uni.showToast({ title: '两次输入密码不一致', icon: 'none' });
  95. return;
  96. }
  97. if(!this.isAgreement){
  98. uni.showToast({
  99. icon:'none',
  100. title: "请先同意协议后再登录",
  101. });
  102. return false;
  103. }
  104. const data={
  105. phone:this.phone,
  106. password:this.password
  107. }
  108. register(data).then(res=>{
  109. console.log(res)
  110. if(res.code==200){
  111. uni.showToast({ title: '登录成功', icon: 'none' });
  112. uni.navigateBack({
  113. delta:1
  114. })
  115. console.log(res)
  116. }else{
  117. uni.showToast({ title: res.msg, icon: 'none' });
  118. }
  119. })
  120. }
  121. }
  122. }
  123. </script>
  124. <style scoped lang="scss">
  125. .log{
  126. background: #fff ;
  127. width: calc(100% - 20rpx);
  128. margin: 10rpx ;
  129. padding: 20rpx 0;
  130. border-radius: 20rpx;
  131. display: flex;
  132. flex-direction: column;
  133. .form-items{
  134. background: #fff ;
  135. display: flex;
  136. align-items: center;
  137. padding: 28rpx 0;
  138. margin: 0 20rpx;
  139. border-bottom: #eee solid 2rpx;
  140. }
  141. }
  142. .submitlog{
  143. background: linear-gradient(135deg, #38e663 0%, #018C39 100%);
  144. border-radius: 80rpx;
  145. color: #fff;
  146. margin: 0 auto;
  147. width: 80%;
  148. padding: 20rpx 0;
  149. text-align: center;
  150. margin-top: 40rpx;
  151. }
  152. .tips{
  153. margin-top: 30rpx;
  154. display: flex;
  155. justify-content: center;
  156. align-items: center;
  157. font-size: 28rpx;
  158. color: #000;
  159. .btn{
  160. color: #018C39;
  161. }
  162. }
  163. /deep/ .uni-checkbox-input {
  164. border-radius: 50% !important;
  165. }
  166. </style>