forget.vue 5.1 KB

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