Skip to content

Commit

Permalink
fig: known bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Horbin-Magician committed Apr 15, 2024
1 parent be2c6fc commit 9d3827f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 31 deletions.
4 changes: 2 additions & 2 deletions front-end/src/pages/CalendarPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { useMessage } from 'naive-ui'

import calendar from '@/utils/calendarUtils'
import { checkLogin } from '@/utils/userUtils';
import { checkLoginPromise } from '@/utils/userUtils';

function preYear () {
let n = show_date.value
Expand Down Expand Up @@ -191,7 +191,7 @@
onMounted(() => {
const message = useMessage()
const router = useRouter()
checkLogin().then((result) => {
checkLoginPromise().then((result) => {
if (!result) {
router.push('/')
message.error("请先登录!")
Expand Down
51 changes: 22 additions & 29 deletions front-end/src/pages/SecretPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { useRouter } from 'vue-router'
import { useMessage, NButton, NTooltip, NModal } from 'naive-ui'

import { checkLogin } from '@/utils/userUtils';
import { checkLoginPromise } from '@/utils/userUtils';
import { getSecret, updateState, updateMessage } from '@/api/secretAPI'

// states
Expand Down Expand Up @@ -88,7 +88,7 @@
onMounted(() => {
const message = useMessage()
const router = useRouter()
checkLogin().then((result) => {
checkLoginPromise().then((result) => {
if (!result) {
router.push('/')
message.error("请先登录!")
Expand All @@ -102,35 +102,28 @@
const start_words = '准备好接收今天的小秘密了吗?';

// update states
let try_num = 3;
function initSecret() {
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);
}
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 {
try_num -= 1;
if(try_num > 0) setTimeout(initSecret, 500); // 如果没有获取成功,50毫秒后再次检查
typeLines(secret);
}
});
}
initSecret();
}
});
});
});
</script>
Expand Down
8 changes: 8 additions & 0 deletions front-end/src/utils/userUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ export const initUser = () => {
* @returns true or false
*/
export const checkLogin = () => {
return memoryUtils.userdata && memoryUtils.userdata.username;
}

/**
* 检查是否的登录
* @returns true or false
*/
export const checkLoginPromise = () => {
return new Promise((resolve, reject) => {
const check = () => {
if (!isLogining) {
Expand Down

0 comments on commit 9d3827f

Please sign in to comment.