|
|
@@ -1,177 +1,21 @@
|
|
|
<template>
|
|
|
- <div class="tab complex-tab">
|
|
|
- <div class="left">
|
|
|
- <h1 class="title">
|
|
|
- 个人信息设置
|
|
|
- <c-tag theme="green">学生</c-tag>
|
|
|
- </h1>
|
|
|
- <div class="info">
|
|
|
- <div>邮箱:{{userInfo.email}}</div>
|
|
|
- <div>手机:{{userInfo.phone}}</div>
|
|
|
- <div>姓名:{{userInfo.name}}</div>
|
|
|
- <div>加入时间:{{momentFromNow(userInfo.createAt)}}</div>
|
|
|
- </div>
|
|
|
- <div class="sub-title">
|
|
|
- 修改资料
|
|
|
- <c-button :theme="showChangeProfile ? 'blue' : 'normal'" :left="8" text
|
|
|
- :icon="showChangeProfile ? 'unfold_less' : 'unfold_more'"
|
|
|
- @click="showChangeProfile = !showChangeProfile">
|
|
|
- {{showChangeProfile ? '收起' : '展开'}}
|
|
|
- </c-button>
|
|
|
- </div>
|
|
|
- <show-transition>
|
|
|
- <div v-if="showChangeProfile">
|
|
|
- <c-input :placeholder="'目前资料中的姓名:' + userInfo.name" class="mb-16" v-model="newName"></c-input>
|
|
|
- <c-button theme="green" block class="mb-32" @click="handleModifyName" icon="check">确认修改姓名</c-button>
|
|
|
- </div>
|
|
|
- </show-transition>
|
|
|
- <div class="sub-title">
|
|
|
- 修改密码
|
|
|
- <c-button :theme="showChangePassword ? 'blue' : 'normal'" :left="8" text :icon="showChangePassword ? 'unfold_less' : 'unfold_more'"
|
|
|
- @click="showChangePassword = !showChangePassword">
|
|
|
- {{showChangePassword ? '收起' : '展开'}}
|
|
|
- </c-button>
|
|
|
- </div>
|
|
|
- <show-transition>
|
|
|
- <div v-if="showChangePassword">
|
|
|
- <div class="verified-code-wrapper">
|
|
|
- <c-input placeholder="邮箱验证码" type="number" v-model="code"></c-input>
|
|
|
- <c-button theme="blue" :no-click-warn="typeof 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 block theme="orange" @click="handleModifyPassword" icon="check">确认修改密码</c-button>
|
|
|
- </div>
|
|
|
- </show-transition>
|
|
|
- </div>
|
|
|
- <slide-in-different-transition>
|
|
|
- <router-view/>
|
|
|
- </slide-in-different-transition>
|
|
|
- </div>
|
|
|
+ <personal :role="userType.student" role-tag-theme="green"></personal>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import CButton from '@/components/Basic/CButton'
|
|
|
-import CInput from '@/components/Basic/CInput'
|
|
|
-import { sendEmailCode } from '@/server/code'
|
|
|
-import { logout, modifyUser, resetPasswordByEmail } from '@/server/user'
|
|
|
-import { mapState } from 'vuex'
|
|
|
-import CTag from '@/components/Basic/CTag'
|
|
|
-import SlideInDifferentTransition from '@/animations/SlideInDifferentTransition'
|
|
|
-import ShowTransition from '@/animations/ShowTransition'
|
|
|
-import momentFromNow from '@/utils/moment-from-now'
|
|
|
+import Personal from '@/views/shared/Personal'
|
|
|
+import userType from '@/enums/user-type'
|
|
|
|
|
|
export default {
|
|
|
- components: { CTag, CInput, CButton, SlideInDifferentTransition, ShowTransition },
|
|
|
+ components: { Personal },
|
|
|
data () {
|
|
|
return {
|
|
|
- emailButtonContent: '发送验证码',
|
|
|
- newName: '',
|
|
|
- code: '',
|
|
|
- password: '',
|
|
|
- passwordEnsure: '',
|
|
|
- showChangeProfile: false,
|
|
|
- showChangePassword: false
|
|
|
- }
|
|
|
- },
|
|
|
- computed: {
|
|
|
- ...mapState({
|
|
|
- userInfo: state => state.main.userInfo
|
|
|
- }),
|
|
|
- email () {
|
|
|
- return this.userInfo.email
|
|
|
- }
|
|
|
- },
|
|
|
- methods: {
|
|
|
- momentFromNow,
|
|
|
- handleSendEmailCode () {
|
|
|
- this.$setInfoMessage('正在尝试发送验证码')
|
|
|
- if (this.email.match(/.+@.*(edu.cn)/)) {
|
|
|
- this.setEmailCodeCd()
|
|
|
- sendEmailCode({ email: this.email }).then(res => {
|
|
|
- this.$setSuccessMessage('邮箱验证码发送成功')
|
|
|
- }).catch(err => {
|
|
|
- this.$setErrorMessage(err.response.data.msg)
|
|
|
- })
|
|
|
- } else {
|
|
|
- this.$setErrorMessage('本邮箱不符合南京大学校邮格式')
|
|
|
- }
|
|
|
- },
|
|
|
- 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.$setSuccessMessage('您已退出登录')
|
|
|
- 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.$setSuccessMessage('密码修改成功')
|
|
|
- }).catch(err => {
|
|
|
- this.$setErrorMessage(err.response.data.msg)
|
|
|
- })
|
|
|
- },
|
|
|
- handleModifyName () {
|
|
|
- if (!this.newName) {
|
|
|
- this.$setInfoMessage('输入的新用户名为空')
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- modifyUser({ name: this.newName }).then(res => {
|
|
|
- this.$setSuccessMessage('修改用户名成功')
|
|
|
- })
|
|
|
+ userType
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
-@import "~@/style/theme.scss";
|
|
|
-@import "~@/views/shared/tab-common";
|
|
|
-
|
|
|
-.sub-title {
|
|
|
- font-size: 20px;
|
|
|
- display: flex;
|
|
|
- align-items: center;
|
|
|
-}
|
|
|
|
|
|
-.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;
|
|
|
- }
|
|
|
-}
|
|
|
-.info {
|
|
|
- font-size: 14px;
|
|
|
- padding: 4px 12px;
|
|
|
- background-color: #f4f4f4;
|
|
|
- color: #7a8a9a;
|
|
|
- line-height: 2;
|
|
|
- margin-bottom: 16px;
|
|
|
-}
|
|
|
</style>
|