forgot.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <template>
  2. <view class="container">
  3. <view class="unp-header">
  4. <view class="unp-logo">
  5. <u-avatar size="80" icon="github-circle-fill" fontSize="80"></u-avatar>
  6. </view>
  7. </view>
  8. <view class="unp-box">
  9. <u--form class="unp-form" labelPosition="left" :model="formData" :rules="rules" ref="form">
  10. <u-form-item label="账号" prop="username" borderBottom ref="item-username">
  11. <u-input type="text" maxlength="20" v-model="formData.username" clearable placeholder="账号由数字和字母组成" border="none" @change="handleUsernameChange"></u-input>
  12. </u-form-item>
  13. <u-gap height="20"></u-gap>
  14. <u-form-item label="验证码" prop="code" labelWidth="80" borderBottom>
  15. <u--input type="number" maxlength="6" v-model="formData.code" border="none" placeholder="请填写验证码"></u--input>
  16. <u-button slot="right" @tap="getCode" :text="tips" type="success" size="mini" :disabled="codeDisabled"></u-button>
  17. <u-code ref="uCode" @change="codeChange" seconds="60" @start="codeDisabled = true" @end="codeDisabled = false"></u-code>
  18. </u-form-item>
  19. <u-gap height="20"></u-gap>
  20. <u-form-item label="密码" prop="password" borderBottom ref="item-password">
  21. <u-input :type="inputType" maxlength="20" v-model="formData.password" placeholder="新密码由数字、字母和符号组成" border="none" @change="handlePasswordChange">
  22. <template slot="suffix">
  23. <u-icon v-if="inputType === 'password'" size="20" color="#666666" name="eye-fill" @click="inputType = 'text'"></u-icon>
  24. <u-icon v-if="inputType === 'text'" size="20" color="#666666" name="eye-off" @click="inputType = 'password'"></u-icon>
  25. </template>
  26. </u-input>
  27. </u-form-item>
  28. <view class="lk-group">
  29. <!-- 占位 -->
  30. </view>
  31. <u-button
  32. type="error"
  33. text="重置密码"
  34. customStyle="margin-top: 50px"
  35. @click="handleSubmit"
  36. ></u-button>
  37. <u-gap height="20"></u-gap>
  38. <u-button type="info" text="返回" @click="navigateBack()"></u-button>
  39. </u--form>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. export default {
  45. data() {
  46. return {
  47. codeDisabled: false,
  48. tips: '',
  49. inputType: 'password',
  50. formData: {
  51. username: '',
  52. code: '',
  53. password: '',
  54. },
  55. rules: {
  56. 'username': {
  57. type: 'string',
  58. max: 20,
  59. required: true,
  60. message: '请输入您的账号',
  61. trigger: ['blur', 'change']
  62. },
  63. 'code': {
  64. type: 'number',
  65. max: 6,
  66. required: true,
  67. message: '请输入验证码',
  68. trigger: ['blur', 'change']
  69. },
  70. 'password': {
  71. type: 'string',
  72. max: 20,
  73. required: true,
  74. message: '请输入您的新密码',
  75. trigger: ['blur', 'change']
  76. }
  77. }
  78. }
  79. },
  80. onLoad() {
  81. },
  82. methods: {
  83. handleUsernameChange(e){
  84. let str = uni.$u.trim(e, 'all');
  85. this.$nextTick(() => {
  86. this.formData.username = str
  87. })
  88. },
  89. handlePasswordChange(e){
  90. let str = uni.$u.trim(e, 'all');
  91. this.$nextTick(() => {
  92. this.formData.password = str
  93. })
  94. },
  95. codeChange(text) {
  96. this.tips = text;
  97. },
  98. getCode() {
  99. if (this.$refs.uCode.canGetCode) {
  100. // 模拟向后端请求验证码
  101. uni.showLoading({
  102. title: '正在获取验证码'
  103. })
  104. setTimeout(() => {
  105. uni.hideLoading();
  106. // 这里此提示会被this.start()方法中的提示覆盖
  107. uni.$u.toast('验证码已发送');
  108. // 通知验证码组件内部开始倒计时
  109. this.$refs.uCode.start();
  110. }, 2000);
  111. } else {
  112. uni.$u.toast('倒计时结束后再发送');
  113. }
  114. },
  115. handleSubmit() {
  116. this.$refs.form.validate().then(res => {
  117. uni.$u.toast('点击了重置密码')
  118. }).catch(err => {
  119. })
  120. },
  121. navigateBack() {
  122. uni.navigateBack()
  123. }
  124. }
  125. }
  126. </script>
  127. <style lang="scss" scoped>
  128. .unp-header {
  129. height: 400rpx;
  130. display: flex;
  131. align-items: center;
  132. justify-content: center;
  133. .unp-logo {
  134. display: flex;
  135. flex-direction: column;
  136. align-items: center;
  137. justify-content: center;
  138. }
  139. }
  140. .unp-box {
  141. display: flex;
  142. flex-direction: column;
  143. align-items: center;
  144. justify-content: center;
  145. .unp-form{
  146. width: 560rpx;
  147. }
  148. }
  149. .lk-group {
  150. height: 40rpx;
  151. margin-top: 40rpx;
  152. display: flex;
  153. align-items: center;
  154. justify-content: space-between;
  155. font-size: 12rpx;
  156. color: #3c9cff;
  157. text-decoration: #3c9cff;
  158. }
  159. </style>