allow filter goods tag

This commit is contained in:
Megghy
2024-09-26 16:36:03 +08:00
parent 4393e3d9a7
commit f61bb626ac
4 changed files with 88 additions and 37 deletions

View File

@@ -1,7 +1,7 @@
/* eslint-disable indent */
import { apiFail } from '@/data/constants'
import { useLocalStorage } from '@vueuse/core'
import { APIRoot, PaginationResponse } from './api-models'
import { apiFail } from '@/data/constants'
const cookie = useLocalStorage('JWT_Token', '')
@@ -62,16 +62,21 @@ export async function QueryGetAPI<T>(
return await QueryGetAPIInternal<APIRoot<T>>(urlString, params, headers)
}
async function QueryGetAPIInternal<T>(urlString: string, params?: any, headers?: [string, string][]) {
const url = new URL(urlString)
url.search = getParams(params)
if (cookie.value) {
headers ??= []
if (cookie.value) headers?.push(['Authorization', `Bearer ${cookie.value}`])
try {
const url = new URL(urlString)
url.search = getParams(params)
if (cookie.value) {
headers ??= []
if (cookie.value) headers?.push(['Authorization', `Bearer ${cookie.value}`])
}
return await QueryAPIInternal<T>(url, {
method: 'get',
headers: headers,
})
} catch (err) {
console.log(`url:${urlString}, error:${err}`)
throw err
}
return await QueryAPIInternal<T>(url, {
method: 'get',
headers: headers,
})
}
function getParams(params: any) {
const urlParams = new URLSearchParams(window.location.search)