forget.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <view class="fotgerpage">
  3. <view class="fotgerpage-title">找回密码</view>
  4. <view>
  5. <view class="login_box">
  6. <u-form :model="form" ref="uForm" labelWidth="160">
  7. <u-form-item prop="tel" ref="tel" label="手机号"
  8. ><u-input
  9. v-model="form.tel"
  10. type="number"
  11. maxlength="11"
  12. border="bottom"
  13. placeholder-style="color:#999999"
  14. placeholder="请输入手机号"
  15. /></u-form-item>
  16. <u-form-item prop="code" label="验证码">
  17. <u--input
  18. v-model="form.code"
  19. type="number"
  20. border="bottom"
  21. placeholder-style="color:#999999"
  22. placeholder="请输入验证码"
  23. >
  24. <template slot="suffix">
  25. <u-code
  26. ref="uCode"
  27. @change="codeChange"
  28. seconds="60"
  29. changeText="X秒重新获取"
  30. ></u-code>
  31. <u-button size="mini" @click="getCode">{{ codeTips }}</u-button>
  32. </template>
  33. </u--input>
  34. </u-form-item>
  35. <u-form-item prop="pwd" label="新密码"
  36. ><u-input
  37. class="password"
  38. border="bottom"
  39. placeholder-style="color:#999999"
  40. v-model="form.pwd"
  41. type="password"
  42. placeholder="请输入新密码"
  43. /></u-form-item>
  44. <u-form-item prop="pwdAgain" label="确认密码"
  45. ><u-input
  46. class="password"
  47. border="bottom"
  48. placeholder-style="color:#999999"
  49. v-model="form.pwdAgain"
  50. type="password"
  51. placeholder="再次输入新密码"
  52. /></u-form-item>
  53. </u-form>
  54. </view>
  55. <u-button
  56. :disabled="isUse"
  57. class="c_btn"
  58. text="确定"
  59. @click="submit"
  60. ></u-button>
  61. </view>
  62. </view>
  63. </template>
  64. <script>
  65. import { forgetSms, forgetUser } from "@/utils/login";
  66. export default {
  67. data() {
  68. return {
  69. code: "",
  70. form: {
  71. code: "",
  72. tel: "18378140619",
  73. pwd: "123456Aa..",
  74. pwdAgain: "123456Aa..",
  75. },
  76. rules: {
  77. tel: [
  78. {
  79. required: true,
  80. message: "请输入手机号",
  81. trigger: ["change"],
  82. },
  83. {
  84. validator: (rule, value, callback) => {
  85. return this.$u.test.mobile(value);
  86. },
  87. message: "手机号码格式不正确",
  88. trigger: ["change"],
  89. },
  90. ],
  91. pwd: [
  92. {
  93. validator: (rule, value, callback) => {
  94. if (!value) return callback("请输入密码");
  95. const reg =
  96. /^(?!.*\s)(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[\W_]).{8,16}$/;
  97. if (!reg.test(value)) {
  98. callback("密码由8-16位、大小写字母、符号组成");
  99. }
  100. return callback();
  101. },
  102. trigger: ["change"],
  103. },
  104. ],
  105. pwdAgain: [
  106. {
  107. validator: (rule, value, callback) => {
  108. if (!value) return callback("请输入密码");
  109. const reg =
  110. /^(?!.*\s)(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[\W_]).{8,16}$/;
  111. if (!reg.test(value)) {
  112. callback("密码由8-16位、大小写字母、符号组成");
  113. }
  114. if (value != this.form.pwd) return callback("两次密码不一致");
  115. return callback();
  116. },
  117. trigger: ["change"],
  118. },
  119. ],
  120. code: [
  121. {
  122. required: true,
  123. message: "请输入验证码",
  124. trigger: ["change"],
  125. },
  126. ],
  127. },
  128. codeTips: "",
  129. read: "",
  130. isUse: false,
  131. };
  132. },
  133. methods: {
  134. submit() {
  135. this.$refs.uForm.validate().then((res) => {
  136. this.isUse = true;
  137. let datas = {
  138. tel: this.form.tel,
  139. code: this.form.code,
  140. pwd: this.form.pwd,
  141. };
  142. forgetUser(datas)
  143. .then((res) => {
  144. uni.showModal({
  145. title: "提示",
  146. content: "修改成功",
  147. showCancel: false,
  148. success: function (resst) {
  149. uni.navigateBack();
  150. },
  151. });
  152. })
  153. .finally(() => {
  154. this.isUse = false;
  155. });
  156. });
  157. },
  158. codeChange(text) {
  159. this.codeTips = text;
  160. },
  161. // 获取验证码
  162. getCode() {
  163. if (this.$refs.uCode.canGetCode) {
  164. this.$refs.uForm.validateField("tel", (res) => {
  165. if (res.length) {
  166. return;
  167. }
  168. let datas = { tel: this.form.tel };
  169. forgetSms(datas).then(
  170. (res) => {
  171. this.$u.toast("验证码已发送");
  172. this.$refs.uCode.start();
  173. },
  174. (err) => {
  175. console.log(err);
  176. }
  177. );
  178. });
  179. }
  180. },
  181. },
  182. onLoad(option) {},
  183. onReady() {
  184. this.$refs.uForm.setRules(this.rules);
  185. },
  186. };
  187. </script>
  188. <style scoped lang="scss">
  189. .fotgerpage {
  190. padding: 0 48rpx;
  191. .fotgerpage-title {
  192. font-weight: bold;
  193. color: #222222;
  194. font-size: 48rpx;
  195. margin: 96rpx 0;
  196. }
  197. }
  198. /deep/page {
  199. background-color: #ffffff;
  200. height: 100%;
  201. width: 100%;
  202. }
  203. .login_box {
  204. margin-bottom: 100rpx;
  205. }
  206. </style>