Remove outdated UI components and screens for activity history, AI quit assistant, home dashboard, profile & settings, and smoking statistics. Update API to include a new endpoint for home dashboard data retrieval. Enhance smoke record dialog with improved layout and styling adjustments.
This commit is contained in:
+25
-6
@@ -9,7 +9,8 @@ export const useLogsStore = defineStore('logs', {
|
||||
pageSize: 20, // 每页数量
|
||||
hasMore: true, // 是否有更多
|
||||
loading: false, // 加载状态
|
||||
refreshing: false // 刷新状态
|
||||
refreshing: false, // 刷新状态
|
||||
queryType: 'all' // 当前筛选类型
|
||||
}),
|
||||
|
||||
getters: {
|
||||
@@ -28,12 +29,12 @@ export const useLogsStore = defineStore('logs', {
|
||||
|
||||
// 抽烟记录数量
|
||||
smokeCount: (state) => {
|
||||
return state.logs.filter(log => log.num > 0).length
|
||||
return state.logs.filter(log => normalizeLogType(log) === 'smoke').length
|
||||
},
|
||||
|
||||
// 忍住记录数量
|
||||
resistedCount: (state) => {
|
||||
return state.logs.filter(log => log.num === 0 && log.level === 0).length
|
||||
return state.logs.filter(log => normalizeLogType(log) === 'resisted').length
|
||||
},
|
||||
|
||||
// 格式化记录列表(按时间倒序,最新的在前)
|
||||
@@ -64,7 +65,7 @@ export const useLogsStore = defineStore('logs', {
|
||||
})
|
||||
|
||||
return sortedLogs.map((log, index) => {
|
||||
const type = (log.level === 0 && log.num === 0) ? 'resisted' : 'smoke'
|
||||
const type = normalizeLogType(log)
|
||||
|
||||
// 计算间隔时间:当前记录与上一条记录的间隔(上一条是 index-1,因为已倒序)
|
||||
let interval = ''
|
||||
@@ -111,7 +112,7 @@ export const useLogsStore = defineStore('logs', {
|
||||
|
||||
actions: {
|
||||
// 获取记录列表
|
||||
async fetchLogs(refresh = false) {
|
||||
async fetchLogs(refresh = false, type) {
|
||||
if (this.loading) return
|
||||
|
||||
this.loading = true
|
||||
@@ -119,12 +120,14 @@ export const useLogsStore = defineStore('logs', {
|
||||
this.refreshing = true
|
||||
this.page = 1
|
||||
this.logs = []
|
||||
this.queryType = type || 'all'
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await api.getLogs({
|
||||
page: this.page,
|
||||
page_size: this.pageSize
|
||||
page_size: this.pageSize,
|
||||
type: this.queryType
|
||||
})
|
||||
|
||||
if (res.data) {
|
||||
@@ -242,6 +245,7 @@ export const useLogsStore = defineStore('logs', {
|
||||
this.total = 0
|
||||
this.page = 1
|
||||
this.hasMore = true
|
||||
this.queryType = 'all'
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -270,3 +274,18 @@ function formatLogTime(timeStr) {
|
||||
const minutes = String(date.getMinutes()).padStart(2, '0')
|
||||
return `${hours}:${minutes}`
|
||||
}
|
||||
|
||||
function normalizeLogType(log) {
|
||||
const rawType = log?.type
|
||||
if (typeof rawType === 'string') {
|
||||
const value = rawType.toLowerCase()
|
||||
if (value === 'resisted' || value === 'resist') return 'resisted'
|
||||
if (value === 'smoke' || value === 'log_smoke') return 'smoke'
|
||||
}
|
||||
if (typeof rawType === 'number') {
|
||||
if (rawType === 0) return 'resisted'
|
||||
if (rawType === 1) return 'smoke'
|
||||
}
|
||||
if (log?.num === 0) return 'resisted'
|
||||
return 'smoke'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user