✨ 登录后跳转至之前访问界面(暂只支持文章详情页+个人主页)
This commit is contained in:
parent
b79977863c
commit
1335dd9786
260
pages/login.vue
260
pages/login.vue
@ -52,151 +52,157 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import {mapState} from 'vuex';
|
import {mapState} from 'vuex';
|
||||||
|
|
||||||
const Cookie = process.client ? require('js-cookie') : undefined
|
const Cookie = process.client ? require('js-cookie') : undefined
|
||||||
export default {
|
export default {
|
||||||
name: "login",
|
name: "login",
|
||||||
middleware: 'notAuthenticated',
|
middleware: 'notAuthenticated',
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
user: {
|
user: {
|
||||||
account: '',
|
account: '',
|
||||||
password: ''
|
password: ''
|
||||||
},
|
},
|
||||||
forgetForm: {
|
forgetForm: {
|
||||||
email: ''
|
email: ''
|
||||||
},
|
},
|
||||||
forget: false,
|
forget: false,
|
||||||
loading: false,
|
loading: false,
|
||||||
loginLoading: false
|
loginLoading: false,
|
||||||
}
|
historyUrl: ''
|
||||||
},
|
}
|
||||||
computed: {
|
},
|
||||||
...mapState({
|
computed: {
|
||||||
article: state => state.article.detail.data
|
...mapState({
|
||||||
})
|
article: state => state.article.detail.data
|
||||||
},
|
})
|
||||||
methods: {
|
},
|
||||||
login() {
|
methods: {
|
||||||
let _ts = this;
|
login() {
|
||||||
_ts.$refs.user.validate((valid) => {
|
let _ts = this;
|
||||||
if (valid) {
|
_ts.$refs.user.validate((valid) => {
|
||||||
_ts.$set(_ts, 'loginLoading', true);
|
if (valid) {
|
||||||
setTimeout(function () {
|
_ts.$set(_ts, 'loginLoading', true);
|
||||||
_ts.$set(_ts, 'loginLoading', false);
|
setTimeout(function () {
|
||||||
}, 10000);
|
_ts.$set(_ts, 'loginLoading', false);
|
||||||
|
}, 10000);
|
||||||
|
|
||||||
let data = {
|
let data = {
|
||||||
account: _ts.user.account,
|
account: _ts.user.account,
|
||||||
password: _ts.user.password
|
password: _ts.user.password
|
||||||
}
|
}
|
||||||
|
|
||||||
_ts.$axios.$post('/api/console/login', data).then(function (res) {
|
_ts.$axios.$post('/api/console/login', data).then(function (res) {
|
||||||
_ts.$set(_ts, 'loginLoading', false);
|
_ts.$set(_ts, 'loginLoading', false);
|
||||||
if (res) {
|
if (res) {
|
||||||
if (res.message) {
|
if (res.message) {
|
||||||
_ts.$message(res.message);
|
_ts.$message(res.message);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let auth = {
|
let auth = {
|
||||||
accessToken: res.user.token,
|
accessToken: res.user.token,
|
||||||
idUser: res.user.idUser,
|
idUser: res.user.idUser,
|
||||||
role: res.user.weights
|
role: res.user.weights
|
||||||
}
|
}
|
||||||
|
|
||||||
let user = {
|
let user = {
|
||||||
nickname: res.user.nickname,
|
nickname: res.user.nickname,
|
||||||
avatarURL: res.user.avatarUrl
|
avatarURL: res.user.avatarUrl
|
||||||
}
|
}
|
||||||
_ts.$store.commit('setAuth', auth) // mutating to store for client rendering
|
_ts.$store.commit('setAuth', auth) // mutating to store for client rendering
|
||||||
localStorage.setItem('user', JSON.stringify(user))
|
localStorage.setItem('user', JSON.stringify(user))
|
||||||
_ts.$store.commit('setUser', user) // mutating to store for client rendering
|
_ts.$store.commit('setUser', user) // mutating to store for client rendering
|
||||||
Cookie.set('auth', auth)
|
Cookie.set('auth', auth)
|
||||||
|
if (_ts.historyUrl) {
|
||||||
|
window.location.href = _ts.historyUrl
|
||||||
|
} else {
|
||||||
_ts.$router.push({
|
_ts.$router.push({
|
||||||
name: 'index'
|
name: 'index'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
} else {
|
})
|
||||||
return false;
|
} else {
|
||||||
}
|
return false;
|
||||||
});
|
|
||||||
},
|
|
||||||
register() {
|
|
||||||
this.$router.push(
|
|
||||||
{
|
|
||||||
name: 'register'
|
|
||||||
}
|
|
||||||
)
|
|
||||||
},
|
|
||||||
forgetPassword() {
|
|
||||||
this.forget = true;
|
|
||||||
},
|
|
||||||
hideForgetPasswordDialog() {
|
|
||||||
this.forget = false;
|
|
||||||
},
|
|
||||||
sendEmailCode() {
|
|
||||||
let _ts = this;
|
|
||||||
_ts.loading = true;
|
|
||||||
let email = _ts.forgetForm.email;
|
|
||||||
if (!email) {
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
let data = {
|
});
|
||||||
email: email
|
|
||||||
};
|
|
||||||
_ts.$axios.$get('/api/console/get-forget-password-email', {
|
|
||||||
params: data
|
|
||||||
}).then(function (res) {
|
|
||||||
_ts.loading = false;
|
|
||||||
_ts.forget = false;
|
|
||||||
if (res) {
|
|
||||||
_ts.$message(res.message)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
mounted() {
|
register() {
|
||||||
this.$store.commit('setActiveMenu', 'login')
|
this.$router.push(
|
||||||
|
{
|
||||||
|
name: 'register'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
forgetPassword() {
|
||||||
|
this.forget = true;
|
||||||
|
},
|
||||||
|
hideForgetPasswordDialog() {
|
||||||
|
this.forget = false;
|
||||||
|
},
|
||||||
|
sendEmailCode() {
|
||||||
|
let _ts = this;
|
||||||
|
_ts.loading = true;
|
||||||
|
let email = _ts.forgetForm.email;
|
||||||
|
if (!email) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
let data = {
|
||||||
|
email: email
|
||||||
|
};
|
||||||
|
_ts.$axios.$get('/api/console/get-forget-password-email', {
|
||||||
|
params: data
|
||||||
|
}).then(function (res) {
|
||||||
|
_ts.loading = false;
|
||||||
|
_ts.forget = false;
|
||||||
|
if (res) {
|
||||||
|
_ts.$message(res.message)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.$store.commit('setActiveMenu', 'login');
|
||||||
|
this.$set(this, 'historyUrl', this.$route.query.historyUrl || '');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.icon-rymcu {
|
.icon-rymcu {
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
display: block;
|
display: block;
|
||||||
height: 4rem;
|
height: 4rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.verify .verify-wrap {
|
.verify .verify-wrap {
|
||||||
/*width: 60%;*/
|
/*width: 60%;*/
|
||||||
}
|
}
|
||||||
|
|
||||||
.flex-inline {
|
.flex-inline {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.verify .intro {
|
.verify .intro {
|
||||||
padding: 50px;
|
padding: 50px;
|
||||||
background-color: #f1f7fe;
|
background-color: #f1f7fe;
|
||||||
/*width: 40%;*/
|
/*width: 40%;*/
|
||||||
color: #616161;
|
color: #616161;
|
||||||
}
|
}
|
||||||
|
|
||||||
.verify__sign {
|
.verify__sign {
|
||||||
background-color: transparent !important;
|
background-color: transparent !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.vditor-reset {
|
.vditor-reset {
|
||||||
font-variant-ligatures: no-common-ligatures;
|
font-variant-ligatures: no-common-ligatures;
|
||||||
font-family: Helvetica Neue, Luxi Sans, DejaVu Sans, Tahoma, Hiragino Sans GB, Microsoft Yahei, sans-serif, Apple Color Emoji, Segoe UI Emoji, Noto Color Emoji, Segoe UI Symbol, Android Emoji, EmojiSymbols;
|
font-family: Helvetica Neue, Luxi Sans, DejaVu Sans, Tahoma, Hiragino Sans GB, Microsoft Yahei, sans-serif, Apple Color Emoji, Segoe UI Emoji, Noto Color Emoji, Segoe UI Symbol, Android Emoji, EmojiSymbols;
|
||||||
word-wrap: break-word;
|
word-wrap: break-word;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
word-break: break-word;
|
word-break: break-word;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -22,12 +22,12 @@
|
|||||||
<div v-if="oauth.idUser !== user.idUser">
|
<div v-if="oauth.idUser !== user.idUser">
|
||||||
<el-button type="primary" v-if="isFollow" @click="cancelFollowUser(user.idUser)" plain>取消关注</el-button>
|
<el-button type="primary" v-if="isFollow" @click="cancelFollowUser(user.idUser)" plain>取消关注</el-button>
|
||||||
<el-button type="primary" v-else @click="followUser(user.idUser)" plain>关注</el-button>
|
<el-button type="primary" v-else @click="followUser(user.idUser)" plain>关注</el-button>
|
||||||
<el-button @click="gotoChats" plain>聊天</el-button>
|
<el-button v-show="false" @click="gotoChats" plain>聊天</el-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-else>
|
<div v-else>
|
||||||
<el-button type="primary" @click="login" plain>关注</el-button>
|
<el-button type="primary" @click="login" plain>关注</el-button>
|
||||||
<el-button @click="login" plain>聊天</el-button>
|
<el-button v-show="false" @click="login" plain>聊天</el-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -151,7 +151,10 @@ export default {
|
|||||||
},
|
},
|
||||||
login() {
|
login() {
|
||||||
this.$router.push({
|
this.$router.push({
|
||||||
path: '/login'
|
path: '/login',
|
||||||
|
query: {
|
||||||
|
historyUrl: window.location.href
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user