forget.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <template>
  2. <view class="container">
  3. <u-form :model="forgetForm" ref="forgetForm" label-width="160"
  4. :label-style="{ color: '#000', fontSize: '30rpx'}">
  5. <u-form-item label="手机号" prop="phone" :border-bottom="false">
  6. <u-input height="80" placeholder="请输入手机号" border-color="#d0d0d0" v-model="forgetForm.phone"
  7. :border="true" class="form-item-input" type="number" />
  8. </u-form-item>
  9. <u-form-item label="验证码" prop="captcha" :border-bottom="false">
  10. <view class="code-form-item">
  11. <u-input height="80" placeholder="请输入验证码" border-color="#d0d0d0" v-model="forgetForm.captcha"
  12. :border="true" class="form-item-input code-input">
  13. </u-input>
  14. <u-button size="mini" type="primary" class="code-button" @click="getCode">{{ tips }}</u-button>
  15. </view>
  16. </u-form-item>
  17. <u-form-item label="新密码" prop="newPwd" :border-bottom="false">
  18. <u-input height="80" placeholder="请输入新密码" border-color="#d0d0d0" v-model="forgetForm.newPwd"
  19. :border="true" class="form-item-input" type="password" />
  20. </u-form-item>
  21. <view class="form-button" @click="submit">
  22. 确认
  23. </view>
  24. </u-form>
  25. <u-verification-code :seconds="seconds" ref="uCode1" @change="codeChange"></u-verification-code>
  26. <u-popup v-model="show" mode="center" border-radius="10">
  27. <view class="popup">
  28. <text class="popup-title">请输入验证码</text>
  29. <view class="popup-content">
  30. <u-input height="80" placeholder="请输入验证码" border-color="#d0d0d0"
  31. v-model="numberCaptchaForm.numberCaptcha" :border="true" class="form-item-input"
  32. style="flex-grow: 1;" @confirm="submitCode" />
  33. <image :src="numberCaptchaSrc" mode="aspectFit" @click="loadImage"
  34. style="height:40px;margin-left:20rpx;width: 180rpx;flex: 0 0 auto;"></image>
  35. </view>
  36. <view class="popup-btn">
  37. <u-button type="primary" @click="submitCode" style="width: 48%;flex: 0 0 auto;">提交</u-button>
  38. <u-button type="default" @click="closePopup" style="width: 48%;flex: 0 0 auto;">取消</u-button>
  39. </view>
  40. </view>
  41. </u-popup>
  42. </view>
  43. </template>
  44. <script>
  45. import {
  46. getCaptchaImage,
  47. checknumberCaptcha,
  48. smsSend,
  49. resetPwd
  50. } from "@/api/login.js"
  51. import {
  52. msg, msgSuccess
  53. } from "@/utils/common.js"
  54. import {
  55. encryptAESCBC
  56. } from "@/utils/crypto.js"
  57. export default {
  58. data() {
  59. return {
  60. // ----验证码 start -----
  61. numberCaptchaForm: {
  62. numberCaptcha: '',
  63. numberCaptchaUuid: ''
  64. },
  65. numberCaptchaSrc: 'https://imgconvert.csdnimg.cn/aHR0cDovL3RjLnhpYW55dWNvZGVyLmNuL2Jsb2cyMDIwMDEwNDIwMzUwNy5wbmc?x-oss-process=image/format,png',
  66. show: false,
  67. tips: '',
  68. seconds: 60,
  69. // ----验证码 end -----
  70. forgetForm: {
  71. phone: '18320082803', //手机号
  72. captcha: "", //验证码
  73. captchaUuid: "",
  74. newPwd: '', // 新密码
  75. },
  76. rules: {
  77. captcha: [{
  78. required: true,
  79. message: '请输入验证码',
  80. trigger: ['blur']
  81. }],
  82. newPwd: [{
  83. required: true,
  84. message: '请输入新密码',
  85. trigger: ['blur']
  86. }],
  87. phone: [{
  88. required: true,
  89. message: '请输入手机号码',
  90. trigger: ['blur']
  91. }, {
  92. pattern: /^1[3-9]\d{9}$/,
  93. message: '请输入正确的手机号',
  94. trigger: ['blur']
  95. }]
  96. }
  97. };
  98. },
  99. methods: {
  100. submit() {
  101. const that = this;
  102. that.$refs.forgetForm.validate((valid) => {
  103. // console.log(valid, that.forgetForm, 456);
  104. if (valid) {
  105. // 联调
  106. const form = { ...that.forgetForm };
  107. form.newPwd = encryptAESCBC(form.newPwd);
  108. resetPwd(form).then(res=>{
  109. if(res.code == 0){
  110. msgSuccess("重置成功!");
  111. setTimeout(()=>{
  112. uni.reLaunch({
  113. url: "/pages/initial/initial",
  114. })
  115. }, 1000)
  116. }
  117. })
  118. }
  119. })
  120. },
  121. back() {
  122. uni.navigateBack({
  123. delta: 1,
  124. animationType: 'pop-out',
  125. animationDuration: 200
  126. })
  127. },
  128. // --------验证码 start---------
  129. codeChange(text) {
  130. this.tips = text;
  131. },
  132. getCode() {
  133. let { phone } = this.forgetForm
  134. if(!/^1[3-9]\d{9}$/.test(phone)){
  135. msg("请输入正确的手机号");
  136. return;
  137. }
  138. if (this.$refs.uCode1.canGetCode) {
  139. this.showPopup()
  140. } else {
  141. msg('倒计时结束后再发送');
  142. }
  143. },
  144. // end() {
  145. // msg('倒计时结束');
  146. // },
  147. // start() {
  148. // msg('倒计时开始');
  149. // },
  150. showPopup() {
  151. this.loadImage()
  152. this.show = true;
  153. },
  154. closePopup() {
  155. this.show = false;
  156. this.numberCaptchaForm.numberCaptcha = ''; // 清空输入框
  157. },
  158. async submitCode() {
  159. let { numberCaptcha } = this.numberCaptchaForm
  160. if (numberCaptcha.length!=4) {
  161. uni.showToast({
  162. title: '请输入4位验证码',
  163. icon: 'none'
  164. });
  165. return;
  166. }
  167. uni.showLoading({
  168. title: '正在校验验证码'
  169. })
  170. const checkRes = await checknumberCaptcha(this.numberCaptchaForm);
  171. if (!checkRes.data.valid) {
  172. uni.showToast({
  173. title: '验证码输入错误',
  174. icon: 'none'
  175. });
  176. return;
  177. }
  178. const codeRes = await smsSend({
  179. phone: this.forgetForm.phone
  180. });
  181. if (codeRes && codeRes.data.captchaUuid) {
  182. this.getPhoneCapt++;
  183. this.forgetForm.captchaUuid = codeRes.data.captchaUuid
  184. this.closePopup();
  185. this.$refs.uCode1.start()
  186. }
  187. uni.hideLoading();
  188. },
  189. // 加载验证码图片
  190. async loadImage() {
  191. // 联调
  192. uni.showLoading({
  193. title: '正在获取图片'
  194. })
  195. const img = await getCaptchaImage();
  196. if (!img.data.numberCaptchaSrc) {
  197. return
  198. }
  199. this.numberCaptchaForm.numberCaptchaUuid = img.data.numberCaptchaUuid
  200. this.numberCaptchaSrc = img.data.numberCaptchaSrc;
  201. uni.hideLoading();
  202. }
  203. // --------验证码 end---------
  204. },
  205. onLoad() {},
  206. onReady() {
  207. this.$refs.forgetForm.setRules(this.rules);
  208. }
  209. }
  210. </script>
  211. <style lang="scss">
  212. .u-form-item {
  213. padding: 30rpx 0 !important;
  214. }
  215. .u-form-item .u-input--border {
  216. border-radius: 16rpx !important;
  217. }
  218. .u-form-item .u-form-item--left__content__label {
  219. display: block !important;
  220. text-align: justify;
  221. text-align-last: justify;
  222. padding: 0 20rpx 0 10rpx;
  223. }
  224. .u-input {
  225. background-color: #f7f7f7 !important;
  226. }
  227. .code-input .u-input{
  228. padding-right: 200rpx !important;
  229. }
  230. .code-button .u-size-mini{
  231. display: block !important;
  232. }
  233. </style>
  234. <style lang="scss" scoped>
  235. .container {
  236. height: 100vh;
  237. width: 100vw;
  238. background-color: #ffffff;
  239. padding: 0 40rpx;
  240. }
  241. .form-item-input {
  242. width: 100%;
  243. }
  244. .form-button {
  245. background: linear-gradient(90deg, #006af5, #21b0fc);
  246. border-radius: 20rpx;
  247. line-height: 80rpx;
  248. text-align: center;
  249. color: #fff;
  250. margin: 50rpx 0;
  251. }
  252. .form-tip {
  253. text-align: center;
  254. color: #000000;
  255. }
  256. .code-form-item{
  257. position: relative;
  258. .code-button{
  259. position: absolute;
  260. right: 15rpx;
  261. top: 50%;
  262. transform: translateY(-50%);
  263. }
  264. }
  265. // 数字验证码弹窗
  266. .popup {
  267. padding: 40rpx;
  268. border-radius: 20rpx;
  269. .popup-title {
  270. font-size: 18px;
  271. text-align: center;
  272. display: inline-block;
  273. width: 100%;
  274. // margin-bottom: 15px;
  275. }
  276. .popup-content {
  277. display: flex;
  278. align-items: center;
  279. margin: 50rpx 0;
  280. }
  281. .popup-btn {
  282. display: flex;
  283. justify-content: space-between;
  284. }
  285. }
  286. </style>