forgot.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 type="error" text="重置密码" customStyle="margin-top: 50px" @click="handleSubmit"></u-button>
  32. <u-gap height="20"></u-gap>
  33. <u-button type="info" text="返回" @click="navigateBack()"></u-button>
  34. </u--form>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. export default {
  40. data() {
  41. return {
  42. codeDisabled: false,
  43. tips: '',
  44. inputType: 'password',
  45. formData: {
  46. username: '',
  47. code: '',
  48. password: ''
  49. },
  50. rules: {
  51. username: {
  52. type: 'string',
  53. max: 20,
  54. required: true,
  55. message: '请输入您的账号',
  56. trigger: ['blur', 'change']
  57. },
  58. code: {
  59. type: 'number',
  60. max: 6,
  61. required: true,
  62. message: '请输入验证码',
  63. trigger: ['blur', 'change']
  64. },
  65. password: {
  66. type: 'string',
  67. max: 20,
  68. required: true,
  69. message: '请输入您的新密码',
  70. trigger: ['blur', 'change']
  71. }
  72. }
  73. }
  74. },
  75. onLoad() {},
  76. methods: {
  77. handleUsernameChange(e) {
  78. let str = uni.$u.trim(e, 'all')
  79. this.$nextTick(() => {
  80. this.formData.username = str
  81. })
  82. },
  83. handlePasswordChange(e) {
  84. let str = uni.$u.trim(e, 'all')
  85. this.$nextTick(() => {
  86. this.formData.password = str
  87. })
  88. },
  89. codeChange(text) {
  90. this.tips = text
  91. },
  92. getCode() {
  93. if (this.$refs.uCode.canGetCode) {
  94. // 模拟向后端请求验证码
  95. uni.showLoading({
  96. title: '正在获取验证码'
  97. })
  98. setTimeout(() => {
  99. uni.hideLoading()
  100. // 这里此提示会被this.start()方法中的提示覆盖
  101. uni.$u.toast('验证码已发送')
  102. // 通知验证码组件内部开始倒计时
  103. this.$refs.uCode.start()
  104. }, 2000)
  105. } else {
  106. uni.$u.toast('倒计时结束后再发送')
  107. }
  108. },
  109. handleSubmit() {
  110. this.$refs.form
  111. .validate()
  112. .then(res => {
  113. uni.$u.toast('点击了重置密码')
  114. })
  115. },
  116. navigateBack() {
  117. uni.navigateBack()
  118. }
  119. }
  120. }
  121. </script>
  122. <style lang="scss" scoped>
  123. .unp-header {
  124. height: 400rpx;
  125. @include flex-center;
  126. .unp-logo {
  127. @include flex-center;
  128. }
  129. }
  130. .unp-box {
  131. @include flex-center(column);
  132. .unp-form {
  133. width: 560rpx;
  134. }
  135. }
  136. .lk-group {
  137. height: 40rpx;
  138. margin-top: 40rpx;
  139. @include flex-space-between;
  140. font-size: 12rpx;
  141. color: $u-primary;
  142. text-decoration: $u-primary;
  143. }
  144. </style>