|
|
@@ -1,15 +1,109 @@
|
|
|
<template>
|
|
|
<div class="tab">
|
|
|
- <h1 class="title">个人信息设置 <span class="tag">学生</span></h1>
|
|
|
- <div class="sub-title"></div>
|
|
|
+ <h1 class="title">个人信息设置 <span class="tag">教师</span></h1>
|
|
|
+ <div class="sub-title">修改姓名</div>
|
|
|
+ <c-input placeholder="姓名" class="mb-16" v-model="newName"></c-input>
|
|
|
+ <c-button class="warning full-width mb-32" @click="handleModifyName">确认修改姓名</c-button>
|
|
|
+ <div class="sub-title">修改密码</div>
|
|
|
+ <div class="verified-code-wrapper">
|
|
|
+ <c-input placeholder="邮箱验证码" type="number"></c-input>
|
|
|
+ <c-button class="secondary" :disabled="typeof this.emailButtonContent === typeof 0"
|
|
|
+ @click="handleSendEmailCode">{{ emailButtonContent }}
|
|
|
+ </c-button>
|
|
|
+ </div>
|
|
|
+ <c-input placeholder="新密码" type="password" class="mb-16" v-model="password"></c-input>
|
|
|
+ <c-input placeholder="确认新密码" type="password" class="mb-16" v-model="passwordEnsure"></c-input>
|
|
|
+ <c-button class="warning full-width mb-32" @click="handleModifyPassword">确认修改密码</c-button>
|
|
|
+ <c-button class="error full-width" @click="handleLogout">登出</c-button>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-export default {}
|
|
|
+import CButton from '@/components/CButton'
|
|
|
+import CInput from '@/components/CInput'
|
|
|
+import { sendEmailCode } from '@/server/code'
|
|
|
+import { logout, modifyUser, resetPasswordByEmail } from '@/server/user'
|
|
|
+
|
|
|
+export default {
|
|
|
+ components: { CInput, CButton },
|
|
|
+ data () {
|
|
|
+ return {
|
|
|
+ email: '',
|
|
|
+ emailButtonContent: '发送验证码',
|
|
|
+ newName: '',
|
|
|
+ password: '',
|
|
|
+ passwordEnsure: ''
|
|
|
+ }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ handleSendEmailCode () {
|
|
|
+ this.$showMessage({ message: '正在尝试发送验证码', type: 'info' })
|
|
|
+ if (this.email.match(/.+@(nju.edu.cn|smail.nju.edu.cn)/)) {
|
|
|
+ this.setEmailCodeCd()
|
|
|
+ sendEmailCode({ email: this.email })
|
|
|
+ } else {
|
|
|
+ this.$showMessage({ message: '本邮箱不符合南京大学校邮格式', type: 'error' })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ setEmailCodeCd () {
|
|
|
+ this._emailCodeCdInterval && clearInterval(this._emailCodeCdInterval)
|
|
|
+ this.emailButtonContent = 60
|
|
|
+ this._emailCodeCdInterval = setInterval(() => {
|
|
|
+ this.emailButtonContent--
|
|
|
+ if (typeof this.emailButtonContent !== typeof 0 || this.emailButtonContent <= 0) {
|
|
|
+ clearInterval(this._emailCodeCdInterval)
|
|
|
+ this.emailButtonContent = '发送验证码'
|
|
|
+ }
|
|
|
+ }, 1000)
|
|
|
+ },
|
|
|
+ handleLogout () {
|
|
|
+ logout()
|
|
|
+ this.$router.push({ name: 'login' })
|
|
|
+ },
|
|
|
+ handleModifyPassword () {
|
|
|
+ if (!this.password || this.password !== this.passwordEnsure) {
|
|
|
+ this.$setInfoMessage('两次输入的密码不一致')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ resetPasswordByEmail({ email: this.email, code: this.code, password: this.password }).then(res => {
|
|
|
+ this.$setInfoMessage('密码修改成功')
|
|
|
+ }).catch(err => {
|
|
|
+ this.$setErrorMessage(err.response.data.msg)
|
|
|
+ })
|
|
|
+ },
|
|
|
+ handleModifyName () {
|
|
|
+ if (!this.newName) {
|
|
|
+ this.$setInfoMessage('输入的新用户名为空')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ modifyUser({ name: this.newName }).then(res => {
|
|
|
+ this.$setSuccessMessage('修改用户名成功')
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
@import "~@/style/theme.scss";
|
|
|
@import "~@/views/shared/tab-common";
|
|
|
+
|
|
|
+.verified-code-wrapper {
|
|
|
+ margin-bottom: 16px;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ flex: 1;
|
|
|
+
|
|
|
+ .c-input {
|
|
|
+ margin-bottom: unset;
|
|
|
+ flex: 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ .c-button {
|
|
|
+ margin-left: 12px;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
</style>
|