@@ -52,29 +52,27 @@ export default {
5252 computed: {
5353 year () {
5454 return new Date ().getFullYear ()
55- },
56- isHasKey () {
57- const keyPage = this .$themeConfig .keyPage
58- const keys = keyPage .keys
59- return keys && keys .indexOf (sessionStorage .getItem (' key' )) > - 1
60- },
61- isHasPageKey () {
62- const pageKeys = this .$frontmatter .keys
63-
64- return pageKeys && pageKeys .indexOf (sessionStorage .getItem (` pageKey${ window .location .pathname } ` )) > - 1
6555 }
6656 },
6757 methods: {
6858 inter () {
69- const keyVal = this .key .trim ()
70- const key = this .isPage ? ` pageKey${ window .location .pathname } ` : ' key'
71- sessionStorage .setItem (key, keyVal)
72- const isHasKey = this .isPage ? this .isHasPageKey : this .isHasKey
73- if (! isHasKey) {
59+ const {
60+ key ,
61+ isPage ,
62+ isHasPageKey ,
63+ isHasKey ,
64+ $refs: { passwordBtn }
65+ } = this
66+ const keyVal = key .trim ()
67+ const pageKey = ` pageKey${ window .location .pathname } `
68+ const keyName = isPage ? pageKey : ' key'
69+ sessionStorage .setItem (keyName, keyVal)
70+ const isKeyTrue = isPage ? isHasPageKey () : isHasKey ()
71+ if (! isKeyTrue) {
7472 this .warningText = ' Key Error'
7573 return
7674 }
77- const passwordBtn = this . $refs . passwordBtn
75+
7876 const width = document .getElementById (' box' ).getClientRects ()[0 ].width
7977
8078 passwordBtn .style .width = ` ${ width - 2 } px`
@@ -88,6 +86,17 @@ export default {
8886 },
8987 inputBlur () {
9088 this .warningText = ' Konck! Knock!'
89+ },
90+ isHasKey () {
91+ const keyPage = this .$themeConfig .keyPage
92+ const keys = keyPage .keys
93+ return keys && keys .indexOf (sessionStorage .getItem (' key' )) > - 1
94+ },
95+ isHasPageKey () {
96+ const pageKeys = this .$frontmatter .keys
97+ const pageKey = ` pageKey${ window .location .pathname } `
98+
99+ return pageKeys && pageKeys .indexOf (sessionStorage .getItem (pageKey)) > - 1
91100 }
92101 }
93102}
0 commit comments