diff --git a/pages/auth.vue b/pages/auth.vue index d131b06..3c66ef6 100644 --- a/pages/auth.vue +++ b/pages/auth.vue @@ -26,7 +26,6 @@ export default { return } - window.opener.localStorage.visitorToken = data.result window.opener.authSuccess(data) window.close() diff --git a/pages/post/_id.vue b/pages/post/_id.vue index acc32ac..5082d5a 100644 --- a/pages/post/_id.vue +++ b/pages/post/_id.vue @@ -52,8 +52,8 @@ .comment-no-userinfo(v-if="!visitorToken") 尚未登陆 .comment-userinfo(v-else) .comment-avatar - img(:src="'https://picsum.photos/100/100/?blur=1'") - .comment-nickname 张三 + img(:src="visitorInfo.avatarURL") + .comment-nickname {{ visitorInfo.nickname }} .comment-logout(@click="commentLogout") 退出 .comment-btn(@click="commentCommit") 发布 .comment-reply-commit(id="comment-reply-commit", v-show="replyID") @@ -64,8 +64,8 @@ .comment-no-userinfo(v-if="!visitorToken") 尚未登陆 .comment-userinfo(v-else) .comment-avatar - img(:src="'https://picsum.photos/100/100/?blur=1'") - .comment-nickname 张三 + img(:src="visitorInfo.avatarURL") + .comment-nickname {{ visitorInfo.nickname }} .comment-logout(@click="commentLogout") 退出 .comment-btn(@click="commentCommit") 发布 ins.adsbygoogle(style="display:block; text-align:center; margin-top:20px;", data-ad-layout="in-article", data-ad-format="fluid", data-ad-client="ca-pub-2143583075951360", data-ad-slot="4741804954") @@ -111,13 +111,30 @@ export default { tocIds: result.post_toc_ids, replyLastID: null, replyID: null, - visitorToken: null + visitorToken: null, + visitorInfo: { + nickname: null, + avatarURL: null, + email: null, + blog: null + } } }, mounted () { // 创建编辑器 this.visitorToken = window.localStorage.visitorToken + if (this.visitorToken && window.localStorage.visitorInfo) { + try { + this.visitorInfo = JSON.parse(window.localStorage.visitorInfo) + } catch (_) { } + } if (process.client) { + window.setAuthToken = (visitorToken, visitorInfo) => { + window.localStorage.visitorToken = visitorToken + window.localStorage.visitorInfo = JSON.stringify(visitorInfo) + this.visitorToken = visitorToken + this.visitorInfo = visitorInfo + } if (!window.editorObj && window.Vditor) { const upload = { accept: 'image/*, video/*, audio/*, text/*, application/*, .rar, .zip, .php, .pptx, .ppt, .doc, .docx, .txt, .xls, .xlsx', @@ -452,7 +469,7 @@ export default { }, commentLogout () { - window.localStorage.visitorToken = null + window.localStorage.removeItem('visitorToken') this.visitorToken = null }, login () { diff --git a/plugins/browser.js b/plugins/browser.js index 50c5344..c95e062 100644 --- a/plugins/browser.js +++ b/plugins/browser.js @@ -66,4 +66,9 @@ window.Vditor = vditor window.authSuccess = (data) => { // eslint-disable-line console.log('授权成功', data) + if (data.status === 1) { + try { + if (window.setAuthToken) { window.setAuthToken(data.result.token, data.result.visitorInfo) } + } catch (_) { } + } }