Skip to content

Commit

Permalink
fix: known bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
Horbin-Magician committed Apr 15, 2024
1 parent aef87d9 commit c1545e4
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 39 deletions.
12 changes: 7 additions & 5 deletions front-end/src/pages/CalendarPage.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- 日历页 Calendar -->
<script setup>
import { ref } from 'vue';
import { ref, onMounted } from 'vue';
import { RouterLink, useRouter, useRoute } from 'vue-router'
import { useMessage } from 'naive-ui'

Expand Down Expand Up @@ -191,10 +191,12 @@
onMounted(() => {
const message = useMessage()
const router = useRouter()
if(!checkLogin()) {
router.push('/')
message.error("请先登录!")
}
checkLogin().then((result) => {
if (!result) {
router.push('/')
message.error("请先登录!")
}
});
});
</script>

Expand Down
68 changes: 35 additions & 33 deletions front-end/src/pages/SecretPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,41 +88,43 @@
onMounted(() => {
const message = useMessage()
const router = useRouter()
if(!checkLogin()) {
router.push('/')
message.error("请先登录!")
}

const start_words_first =
'欢迎来到秘密树洞!@' +
'从今天到小小语毕业,这里每天都会浮现一条小小槟的“小秘密”。@' +
'最后,这将变成你我共同的秘密。@' +
'准备好接收第一条小秘密了吗?';
const start_words = '准备好接收今天的小秘密了吗?';
checkLogin().then((result) => {
if (!result) {
router.push('/')
message.error("请先登录!")
}

// update states
getSecret().then(data => {
if(data && data.status === '0') {
data = data.data
secret_state.value = parseInt(data.state)
msg_board_text.value = data.message
secret = data.secret

if(secret_state.value === -1) {
// 得到格式化的当前日期
const today = new Date();
const year = today.getFullYear(); // 获取年份
const month = today.getMonth() + 1; // 获取月份,月份是从0开始的,所以需要加1
const date = today.getDate(); // 获取日期
const formattedDate = year + String(month).padStart(2, '0') + String(date).padStart(2, '0');
// 根据日期判断提示词
if(formattedDate == '20240415') typeLines(start_words_first);
else typeLines(start_words);
} else {
typeLines(secret);
const start_words_first =
'欢迎来到秘密树洞!@' +
'从今天到小小语毕业,这里每天都会浮现一条小小槟的“小秘密”。@' +
'最后,这将变成你我共同的秘密。@' +
'准备好接收第一条小秘密了吗?';
const start_words = '准备好接收今天的小秘密了吗?';

// update states
getSecret().then(data => {
if(data && data.status === '0') {
data = data.data
secret_state.value = parseInt(data.state)
msg_board_text.value = data.message
secret = data.secret

if(secret_state.value === -1) {
// 得到格式化的当前日期
const today = new Date();
const year = today.getFullYear(); // 获取年份
const month = today.getMonth() + 1; // 获取月份,月份是从0开始的,所以需要加1
const date = today.getDate(); // 获取日期
const formattedDate = year + String(month).padStart(2, '0') + String(date).padStart(2, '0');
// 根据日期判断提示词
if(formattedDate == '20240415') typeLines(start_words_first);
else typeLines(start_words);
} else {
typeLines(secret);
}
}
}
})
})
});
});
</script>

Expand Down
11 changes: 10 additions & 1 deletion front-end/src/utils/userUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,14 @@ export const initUser = () => {
* @returns true or false
*/
export const checkLogin = () => {
return memoryUtils.userdata && memoryUtils.userdata.username
return new Promise((resolve, reject) => {
const check = () => {
if (!isLogining) {
resolve(memoryUtils.userdata && memoryUtils.userdata.username); // 解决Promise,返回用户数据
} else {
setTimeout(check, 50); // 如果仍在登录中,50毫秒后再次检查
}
};
check(); // 开始检查登录状态
});
}

0 comments on commit c1545e4

Please sign in to comment.