初次提交

This commit is contained in:
2026-01-12 15:19:54 +08:00
parent f70cb01d14
commit 141ddbb059
15 changed files with 1117 additions and 0 deletions

69
utils/storage.js Normal file
View File

@@ -0,0 +1,69 @@
const TOKEN_KEY = 'access_token'
const USER_INFO_KEY = 'user_info'
const QUESTION_KEY = 'question'
const ANSWERED_QUESTIONS_KEY = 'answered_questions'
const storage = {
setToken(token) {
uni.setStorageSync(TOKEN_KEY, token)
},
getToken() {
return uni.getStorageSync(TOKEN_KEY) || ''
},
removeToken() {
uni.removeStorageSync(TOKEN_KEY)
},
setUserInfo(userInfo) {
uni.setStorageSync(USER_INFO_KEY, userInfo)
},
getUserInfo() {
return uni.getStorageSync(USER_INFO_KEY) || null
},
removeUserInfo() {
uni.removeStorageSync(USER_INFO_KEY)
},
setQuestion(question) {
uni.setStorageSync(QUESTION_KEY, question)
},
getQuestion() {
return uni.getStorageSync(QUESTION_KEY) || null
},
removeQuestion() {
uni.removeStorageSync(QUESTION_KEY)
},
addAnsweredQuestion(sn) {
const answeredQuestions = this.getAnsweredQuestions()
if (!answeredQuestions.includes(sn)) {
answeredQuestions.push(sn)
uni.setStorageSync(ANSWERED_QUESTIONS_KEY, answeredQuestions)
}
},
getAnsweredQuestions() {
return uni.getStorageSync(ANSWERED_QUESTIONS_KEY) || []
},
isQuestionAnswered(sn) {
const answeredQuestions = this.getAnsweredQuestions()
return answeredQuestions.includes(sn)
},
clearAnsweredQuestions() {
uni.removeStorageSync(ANSWERED_QUESTIONS_KEY)
},
clearAll() {
uni.clearStorageSync()
}
}
export default storage