Skip to content

Commit

Permalink
fix: tags api
Browse files Browse the repository at this point in the history
  • Loading branch information
MarleneJiang committed Jan 29, 2023
1 parent 91cd4ce commit a65ab0a
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,4 @@ dist
.tern-port
.vercel
frontend/.env
backend/src/extensions/documentation/documentation/1.0.0/full_documentation.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"name": "Apache 2.0",
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
},
"x-generation-date": "2023-01-28T14:10:48.649Z"
"x-generation-date": "2023-01-29T12:28:39.928Z"
},
"x-strapi-config": {
"path": "/documentation",
Expand Down
5 changes: 3 additions & 2 deletions frontend/components/Aside/ArticleList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ defineProps({
required: true,
},
})
tags = ['前端']
const { data: ArticleList } = await useFetch(`/api/articles/tags?tags=${tags}&authorId=${item.authorId}`)
const tags = ['前端']
const authorId = '5'
const { data: ArticleList } = await useFetch(`/api/articles/tags?tags=${JSON.stringify(tags)}&authorId=${authorId}`)
</script>

<template>
Expand Down
2 changes: 1 addition & 1 deletion frontend/server/api/articles/[id].ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useGraphql } from '~~/composables/useGraphql'
import { useGraphql } from '~~/utils/useGraphql'
import type { IArticle } from '~~/types/IArticle'
export default defineEventHandler(async (event): Promise<IArticle> => {
const id = event.context.params.id
Expand Down
2 changes: 1 addition & 1 deletion frontend/server/api/articles/columns/[id].ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useGraphql } from '~~/composables/useGraphql'
import { useGraphql } from '~~/utils/useGraphql'

interface IArticleItem {
id: string
Expand Down
2 changes: 1 addition & 1 deletion frontend/server/api/articles/list.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useGraphql } from '~~/composables/useGraphql'
import { useGraphql } from '~~/utils/useGraphql'
import { useTime } from '~~/composables/useTime'
interface IAuthor {
name: string
Expand Down
2 changes: 1 addition & 1 deletion frontend/server/api/articles/tags.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useGraphql } from '~~/composables/useGraphql'
import { useGraphql } from '~~/utils/useGraphql'
interface ITagItem {
tag: string
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/server/api/authors/list.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useGraphql } from '~~/composables/useGraphql'
import { useGraphql } from '~~/utils/useGraphql'
interface IAuthorListItem {
name: string
motto: string
Expand Down
2 changes: 1 addition & 1 deletion frontend/server/api/global/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useGraphql } from '~~/composables/useGraphql'
import { useGraphql } from '~~/utils/useGraphql'
interface IGadget {
title: string
subscribe: string
Expand Down
2 changes: 1 addition & 1 deletion frontend/server/api/global/navs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useGraphql } from '~~/composables/useGraphql'
import { useGraphql } from '~~/utils/useGraphql'
interface INavItem {
name: string
url: string
Expand Down
2 changes: 1 addition & 1 deletion frontend/server/api/global/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useGraphql } from '~~/composables/useGraphql'
import { useGraphql } from '~~/utils/useGraphql'
interface ITypeItem {
type: string
}
Expand Down
40 changes: 24 additions & 16 deletions frontend/composables/useGraphql.ts → frontend/utils/useGraphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,31 @@ const removeStrapiWrapper = (data: any) => {
}

export async function useGraphql(query: any) {
const runtimeConfig = useRuntimeConfig()
const data = JSON.stringify({
query,
})
const config = {
method: 'post',
url: runtimeConfig.public.graphql_url,
headers: {
'Content-Type': 'application/json',
'Accept': '*/*',
'Connection': 'keep-alive',
},
data,
}
try {
const runtimeConfig = useRuntimeConfig()
const data = JSON.stringify({
query,
})
const config = {
method: 'post',
url: runtimeConfig.public.graphql_url,
headers: {
'Content-Type': 'application/json',
'Accept': '*/*',
'Connection': 'keep-alive',
},
data,
}

const res = await axios(config)
const res = await axios(config)

return removeStrapiWrapper(res.data)
return removeStrapiWrapper(res.data)
}
catch (err: any) {
console.error('API请求错误')
console.error('状态码', err.response.status)
console.error('请求数据', err.config.data)
console.error('错误说明', err.response.data)
}
}

0 comments on commit a65ab0a

Please sign in to comment.