register.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <template>
  2. <view class="page">
  3. <view :style="{'marginTop':'10rpx'}">
  4. <u--form labelPosition="left" :model="form" :rules="rules" ref="uForm">
  5. <u-form-item :labelWidth="80" label="姓名:" borderBottom prop="name" ref="item1">
  6. <u--input v-model="form.username" placeholder="请输入姓名" border="none"></u--input>
  7. </u-form-item>
  8. <u-form-item :labelWidth="80" label="性别:" borderBottom prop="sex" ref="item1" @click="showSex = true">
  9. <u--input v-model="form.sex" disabled disabledColor="#ffffff" placeholder="请选择性别" border="none"></u--input>
  10. <u-icon slot="right" name="arrow-right"></u-icon>
  11. </u-form-item>
  12. <u-form-item :labelWidth="80" label="生日:" borderBottom prop="sex" ref="item1" @click="showBirthday = true">
  13. <u--input v-model="form.sex" disabled disabledColor="#ffffff" placeholder="请选择生日" border="none"></u--input>
  14. <u-icon slot="right" name="arrow-right"></u-icon>
  15. </u-form-item>
  16. <u-form-item :labelWidth="80" label="手机号:" borderBottom prop="username" ref="item1">
  17. <u--input v-model="form.username" placeholder="请输入手机号" border="none"></u--input>
  18. </u-form-item>
  19. <u-form-item :labelWidth="80" label="验证码:" borderBottom prop="code" ref="item1">
  20. <view class="inputCode">
  21. <u--input v-model="form.code" placeholder="请输入验证码" border="none"></u--input>
  22. </view>
  23. <u-button slot="right" @tap="getCode" :text="tips" type="success" size="small" :disabled="disabled1"></u-button>
  24. </u-form-item>
  25. <u-form-item :labelWidth="80" label="密码:" borderBottom prop="newPassword" ref="item1">
  26. <u--input v-model="form.newPassword" placeholder="请输入密码" type="password" border="none"></u--input>
  27. </u-form-item>
  28. <u-form-item :labelWidth="80" label="确认密码:" borderBottom prop="againPassword" ref="item1">
  29. <u--input v-model="form.againPassword" placeholder="再次确认密码" type="password" border="none"></u--input>
  30. </u-form-item>
  31. </u--form>
  32. <view :style="{'marginTop':'100rpx'}">
  33. <button class="customStyle" @click="retrievePassword">提交</button>
  34. </view>
  35. <view class="flex-row justify-end register">
  36. <text @click="gologin">去登录-></text>
  37. </view>
  38. </view>
  39. <u-code ref="uCode" @change="codeChange" seconds="60" @start="disabled1 = true" @end="disabled1 = false"></u-code>
  40. <u-action-sheet
  41. :show="showSex"
  42. :actions="actions"
  43. title="请选择性别"
  44. @close="showSex = false"
  45. @select="sexSelect">
  46. </u-action-sheet>
  47. <u-datetime-picker
  48. :show="showBirthday"
  49. :value="birthday"
  50. mode="date"
  51. closeOnClickOverlay
  52. @confirm="birthdayConfirm"
  53. @cancel="birthdayClose"
  54. @close="birthdayClose"
  55. ></u-datetime-picker>
  56. </view>
  57. </template>
  58. <script>
  59. export default {
  60. data() {
  61. return {
  62. showBirthday:false,
  63. showSex:false,
  64. birthday: Number(new Date()),
  65. actions: [{
  66. name: '男',
  67. value:'1'
  68. },
  69. {
  70. name: '女',
  71. value:'0'
  72. },{
  73. name: '保密',
  74. value:'2'
  75. }
  76. ],
  77. tips:'',
  78. form:{
  79. username:'',
  80. code:'',
  81. newPassword:'',
  82. againPassword:''
  83. },
  84. rules: {
  85. 'username': {
  86. type: 'string',
  87. required: true,
  88. min:11,
  89. max: 11,
  90. pattern:this.$phonePattern,
  91. message: '请输入正确的电话号码',
  92. trigger: ['blur', 'change']
  93. },
  94. 'code': {
  95. type: 'string',
  96. required: true,
  97. min:4,
  98. max: 6,
  99. message: '请输入验证码',
  100. trigger: ['blur', 'change']
  101. },
  102. 'newPassword': {
  103. type: 'string',
  104. min:6,
  105. max: 16,
  106. required: true,
  107. message: '请输入6-18位密码',
  108. trigger: ['blur', 'change']
  109. },
  110. 'againPassword': {
  111. type: 'string',
  112. min:6,
  113. max: 16,
  114. required: true,
  115. message: '请输入6-18位密码',
  116. trigger: ['blur', 'change']
  117. }
  118. },
  119. }
  120. },
  121. methods: {
  122. gologin(){
  123. uni.navigateTo({
  124. url:'/pages/login/login'
  125. })
  126. },
  127. birthdayClose() {
  128. this.showBirthday = false
  129. // this.$refs.form1.validateField('userInfo.birthday')
  130. },
  131. birthdayConfirm(e) {
  132. console.log(e)
  133. this.showBirthday = false
  134. this.form.birthday = uni.$u.timeFormat(e.value, 'yyyy-mm-dd')
  135. // this.$refs.form1.validateField('userInfo.birthday')
  136. },
  137. sexSelect(e) {
  138. console.log(e)
  139. },
  140. retrievePassword(){
  141. this.$refs.uForm.validate().then(res => {
  142. this.$api.login.retrievePassword(this.form).then(res=>{
  143. uni.showToast({
  144. icon: 'success',
  145. duration: 2000,
  146. title: '修改成功,即将跳转登录页'
  147. });
  148. setTimeout(()=>{
  149. this.logout()
  150. },2000)
  151. })
  152. })
  153. },
  154. logout(){
  155. this.$api.login.logout().then(res=>{
  156. uni.clearStorageSync();
  157. uni.navigateTo({
  158. url:'/pages/login/login'
  159. })
  160. })
  161. },
  162. back(){
  163. uni.navigateBack({
  164. delta: 1
  165. });
  166. },
  167. codeChange(text) {
  168. this.tips = text;
  169. },
  170. getCode() {
  171. if (this.$refs.uCode.canGetCode) {
  172. // 模拟向后端请求验证码
  173. uni.showLoading({
  174. title: '正在获取验证码'
  175. })
  176. this.$api.service.getSmsCode({phonenumber: this.form.username}).then(res=>{
  177. uni.hideLoading();
  178. // 这里此提示会被this.start()方法中的提示覆盖
  179. uni.$u.toast('验证码已发送');
  180. // 通知验证码组件内部开始倒计时
  181. this.$refs.uCode.start();
  182. })
  183. } else {
  184. uni.$u.toast('倒计时结束后再发送');
  185. }
  186. },
  187. }
  188. }
  189. </script>
  190. <style lang="scss" scoped>
  191. @import './index.rpx.css';
  192. </style>