|
@@ -0,0 +1,176 @@
|
|
|
+import { defineComponent, onMounted, reactive, ref } from 'vue';
|
|
|
+import styles from './update-password.module.less';
|
|
|
+import {
|
|
|
+ NButton,
|
|
|
+ NForm,
|
|
|
+ NFormItem,
|
|
|
+ NInput,
|
|
|
+ NSelect,
|
|
|
+ NSpace,
|
|
|
+ useMessage
|
|
|
+} from 'naive-ui';
|
|
|
+import { useRouter } from 'vue-router';
|
|
|
+import { useUserStore } from '/src/store/modules/users';
|
|
|
+import { gradeToCN } from '/src/utils/contants';
|
|
|
+import { sendSms, updatePassword } from '/src/views/login/api';
|
|
|
+export default defineComponent({
|
|
|
+ name: 'train-update',
|
|
|
+ emits: ['close', 'submit'],
|
|
|
+ setup(props, { emit }) {
|
|
|
+ const message = useMessage();
|
|
|
+ const userStore = useUserStore();
|
|
|
+ const forms = reactive({
|
|
|
+ mobile: userStore.getUserInfo.phone || '',
|
|
|
+ password: null,
|
|
|
+ rePassword: null,
|
|
|
+ clientType: 'TEACHER',
|
|
|
+ code: null
|
|
|
+ });
|
|
|
+
|
|
|
+ const gotoClassPage = () => {
|
|
|
+ formsRef.value.validate(async (error: any) => {
|
|
|
+ if (error) return;
|
|
|
+
|
|
|
+ if (forms.password !== forms.rePassword) {
|
|
|
+ message.error('两次密码不一致');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ await updatePassword({
|
|
|
+ mobile: forms.mobile,
|
|
|
+ password: forms.password,
|
|
|
+ clientType: 'TEACHER',
|
|
|
+ code: forms.code
|
|
|
+ });
|
|
|
+
|
|
|
+ message.success('更新成功');
|
|
|
+ emit('submit');
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ const formsRef = ref();
|
|
|
+
|
|
|
+ const isDisabledCode = ref(false);
|
|
|
+ const starTimer = ref(60);
|
|
|
+ const codeName = '发送短信';
|
|
|
+ const sendMessage = async () => {
|
|
|
+ if (!forms.mobile) {
|
|
|
+ message.error('请输入手机号');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ await sendSms({
|
|
|
+ clientId: 'cooleshow-teacher',
|
|
|
+ mobile: forms.mobile,
|
|
|
+ type: 'LOGIN'
|
|
|
+ });
|
|
|
+ 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);
|
|
|
+ };
|
|
|
+
|
|
|
+ onMounted(async () => {
|
|
|
+ //
|
|
|
+ });
|
|
|
+ return () => (
|
|
|
+ <div class={styles.updatePassword}>
|
|
|
+ <p class={styles.tips}>
|
|
|
+ 检测到您尚未修改默认密码,为了您的账户安全,请重新设置登录密码
|
|
|
+ </p>
|
|
|
+ <NForm
|
|
|
+ labelAlign="right"
|
|
|
+ labelPlacement="left"
|
|
|
+ labelWidth={'auto'}
|
|
|
+ ref={formsRef}
|
|
|
+ model={forms}>
|
|
|
+ <NFormItem path="currentClass" label="手机号">
|
|
|
+ <p class={styles.phone}>{forms.mobile}</p>
|
|
|
+ </NFormItem>
|
|
|
+ <NFormItem
|
|
|
+ path="password"
|
|
|
+ label="新密码"
|
|
|
+ rule={[
|
|
|
+ {
|
|
|
+ required: true,
|
|
|
+ message: '请输入新密码'
|
|
|
+ }
|
|
|
+ ]}>
|
|
|
+ <NInput
|
|
|
+ v-model:value={forms.password}
|
|
|
+ clearable
|
|
|
+ placeholder={'请输入新密码'}
|
|
|
+ />
|
|
|
+ </NFormItem>
|
|
|
+ <NFormItem
|
|
|
+ path="rePassword"
|
|
|
+ label="再次输入"
|
|
|
+ rule={[
|
|
|
+ {
|
|
|
+ required: true,
|
|
|
+ message: '再次输入新密码'
|
|
|
+ }
|
|
|
+ ]}>
|
|
|
+ <NInput
|
|
|
+ v-model:value={forms.rePassword}
|
|
|
+ clearable
|
|
|
+ placeholder={'再次输入新密码'}
|
|
|
+ />
|
|
|
+ </NFormItem>
|
|
|
+ <NFormItem
|
|
|
+ path="code"
|
|
|
+ label="验证码"
|
|
|
+ rule={[
|
|
|
+ {
|
|
|
+ required: true,
|
|
|
+ message: '请输入验证码',
|
|
|
+ trigger: 'change'
|
|
|
+ }
|
|
|
+ ]}>
|
|
|
+ <NInput
|
|
|
+ v-model:value={forms.code}
|
|
|
+ placeholder={'请输入验证码'}
|
|
|
+ clearable
|
|
|
+ class={styles.sendInput}
|
|
|
+ maxlength={6}>
|
|
|
+ {{
|
|
|
+ suffix: () => (
|
|
|
+ <NButton
|
|
|
+ class={styles.sendMsg}
|
|
|
+ disabled={isDisabledCode.value}
|
|
|
+ onClick={() => sendMessage()}>
|
|
|
+ {isDisabledCode.value ? starTimer.value + 'S' : codeName}
|
|
|
+ </NButton>
|
|
|
+ )
|
|
|
+ }}
|
|
|
+ </NInput>
|
|
|
+ </NFormItem>
|
|
|
+ <NSpace class={styles.updateBtnGroup}>
|
|
|
+ <NButton
|
|
|
+ strong
|
|
|
+ type="primary"
|
|
|
+ round
|
|
|
+ onClick={() => gotoClassPage()}>
|
|
|
+ 确认
|
|
|
+ </NButton>
|
|
|
+ </NSpace>
|
|
|
+ </NForm>
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+ }
|
|
|
+});
|