feat(client): show actionable customs count on sidebar
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import { ref } from 'vue'
|
||||
import { defineStore } from 'pinia'
|
||||
import { getMerchantCustomsPendingCount } from '../api/customs'
|
||||
|
||||
export const useCustomsPendingStore = defineStore('client-customs-pending', () => {
|
||||
const count = ref<number | null>(null)
|
||||
const loading = ref(false)
|
||||
const error = ref('')
|
||||
let scope = ''
|
||||
let requestVersion = 0
|
||||
|
||||
function setScope(value: string) {
|
||||
if (scope === value) return
|
||||
scope = value
|
||||
requestVersion++
|
||||
count.value = null
|
||||
error.value = ''
|
||||
loading.value = false
|
||||
}
|
||||
|
||||
async function refresh(force = false) {
|
||||
if (!scope || (loading.value && !force)) return
|
||||
const request = ++requestVersion
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await getMerchantCustomsPendingCount()
|
||||
if (request !== requestVersion) return
|
||||
count.value = result
|
||||
error.value = ''
|
||||
} catch {
|
||||
if (request !== requestVersion) return
|
||||
count.value = null
|
||||
error.value = '报关待办数量加载失败,请进入报关资料刷新'
|
||||
} finally {
|
||||
if (request === requestVersion) loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
return { count, loading, error, setScope, refresh }
|
||||
})
|
||||
Reference in New Issue
Block a user