register.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <template>
  2. <view>
  3. <navigation-bar background-color="#fff" front-color="#000000" />
  4. <view class="remain">
  5. <h1>账号注册</h1>
  6. </view>
  7. <view class="form">
  8. <u-form :model="form" ref="uForm" label-width="100px" label-position="top">
  9. <u-form-item label="手机号" prop="phone">
  10. <view class="form-input">
  11. <u-input v-model="form.phone" type="number" border="surround" maxlength='11'
  12. placeholder='请输入手机号码' :clearable='false' />
  13. </view>
  14. </u-form-item>
  15. <u-form-item label="验证码" prop="smsCode">
  16. <view class="form-input">
  17. <u-input placeholder="请输入验证码" v-model="form.smsCode">
  18. <template slot="suffix">
  19. <span class="code" @click="getCode">{{code}}</span>
  20. </template>
  21. </u-input>
  22. </view>
  23. </u-form-item>
  24. <u-form-item label="密码" prop="password">
  25. <view class="form-input">
  26. <u-input v-model="form.password" type="password" placeholder='请输入密码' :clearable='false' />
  27. </view>
  28. </u-form-item>
  29. <u-form-item label="确认密码" prop="rePassword">
  30. <view class="form-input">
  31. <u-input v-model="form.rePassword" type="password" placeholder='请输入密码' :clearable='false' />
  32. </view>
  33. </u-form-item>
  34. </u-form>
  35. <view class="btn">
  36. <view style="margin-bottom: 20rpx;font-size: 28rpx;">
  37. <u-checkbox-group v-model="value" :wrap="true">
  38. <u-checkbox name="1"></u-checkbox>注册同意<text class="blue-class">《用户协议》</text>和<text
  39. class="blue-class">《隐私政策》</text>
  40. </u-checkbox-group>
  41. </view>
  42. <view>
  43. <u-button type="error" shape="circle" text="注册" @click="submit()"></u-button>
  44. </view>
  45. <view class="tip" @click="toLogin()">已有账号,去<text class="blue-class"
  46. style="margin-left: 10rpx;">登录</text></view>
  47. </view>
  48. </view>
  49. </view>
  50. </template>
  51. <script>
  52. export default {
  53. data() {
  54. const passwordValid = (rule, value, callback) => {
  55. value == this.form.password ? callback() : callback(new Error('两次输入密码不一致'))
  56. };
  57. return {
  58. time: 60,
  59. code: '获取验证码',
  60. value: ['1'],
  61. form: {
  62. phone: '',
  63. smsCode: '',
  64. password: '',
  65. type: '',
  66. rePassword: '',
  67. },
  68. rules: {
  69. phone: [{
  70. required: true,
  71. message: '请输入手机号',
  72. trigger: 'blur,change'
  73. },
  74. {
  75. validator: (rule, value, callback) => {
  76. return uni.$u.test.mobile(value);
  77. },
  78. message: '手机号码不正确',
  79. trigger: ['change', 'blur'],
  80. }
  81. ],
  82. password: [{
  83. required: true,
  84. message: '请输入密码',
  85. trigger: 'blur,change'
  86. }],
  87. rePassword: [{
  88. validator: passwordValid,
  89. required: true,
  90. trigger:'blur'
  91. }],
  92. },
  93. }
  94. },
  95. onReady() {
  96. this.$refs.uForm.setRules(this.rules);
  97. },
  98. onLoad(options) {
  99. this.form.type = options.type;
  100. },
  101. methods: {
  102. startCount() {
  103. setTimeout(() => {
  104. let time = this.time;
  105. if (time == 0) {
  106. this.code = '重新获取';
  107. this.time = 60;
  108. return;
  109. }
  110. this.time = --time;
  111. this.code = time + '后重新获取';
  112. this.startCount();
  113. }, 1000)
  114. },
  115. getCode() {
  116. let time = this.time;
  117. if (time > 0 && time < 60) {
  118. return;
  119. }
  120. let phone = this.form.phone;
  121. if (!this.$common.isPhone(phone)) {
  122. this.$common.toast('请输入正确的手机号');
  123. return;
  124. }
  125. this.startCount();
  126. this.$api.getPhoneSmsCode().then(resp => {
  127. this.$common.toast('已发送');
  128. })
  129. },
  130. submit() {
  131. this.$refs.uForm.validate().then(res => {
  132. let value = this.value;
  133. if (value.length == 0) {
  134. this.$common.toast('请先同意协议');
  135. return;
  136. }
  137. this.$api.doRefister(this.form).then(res => {
  138. if (res.code == 200) {
  139. uni.$u.toast('注册成功')
  140. uni.navigateTo({
  141. url: '/pages/login/login'
  142. });
  143. }
  144. }).catch(err => {
  145. console.log(err)
  146. })
  147. }).catch(errors => {})
  148. },
  149. toLogin() {
  150. uni.navigateTo({
  151. url: '/pages/login/login'
  152. });
  153. },
  154. }
  155. }
  156. </script>
  157. <style lang="scss">
  158. page {
  159. background-color: #fff;
  160. padding: 30px;
  161. }
  162. .remain {
  163. margin: 30rpx 150rpx 0;
  164. text-align: center;
  165. }
  166. .wel {
  167. margin-top: 10px;
  168. }
  169. .form {
  170. height: 200px;
  171. }
  172. .form-input {
  173. width: 100%;
  174. background-color: #f5f5f5;
  175. margin-top: 5px;
  176. border-radius: 20rpx;
  177. border: none;
  178. }
  179. .btn {
  180. margin: 25px 10px;
  181. }
  182. .tip {
  183. margin-top: 30px;
  184. text-align: center;
  185. font-size: 14px;
  186. }
  187. .code {
  188. color: red;
  189. font-size: 13px;
  190. }
  191. .blue-class {
  192. color: #55aaff;
  193. cursor: pointer;
  194. }
  195. </style>