Skip to content

Commit ded37a2

Browse files
author
reco_luan
committed
fix: fix password page
1 parent bbdca20 commit ded37a2

File tree

2 files changed

+41
-28
lines changed

2 files changed

+41
-28
lines changed

components/Common.vue

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
@touchstart="onTouchStart"
66
@touchend="onTouchEnd">
77
<transition name="fade">
8-
<LoadingPage v-if="firstLoad"></LoadingPage>
9-
<Password v-else-if="!isHasKey"></Password>
8+
<LoadingPage v-if="firstLoad" />
9+
<Password v-else-if="!isHasKey" />
1010
<div v-else>
1111
<Navbar
1212
v-if="shouldShowNavbar"
@@ -30,7 +30,7 @@
3030
<Password v-if="!isHasPageKey" :isPage="true"></Password>
3131
<div v-else>
3232
<slot></slot>
33-
<Comments :isShowComments="isShow"/>
33+
<Comments :isShowComments="shouldShowComments"/>
3434
</div>
3535
</div>
3636
</transition>
@@ -70,18 +70,24 @@ export default {
7070
7171
computed: {
7272
// 是否显示评论
73-
isShow () {
73+
shouldShowComments () {
7474
const { isShowComments, home } = this.$frontmatter
75-
return !(this.isComment == false || isShowComments == false || home == true)
75+
return !(
76+
this.isComment == false ||
77+
isShowComments == false ||
78+
home == true
79+
)
7680
},
81+
7782
shouldShowNavbar () {
7883
const { themeConfig } = this.$site
7984
const { frontmatter } = this.$page
85+
8086
if (
8187
frontmatter.navbar === false ||
82-
themeConfig.navbar === false) {
83-
return false
84-
}
88+
themeConfig.navbar === false
89+
) return false
90+
8591
return (
8692
this.$title ||
8793
themeConfig.logo ||
@@ -188,10 +194,8 @@ export default {
188194
189195
watch: {
190196
$frontmatter (newVal, oldVal) {
191-
if (newVal.home) {
192-
this.hasKey()
193-
this.hasPageKey()
194-
}
197+
this.hasKey()
198+
this.hasPageKey()
195199
}
196200
}
197201
}

components/Password.vue

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)