import { defineComponent, reactive, ref } from 'vue'; import styles from '../index.module.less'; import openEye from '../images/openEye.png'; import closeEye from '../images/closeEye.png'; import { useMessage, NForm, NFormItem, NInput, NButton, NInputGroup, NSpace } from 'naive-ui'; import { useRoute, useRouter } from 'vue-router'; import { PageEnum } from '/src/enums/pageEnum'; import { storage } from '@/utils/storage'; import { useUserStore } from '/src/store/modules/users'; import { sendSms, updatePassword } from '../../login/api'; interface FormState { mobile: string; password: string; grant_type: string; loginType: string; client_id: string; client_secret: string; } export default defineComponent({ name: 'forgotPassword', emits: ['close'], props: { phone: { type: String, default: '' } }, setup(props, { emit }) { const formRef = ref(); const message = useMessage(); const loading = ref(false); const showPwd = ref(false); const userStore = useUserStore(); const formInline = reactive({ mobile: props.phone, password: '', code: '', isCaptcha: true }); const isDisabledCode = ref(false); const starTimer = ref(60); const codeName = '发送短信'; const handleSubmit = async () => { formRef.value.validate(async (errors: any) => { if (!errors) { message.loading('修改中...'); loading.value = true; try { await updatePassword({ ...formInline, clientType: 'TEACHER' }); message.success('修改成功'); loading.value = false; emit('close'); setTimeout(() => { userStore.logout(); history.go(0); }, 500); return false; } catch (e: any) { loading.value = false; message.error(e.msg); return false; } } }); return false; }; const sendMessage = () => { formRef.value?.validate( (errors: any) => { if (errors) { return; } checkTimeOut(); sendSms({ clientId: 'cooleshow-teacher', mobile: formInline.mobile, type: 'PASSWORD' }); }, (rule: any) => { return rule.key === 'a'; } ); }; const checkTimeOut = () => { if (isDisabledCode.value) { return; } isDisabledCode.value = true; const tiemr = setInterval(() => { starTimer.value--; console.log(starTimer.value); if (starTimer.value <= 0) { isDisabledCode.value = false; clearInterval(tiemr); } }, 1000); }; return () => ( <>
sendMessage()}> {isDisabledCode.value ? starTimer.value : codeName} {{ 'password-visible-icon': () => ( ), 'password-invisible-icon': () => ( ) }}
emit('close')} size="large" round disabled={loading.value}> 取消 确认修改 ); } });