import { defineComponent, reactive, ref } from 'vue'; import styles from '../index.module.less'; import pwdIcon from '../images/lock-icon.png'; import lockIcon from '../images/pwdIcon.png'; import useIcon from '../images/phoneIcon.png'; import openEye from '../images/openEye.png'; import closeEye from '../images/closeEye.png'; import { useMessage, NForm, NFormItem, NInput, NButton, NInputGroup } 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 '../api'; interface FormState { mobile: string; password: string; grant_type: string; loginType: string; client_id: string; client_secret: string; } export default defineComponent({ name: 'forgotPassword', emits: ['changType'], setup(props, { emit }) { const router = useRouter(); const route = useRoute(); const formRef = ref(); const message = useMessage(); const loading = ref(false); const autoLogin = ref(true); const LOGIN_NAME = PageEnum.BASE_LOGIN_NAME; const showPwd = ref(false); const showPwd2 = ref(false); const userStore = useUserStore(); const formInline = reactive({ mobile: '', password: '', password1: '', code: '', isCaptcha: true }); const isDisabledCode = ref(false); const starTimer = ref(60); const codeName = '发送短信'; const validatePass2 = (rule: any, value: any, callback: any) => { const reg = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/; if (value === '') { callback(new Error('请再次输入密码')); } else if (value !== formInline.password) { callback(new Error('两次输入密码不一致!')); } else if (!reg.test(value)) { callback(new Error('密码为6-20位数字和字母组合')); } else { callback(); } }; 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('changType'); return false; } catch (e: any) { loading.value = false; message.error(e.msg); return false; console.log(e); } } }); return false; }; const sendMessage = async () => { if (!formInline.mobile) { message.error('请输入手机号'); return; } try { const res = await sendSms({ clientId: 'cooleshow-teacher', mobile: formInline.mobile, type: 'PASSWORD' }); checkTimeOut(); } catch (e) { console.log(e); } }; 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 () => (