forget.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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="login" 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:2,
  87. phone:this.form.phone,
  88. password:md5Libs.md5(this.form.password),
  89. code:this.form.code
  90. }
  91. let res=await this.$api.accout.forgetPaw(p)
  92. if (res.success) {
  93. this.$dialog.showModal('找回成功,请重新登录',false).then(()=>{
  94. uni.navigateBack({
  95. delta:1
  96. })
  97. })
  98. }
  99. },
  100. async login(){
  101. this.$refs.uForm.validate(valid => {
  102. if (valid) {
  103. this.forgetPaw()
  104. }
  105. });
  106. },
  107. codeChange(text) {
  108. this.codeTips = text;
  109. },
  110. // 获取验证码
  111. getCode() {
  112. if (this.$isEmpty(this.form.phone)) {
  113. this.$u.toast('请输入手机号')
  114. return
  115. }
  116. if (this.$refs.uCode.canGetCode) {
  117. // 模拟向后端请求验证码
  118. uni.showLoading({
  119. title: '正在获取验证码',
  120. mask: true
  121. })
  122. setTimeout(() => {
  123. let params={
  124. phone:this.form.phone
  125. }
  126. let p=this.$u.queryParams(params)
  127. this.$api.sms.send(p).then(res=>{
  128. if (res.data=="success") {
  129. this.$u.toast('验证码已发送');
  130. // 通知验证码组件内部开始倒计时
  131. }else{
  132. this.$u.toast(res.data);
  133. }
  134. this.$refs.uCode.start();
  135. })
  136. }, 2000);
  137. } else {
  138. this.$u.toast('倒计时结束后再发送');
  139. }
  140. },
  141. }
  142. }
  143. </script>
  144. <style>
  145. page{
  146. background-color: #FFFFFF;
  147. }
  148. </style>
  149. <style lang="scss" scoped>
  150. $color:#d18c42;
  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: #d18c42;
  167. border-radius: 50%;
  168. box-shadow: 0rpx 0rpx 50rpx #c5803b;
  169. }
  170. .bg1{
  171. height: 460rpx;
  172. width: 460rpx;
  173. position: absolute;
  174. right: -240rpx;
  175. top: -240rpx;
  176. background-color: #d18c42;
  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>