t
This commit is contained in:
@@ -1,6 +1,16 @@
|
||||
<script setup>
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { ref, onMounted, computed } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import { useUserStore } from '@/stores/userStore'
|
||||
import { useAppStore } from '@/stores/appStore'
|
||||
import { useDialogStore } from '@/stores/dialogStore'
|
||||
import BindPhoneOnlyDialog from '@/components/BindPhoneOnlyDialog.vue'
|
||||
const router = useRouter()
|
||||
const userStore = useUserStore()
|
||||
const appStore = useAppStore()
|
||||
const dialogStore = useDialogStore()
|
||||
const { isLoggedIn, mobile } = storeToRefs(userStore)
|
||||
const page = ref(1)
|
||||
const pageSize = ref(10)
|
||||
const total = ref(0)
|
||||
@@ -9,30 +19,48 @@ const num = ref(0)
|
||||
const max = ref(60)
|
||||
const loading = ref(false)
|
||||
const finished = ref(false)
|
||||
const showBindNotice = computed(() => isLoggedIn.value && !mobile.value && reportList.value.length > 0)
|
||||
const hasNoRecords = computed(() => reportList.value.length === 0)
|
||||
// 初始加载数据
|
||||
async function fetchData() {
|
||||
loading.value = true
|
||||
const { data, error } = await useApiFetch(`query/list?page=${page.value}&page_size=${pageSize.value}`)
|
||||
.get()
|
||||
.json()
|
||||
if (data.value && !error.value) {
|
||||
if (data.value.code === 200) {
|
||||
total.value = data.value.data.total
|
||||
if (data.value.data.list && data.value.data.list.length > 0) {
|
||||
reportList.value.push(...data.value.data.list)
|
||||
page.value += 1
|
||||
}
|
||||
if (reportList.value.length >= total.value) {
|
||||
finished.value = true
|
||||
}
|
||||
}
|
||||
}
|
||||
loading.value = false
|
||||
if (loading.value || finished.value) return
|
||||
|
||||
loading.value = true
|
||||
try {
|
||||
const { data, error } = await useApiFetch(`query/list?page=${page.value}&page_size=${pageSize.value}`)
|
||||
.get()
|
||||
.json()
|
||||
if (data.value && !error.value) {
|
||||
if (data.value.code === 200) {
|
||||
total.value = data.value.data.total
|
||||
if (data.value.data.list && data.value.data.list.length > 0) {
|
||||
reportList.value.push(...data.value.data.list)
|
||||
page.value += 1
|
||||
}
|
||||
if (reportList.value.length >= total.value) {
|
||||
finished.value = true
|
||||
}
|
||||
} else {
|
||||
// 接口返回错误,停止翻页
|
||||
finished.value = true
|
||||
console.error('获取查询列表失败:', data.value.msg || '未知错误')
|
||||
}
|
||||
} else {
|
||||
// 请求失败或返回错误,停止翻页
|
||||
finished.value = true
|
||||
console.error('获取查询列表失败:', error.value || '请求失败')
|
||||
}
|
||||
} catch (err) {
|
||||
// 捕获异常,停止翻页
|
||||
finished.value = true
|
||||
console.error('获取查询列表失败:', err)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 初始加载
|
||||
onMounted(() => {
|
||||
onMounted(async () => {
|
||||
fetchData()
|
||||
})
|
||||
|
||||
@@ -53,6 +81,19 @@ function toDetail(item) {
|
||||
router.push({ path: '/report', query: { orderId: item.order_id } });
|
||||
}
|
||||
|
||||
function toLogin() {
|
||||
const redirect = encodeURIComponent('/historyQuery')
|
||||
router.push({ path: '/login', query: { redirect, from: 'promotionInquire' } })
|
||||
}
|
||||
|
||||
function handleBindSuccess() {
|
||||
reportList.value = []
|
||||
page.value = 1
|
||||
finished.value = false
|
||||
loading.value = false
|
||||
fetchData()
|
||||
}
|
||||
|
||||
// 状态文字映射
|
||||
function stateText(state) {
|
||||
switch (state) {
|
||||
@@ -88,6 +129,20 @@ function statusClass(state) {
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col gap-4 p-4">
|
||||
<BindPhoneOnlyDialog @bind-success="handleBindSuccess" />
|
||||
<div v-if="showBindNotice"
|
||||
class="bg-yellow-50 border border-yellow-200 text-yellow-700 rounded-lg p-3 flex items-center justify-between">
|
||||
<div class="text-sm">为防止报告丢失,请绑定手机号</div>
|
||||
<button class="px-3 py-1 text-sm font-medium bg-blue-500 text-white rounded"
|
||||
@click="dialogStore.openBindPhone">绑定手机号</button>
|
||||
</div>
|
||||
<div class="text-xs text-gray-500">为保障用户隐私及数据安全,报告保留{{ appStore.queryRetentionDays || 30 }}天,过期自动清理</div>
|
||||
<div v-if="hasNoRecords"
|
||||
class="bg-white rounded-lg shadow-sm p-6 flex flex-col items-center justify-center gap-3">
|
||||
<div class="text-gray-600 text-sm">暂无历史报告</div>
|
||||
<button v-if="!isLoggedIn || !mobile" class="px-4 py-2 bg-blue-500 text-white rounded"
|
||||
@click="toLogin">登录</button>
|
||||
</div>
|
||||
<van-list v-model:loading="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
|
||||
<div v-for="item in reportList" :key="item.id" @click="toDetail(item)"
|
||||
class="bg-white rounded-lg shadow-sm p-4 mb-4 relative cursor-pointer">
|
||||
|
||||
Reference in New Issue
Block a user