Skip to content

Commit

Permalink
搜索修复
Browse files Browse the repository at this point in the history
  • Loading branch information
jianyun8023 committed Aug 27, 2024
1 parent bcecbcd commit 07e0e5a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions app/calibre-pages/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export async function fetchRecentBooks(limit: number, offset: number) {
return response.json().then((data) => data.data);
}

export async function fetchBooks(filter: string[], limit: number, offset: number) {
const response = await fetch('/api/search?q=', {
export async function fetchBooks(keyword: string, filter: string[], limit: number, offset: number) {
const response = await fetch('/api/search?q=' + keyword, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down
2 changes: 1 addition & 1 deletion app/calibre-pages/src/views/BatchMeta.vue
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ export default {
if (this.filterType === 'isbn') {
this.filter[0] = `isbn = "${this.keyword}"`;
}
const data = await fetchBooks(this.filter, this.limit, this.offset);
const data = await fetchBooks("", this.filter, this.limit, this.offset);
this.books = data.records
this.total = data.total
Expand Down
30 changes: 15 additions & 15 deletions app/calibre-pages/src/views/Search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<div class="affix-container">
<el-affix target=".affix-container">
<el-input
v-model="searchQuery"
@input="fetchBooks"
type="text"
placeholder="书名、作者、ISBN"
class=""
v-model="searchQuery"
@input="fetchBooks"
type="text"
placeholder="书名、作者、ISBN"
class=""
/>
</el-affix>
</div>
Expand All @@ -17,39 +17,39 @@
<strong style="margin-left: 10px">{{ keyword }}</strong>
</h2>
<el-text
>共计 {{ total }} 条, 当前{{ offset }} --
>共计 {{ total }} 条, 当前{{ offset }} --
{{ offset + limit >= total ? total : offset + limit }}
</el-text>

<el-row :gutter="20">
<el-col v-for="book in books" :key="book.id" :span="6" :lg="6" :sm="12" :xs="24">
<BookCard :book="book" :more_info="true" />
<BookCard :book="book" :more_info="true"/>
</el-col>
</el-row>
<el-row class="mt-4" justify="center">
<el-button @click="prevPage" :disabled="offset === 0">
<el-icon>
<ArrowLeftBold />
<ArrowLeftBold/>
</el-icon>
上一页
</el-button>
<el-button @click="nextPage" :disabled="offset + limit >= total"
>下一页
>下一页
<el-icon>
<ArrowRightBold />
<ArrowRightBold/>
</el-icon>
</el-button>
</el-row>
</template>

<script lang="ts">
import BookCard from '@/components/BookCard.vue'
import { ElButton, ElCol, ElInput, ElRow } from 'element-plus'
import {ElButton, ElCol, ElInput, ElRow} from 'element-plus'
import {fetchBooks} from "@/api/api";
export default {
name: 'Search',
components: { ElInput, ElButton, ElRow, ElCol, BookCard },
components: {ElInput, ElButton, ElRow, ElCol, BookCard},
data() {
return {
searchQuery: '',
Expand Down Expand Up @@ -91,7 +91,7 @@ export default {
methods: {
async fetchBooks() {
const data = await fetchBooks(this.filter, this.limit, this.offset);
const data = await fetchBooks(this.searchQuery, this.filter, this.limit, this.offset);
this.books = data.records
this.total = data.total
},
Expand All @@ -109,7 +109,7 @@ export default {
}
},
updateQueryParams() {
let query = { ...this.$route.query, offset: this.offset, limit: this.limit }
let query = {...this.$route.query, offset: this.offset, limit: this.limit}
if (this.searchQuery) {
query.q = this.searchQuery
}
Expand All @@ -119,7 +119,7 @@ export default {
if (this.author) {
query.author = this.author
}
this.$router.push({ query: query })
this.$router.push({query: query})
},
initializeFromQueryParams() {
const query = this.$route.query
Expand Down

0 comments on commit 07e0e5a

Please sign in to comment.