|
@@ -0,0 +1,94 @@
|
|
|
+import { useArticle } from "@/modules";
|
|
|
+import { SearchOutlined } from "@ant-design/icons-vue";
|
|
|
+import { Input, List, Pagination } from "ant-design-vue";
|
|
|
+import { defineComponent, onMounted, reactive, watch } from "vue";
|
|
|
+import { useRoute, useRouter } from "vue-router";
|
|
|
+import Item from "./item";
|
|
|
+
|
|
|
+const PAGE_SIZE = 10;
|
|
|
+
|
|
|
+export default defineComponent({
|
|
|
+ setup() {
|
|
|
+ const route = useRoute();
|
|
|
+ const router = useRouter();
|
|
|
+ const { query } = route;
|
|
|
+
|
|
|
+ const storeArt = useArticle();
|
|
|
+
|
|
|
+ const state = reactive({
|
|
|
+ list: [],
|
|
|
+ total: 0,
|
|
|
+ keyword: query.q as string,
|
|
|
+ value: query.q as string,
|
|
|
+ });
|
|
|
+
|
|
|
+ const getData = async (page = 1) => {
|
|
|
+ if (!state.keyword) return;
|
|
|
+ const query = {
|
|
|
+ page: page,
|
|
|
+ size: PAGE_SIZE,
|
|
|
+ query: JSON.stringify({ key: state.keyword }),
|
|
|
+ };
|
|
|
+ const res = await storeArt.searchArticle(query);
|
|
|
+ const list = res.list || [];
|
|
|
+ state.list = list;
|
|
|
+ state.total = res.total;
|
|
|
+ };
|
|
|
+
|
|
|
+ const search = (e: any) => {
|
|
|
+ router.push({ path: "/search", query: { q: e.target.value } });
|
|
|
+ };
|
|
|
+
|
|
|
+ onMounted(() => getData());
|
|
|
+
|
|
|
+ watch(
|
|
|
+ () => route.query.q,
|
|
|
+ () => {
|
|
|
+ state.keyword = route.query.q as string;
|
|
|
+ state.value = route.query.q as string;
|
|
|
+ getData();
|
|
|
+ }
|
|
|
+ );
|
|
|
+
|
|
|
+ return () => {
|
|
|
+ return (
|
|
|
+ <div class="detail_page_w">
|
|
|
+ <div class="flex items-center mt-60px mb-50px py-10px pr-17px px-10px bg-light-50 <md:(mt-30px mb-25px)">
|
|
|
+ <div class="flex-1">
|
|
|
+ <Input
|
|
|
+ class="!text-16px"
|
|
|
+ placeholder="请输入关键词"
|
|
|
+ bordered={false}
|
|
|
+ value={state.value}
|
|
|
+ onPressEnter={search}
|
|
|
+ onChange={(e: any) => (state.value = e.target.value)}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ <SearchOutlined class="text-18px cursor-pointer !text-gray-600 hover:opacity-80 active:opacity-60" />
|
|
|
+ </div>
|
|
|
+ <div class="mt-50px <md:mt-25px">
|
|
|
+ <div class="my-15px text-16px !leading-normal <md:(my-10px text-14px)">
|
|
|
+ 检索完成,共有{state.total}项结果符合您检索的关键词:
|
|
|
+ <span class="font-bold">{state.keyword}</span>
|
|
|
+ </div>
|
|
|
+ <List dataSource={state.list} class="bg-light-50">
|
|
|
+ {{
|
|
|
+ renderItem: ({ item }: any) => <Item record={item} />,
|
|
|
+ }}
|
|
|
+ </List>
|
|
|
+ {state.list.length > 0 && (
|
|
|
+ <div class="my-50px text-center">
|
|
|
+ <Pagination
|
|
|
+ total={state.total}
|
|
|
+ pageSize={PAGE_SIZE}
|
|
|
+ showSizeChanger={false}
|
|
|
+ onChange={getData}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ )}
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+ };
|
|
|
+ },
|
|
|
+});
|