forgotPwd.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. <template>
  2. <div class="forgot-container">
  3. <h2 class="title-big">找回密码</h2>
  4. <el-form label-position="top" label-width="80px" ref="loginCodeForm" :model="loginCodeForm" class="form" :hide-required-asterisk="true" :rules="rulesCode" v-if="stepIndex===0">
  5. <el-form-item label="手机号" prop="phone">
  6. <el-input v-model="loginCodeForm.phone" autocomplete="off" placeholder="请输入完整手机号" @blur="handleTrim('loginCodeForm','phone')" maxlength="20">
  7. <template slot="prepend">+86</template>
  8. </el-input>
  9. </el-form-item>
  10. <el-form-item label="验证码" prop="code" class="code-box">
  11. <el-input v-model="loginCodeForm.code" autocomplete="off" placeholder="请输入验证码" class="code-input" @blur="handleTrim('loginCodeForm','code')" @input="handeleInput" maxlength="20">
  12. </el-input>
  13. <el-button type="primary" @click="sendCode('time','phone','verificationCodeShow')" size="small" class="sendCode" @input="handeleInput">
  14. {{ verificationCodeShow ? time+'s' : '发送验证码' }}
  15. </el-button>
  16. </el-form-item>
  17. <el-form-item class="btn-box">
  18. <el-button type="primary" @click="onSubmitPassword('loginCodeForm')" size="small" :disabled="submitDis" :loading="loading">下一步</el-button>
  19. <el-button @click="onCancel('loginCodeForm')" size="small">取消</el-button>
  20. </el-form-item>
  21. </el-form>
  22. <div v-else class="result-box">
  23. <img src="../assets/mail-check-line.png" />
  24. <p>密码已通过短信发送至您的手机中,请注意查收。</p>
  25. <div class="btn-box">
  26. <el-button type="primary" @click="onCancel('loginCodeForm')" size="small">确定</el-button>
  27. </div>
  28. </div>
  29. </div>
  30. </template>
  31. <script>
  32. import { getLogin } from "@/api/ajax";
  33. import { setToken } from "@/utils/auth";
  34. export default {
  35. name: "forgotPwd",
  36. props: [],
  37. data() {
  38. const validatePhone = (rule, value, callback) => {
  39. if (value === '') {
  40. callback(new Error('请输入手机号'));
  41. } else {
  42. let reg = /^1[3-9]\d{9}$/;
  43. let result = reg.test(value);
  44. if (result) {
  45. callback();
  46. } else {
  47. callback(new Error('请输入正确的手机号'));
  48. }
  49. }
  50. };
  51. return {
  52. loginCodeForm:{
  53. type: 'ADMIN',
  54. phone:'',
  55. code:''
  56. },
  57. rulesCode:{
  58. phone:[
  59. { required: true, validator: validatePhone, trigger: 'blur' }
  60. ],
  61. code:[
  62. { required: true, message: '请输入验证码', trigger: 'blur' }
  63. ]
  64. },
  65. time: 60, //获取验证码的时间
  66. verificationCodeShow: false, //是否已经获取了验证码
  67. loading: false,
  68. timer: null,
  69. submitDis: true,
  70. stepIndex: 0
  71. };
  72. },
  73. watch: {
  74. },
  75. methods: {
  76. // 密码登录提交表单
  77. onSubmitPassword(formName){
  78. this.$refs[formName].validate((valid) => {
  79. if (valid) {
  80. this.loading = true
  81. let MethodName = "/OrgServer/LoginControl/ResetRandomPassword";
  82. let data = {
  83. user_type:this.loginCodeForm.type,
  84. phone_or_email:this.loginCodeForm.phone,
  85. dynamic_verification_code:this.loginCodeForm.code,
  86. dynamic_verification_code_send_type:"SMS"
  87. }
  88. getLogin(MethodName, data)
  89. .then((res) => {
  90. this.loading = false
  91. if(res.status===1){
  92. this.stepIndex++
  93. }
  94. })
  95. .catch(() => {
  96. this.loading = false
  97. this.verificationCodeShow = false;
  98. clearInterval(this.timer);
  99. this.time = 60;
  100. });
  101. } else {
  102. return false;
  103. }
  104. });
  105. },
  106. // 取消 恢复到修改前状态
  107. onCancel(formName){
  108. this.$emit('cancelFot')
  109. },
  110. // 发送验证码
  111. sendCode(time,phone,flag,obj){
  112. let this_ = this;
  113. if(this_[time] != 60){
  114. return
  115. }
  116. this_.timer = null;
  117. if (this_.loginCodeForm[phone]) {
  118. let reg = /^1[3-9]\d{9}$/;
  119. let result = reg.test(this_.loginCodeForm[phone]);
  120. if (!result) {
  121. this_.$message.warning('请输入正确的手机号');
  122. return
  123. }
  124. this_[flag] = true;
  125. this_.timer = setInterval(() => {
  126. this_[time]--;
  127. if (this_[time] == 0) {
  128. this_[flag] = false;
  129. clearInterval(this_.timer);
  130. this_.timer = null;
  131. this_[time] = 60;
  132. }
  133. }, 1000);
  134. let MethodName = "/OrgServer/LoginControl/SendVerificationCode";
  135. let data = {
  136. send_type: 'SMS',
  137. phone_or_email: this_.loginCodeForm.phone,
  138. };
  139. getLogin(MethodName, data).then((res) => {
  140. }).catch(()=>{
  141. this_[flag] = false;
  142. clearInterval(this_.timer);
  143. this_.timer = null;
  144. this_[time] = 60;
  145. });
  146. } else {
  147. this_.$message.warning('请先输入手机号');
  148. }
  149. },
  150. // 去掉前后空格
  151. handleTrim(form,fild){
  152. this[form][fild] = this[form][fild].trim()
  153. if(this.loginCodeForm.phone&&this.loginCodeForm.code){
  154. this.submitDis = false
  155. }else{
  156. this.submitDis = true
  157. }
  158. },
  159. handeleInput(){
  160. if(this.loginCodeForm.phone&&this.loginCodeForm.code){
  161. this.submitDis = false
  162. }else{
  163. this.submitDis = true
  164. }
  165. }
  166. },
  167. mounted() {
  168. },
  169. };
  170. </script>
  171. <style lang="scss" scoped>
  172. .forgot-container{
  173. background: #FFFFFF;
  174. padding: 64px 72px;
  175. .title-big{
  176. font-weight: 400;
  177. font-size: 32px;
  178. line-height: 40px;
  179. margin: 0;
  180. color: #1D2129;
  181. }
  182. .title-name{
  183. font-size: 14px;
  184. line-height: 22px;
  185. color: #86909C;
  186. margin: 0 0 40px 0;
  187. }
  188. .tabs-box{
  189. display: flex;
  190. a{
  191. font-size: 14px;
  192. line-height: 22px;
  193. color: #4E5969;
  194. border-radius: 100px;
  195. padding: 5px 16px;
  196. margin-right: 16px;
  197. &:hover{
  198. background: #F2F3F5;
  199. }
  200. &.active{
  201. background: #F2F3F5;
  202. font-weight: 500;
  203. color: #165DFF;
  204. }
  205. }
  206. }
  207. .form{
  208. margin-top: 40px;
  209. .show-icon{
  210. cursor: pointer;
  211. color: #4E5969;
  212. }
  213. .forgotPwd{
  214. font-size: 14px;
  215. line-height: 22px;
  216. color: #165DFF;
  217. }
  218. }
  219. }
  220. .result-box{
  221. text-align: center;
  222. padding-top: 46px;
  223. img{
  224. width: 64px;
  225. }
  226. p{
  227. width: 260px;
  228. color: #000;
  229. font-size: 16px;
  230. font-weight: 400;
  231. line-height: 24px;
  232. margin: 16px auto 62px auto;
  233. }
  234. .el-button{
  235. width: 100%;
  236. }
  237. }
  238. </style>
  239. <style lang="scss">
  240. .forgot-container{
  241. .form{
  242. .el-form-item__label{
  243. font-weight: 400;
  244. font-size: 14px;
  245. line-height: 22px;
  246. color: #4E5969;
  247. padding-bottom: 8px;
  248. }
  249. .userAgree-box{
  250. .el-form-item__content{
  251. display: flex;
  252. justify-content: space-between;
  253. line-height: 22px;
  254. }
  255. .el-checkbox-group{
  256. flex: 1;
  257. .el-checkbox{
  258. color: rgba(0, 0, 0, 0.88);
  259. font-weight: 400;
  260. }
  261. }
  262. }
  263. .btn-box{
  264. .el-button{
  265. width: 100%;
  266. }
  267. .el-button+.el-button{
  268. margin-left: 0;
  269. margin-top: 8px;
  270. }
  271. }
  272. .el-button--primary{
  273. background: #165DFF;
  274. border-color: #165DFF;
  275. border-radius: 2px;
  276. &:hover{
  277. background: #4080FF;
  278. border-color: #4080FF;
  279. }
  280. &:focus{
  281. background: #0E42D2;
  282. border-color: #0E42D2;
  283. }
  284. }
  285. .el-button--default{
  286. background: #F2F3F5;
  287. border-radius: 2px;
  288. border: none;
  289. color: #4E5969;
  290. &:hover{
  291. background: #E5E6EB;
  292. }
  293. &:focus{
  294. background: #C9CDD4;
  295. }
  296. }
  297. .code-box{
  298. .el-form-item__content{
  299. display: flex;
  300. }
  301. }
  302. .code-input{
  303. height: 32px;
  304. .el-input__inner{
  305. border-radius: 4px 0 0 4px;
  306. }
  307. }
  308. .sendCode{
  309. border-radius: 0 4px 4px 0;
  310. margin-top: 1px;
  311. width: 92px;
  312. flex-shrink: 0;
  313. }
  314. .el-form-item__content,.el-input__icon{
  315. line-height: 32px;
  316. color: #4E5969 !important;
  317. }
  318. .el-input__inner{
  319. height: 32px;
  320. color: #1D2129;
  321. background: #F2F3F5;
  322. border: none;
  323. }
  324. .el-textarea__inner,.el-input-group__prepend{
  325. color: #1D2129;
  326. }
  327. .el-checkbox__input.is-checked+.el-checkbox__label{
  328. color: #165DFF;
  329. }
  330. .el-checkbox__input.is-checked .el-checkbox__inner, .el-checkbox__input.is-indeterminate .el-checkbox__inner{
  331. background: #165DFF;
  332. border-color: #165DFF;
  333. }
  334. .el-input-group__prepend{
  335. width: 54px;
  336. height: 32px;
  337. border: none;
  338. background: #F2F3F5;
  339. border-radius: 2px 0px 0px 2px;
  340. line-height: 32px;
  341. text-align: center;
  342. padding: 0;
  343. }
  344. .el-input-group--prepend{
  345. display: flex;
  346. .el-input__inner{
  347. margin-left: 8px;
  348. flex: 1;
  349. }
  350. }
  351. }
  352. .el-button--primary.is-disabled, .el-button--primary.is-disabled:active, .el-button--primary.is-disabled:focus, .el-button--primary.is-disabled:hover{
  353. background-color: #a0cfff;
  354. border-color: #a0cfff;
  355. }
  356. }
  357. </style>