forget.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <template>
  2. <view style="position: relative;">
  3. <view class="bg"></view>
  4. <view class="bg1"></view>
  5. <view class="back" @click="$back">
  6. <u-icon name="arrow-left" size="50" color="#919191"></u-icon>
  7. </view>
  8. <view class="content">
  9. <view class="top">
  10. <view class="title">
  11. <text>忘记登录密码</text>
  12. <text>输入手机号进行找回密码</text>
  13. </view>
  14. </view>
  15. <view style="width: 76%;margin-top: 80rpx;">
  16. <u-form :model="form" ref="uForm" :rules="rules" :error-type="['message']">
  17. <u-form-item label="手机号" prop="phone" label-width="150">
  18. <u-input :border="false" placeholder="请输入手机号" v-model="form.phone" type="number"></u-input>
  19. </u-form-item>
  20. <u-form-item label="验证码" prop="code" label-width="150">
  21. <view class="flex" >
  22. <u-input style="width: 100%;" :border="false" placeholder="请输入验证码" v-model="form.code" type="text"></u-input>
  23. <u-button shape="circle" slot="right" :custom-style="customStyle" size="mini" @click="getCode">{{codeTips}}</u-button>
  24. </view>
  25. </u-form-item>
  26. <u-form-item label="新密码" prop="password" label-width="150">
  27. <u-input :border="false" placeholder="请设置新的登录密码" v-model="form.password" type="number"></u-input>
  28. </u-form-item>
  29. </u-form>
  30. </view>
  31. <view style="width: 86%;margin-top: 80rpx;">
  32. <view @click="submit" class="btn cu-btn round" style="width:100%;height: 90rpx;font-size: 34rpx;">
  33. 确认修改
  34. </view>
  35. </view>
  36. </view>
  37. <u-verification-code seconds="60" ref="uCode" @change="codeChange"></u-verification-code>
  38. </view>
  39. </template>
  40. <script>
  41. import md5Libs from "uview-ui/libs/function/md5";
  42. export default {
  43. data() {
  44. return {
  45. customStyle:{
  46. 'backgroundColor':'#d18c42',
  47. 'color':'#ffffff'
  48. },
  49. codeTips: '',
  50. form:{
  51. phone:'',
  52. code:'',
  53. password:'',
  54. },
  55. rules: {
  56. phone: [{
  57. required: true,
  58. message: '请输入手机号',
  59. trigger: ['change', 'blur'],
  60. },{
  61. message: '手机号码不正确',
  62. trigger: ['change', 'blur'],
  63. validator: (rule, value, callback) => {
  64. return this.$u.test.mobile(value);
  65. },
  66. }],
  67. code: [{
  68. required: true,
  69. message: '请输入验证码',
  70. trigger: ['change', 'blur'],
  71. }],
  72. password: [{
  73. required: true,
  74. message: '请输入登录密码',
  75. trigger: ['change', 'blur'],
  76. }],
  77. }
  78. }
  79. },
  80. onReady() {
  81. this.$refs.uForm.setRules(this.rules);
  82. },
  83. methods: {
  84. async forgetPaw(){
  85. let p={
  86. type:'MALL',
  87. phone:this.form.phone,
  88. secret:md5Libs.md5(this.form.password),
  89. value:this.form.code,
  90. smsId:this.$cache.get('smsId'),
  91. }
  92. let res=await this.$api.appaccount.forgetPsw(p)
  93. if (res.success) {
  94. this.$dialog.showModalAndBack("修改成功,请重新登录")
  95. }
  96. },
  97. async submit(){
  98. this.$refs.uForm.validate(valid => {
  99. if (valid) {
  100. this.forgetPaw()
  101. }
  102. });
  103. },
  104. codeChange(text) {
  105. this.codeTips = text;
  106. },
  107. // 获取验证码
  108. getCode() {
  109. if (this.$isEmpty(this.form.phone)) {
  110. this.$u.toast('请输入手机号')
  111. return
  112. }
  113. if (this.$refs.uCode.canGetCode) {
  114. // 模拟向后端请求验证码
  115. uni.showLoading({
  116. title: '正在获取验证码',
  117. mask: true
  118. })
  119. setTimeout(() => {
  120. let params={
  121. phone:this.form.phone
  122. }
  123. let p=this.$u.queryParams(params)
  124. this.$api.sms.send(p).then(res=>{
  125. if (res.data.success) {
  126. this.$cache.put('smsId',res.data.id)
  127. this.$u.toast('验证码已发送');
  128. // 通知验证码组件内部开始倒计时
  129. }else{
  130. this.$u.toast(res.data);
  131. }
  132. this.$refs.uCode.start();
  133. })
  134. uni.hideLoading()
  135. }, 2000);
  136. } else {
  137. this.$u.toast('倒计时结束后再发送');
  138. }
  139. },
  140. }
  141. }
  142. </script>
  143. <style>
  144. page{
  145. background-color: #FFFFFF;
  146. }
  147. </style>
  148. <style lang="scss" scoped>
  149. $color:#d18c42;
  150. .btn{
  151. background-color: $color;
  152. color:#FFFFFF;
  153. }
  154. .btn{
  155. background-color: $color;
  156. color:#FFFFFF;
  157. }
  158. .bg{
  159. z-index: 99;
  160. height: 400rpx;
  161. width: 400rpx;
  162. position: absolute;
  163. right: -240rpx;
  164. top: -240rpx;
  165. background-color: #d18c42;
  166. border-radius: 50%;
  167. box-shadow: 0rpx 0rpx 50rpx #c5803b;
  168. }
  169. .bg1{
  170. height: 460rpx;
  171. width: 460rpx;
  172. position: absolute;
  173. right: -240rpx;
  174. top: -240rpx;
  175. background-color: #d18c42;
  176. border-radius: 50%;
  177. box-shadow: #c6813b;
  178. }
  179. .back{
  180. position: absolute;
  181. top: var(--status-bar-height);
  182. left: 20rpx;
  183. padding-top: var(--status-bar-height);
  184. }
  185. .content{
  186. height: 90vh;
  187. display: flex;
  188. flex-direction: column;
  189. justify-content: center;
  190. align-items: center;
  191. .top{
  192. width: 76%;
  193. display: flex;
  194. .title{
  195. margin-right: 20rpx;
  196. display: flex;
  197. flex-direction: column;
  198. justify-content: center;
  199. align-items: flex-start;
  200. text-align: left;
  201. text:first-child{
  202. font-weight: 800;
  203. font-size: 60rpx;
  204. color: #000;
  205. margin-bottom: 20rpx;
  206. }
  207. text:last-child{
  208. font-size: 28rpx;
  209. color: #7f7f7f;
  210. }
  211. }
  212. }
  213. }
  214. </style>