diff --git a/src/api/book.js b/src/api/book.js index 941049f..885d688 100644 --- a/src/api/book.js +++ b/src/api/book.js @@ -1,5 +1,9 @@ import request from '../utils/request' +export function listCategorys(params) { + return request.get('/book/categoryList', { params }); +} + export function searchBooks(params) { return request.get('/book/search', { params }); } diff --git a/src/utils/index.js b/src/utils/index.js index e748471..a3fdd64 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -24,4 +24,52 @@ export const getLocal = (name) => { export const setLocal = (name, value) => { localStorage.setItem(name, value) -} \ No newline at end of file +} + +export const addDay = (days) => { + //创建date + let nowDate = new Date(); + //添加天数 + nowDate.setDate(nowDate.getDate() + days); + //返回 + return nowDate +} + +export const addMonth= (months) => { + //创建date + let nowDate = new Date(); + //添加周数 + nowDate.setMonth(nowDate.getMonth() + months); + //返回 + return nowDate +} + +export const addYear= (years) => { + //创建date + let nowDate = new Date(); + //添加年数 + nowDate.setMonth(nowDate.getYear() + years); + //返回 + return nowDate +} + +export const dateFormat = (fmt, date) => { + let ret; + const opt = { + "Y+": date.getFullYear().toString(), // 年 + "m+": (date.getMonth() + 1).toString(), // 月 + "d+": date.getDate().toString(), // 日 + "H+": date.getHours().toString(), // 时 + "M+": date.getMinutes().toString(), // 分 + "S+": date.getSeconds().toString() // 秒 + // 有其他格式化字符需求可以继续添加,必须转化成字符串 + }; + for (let k in opt) { + ret = new RegExp("(" + k + ")").exec(fmt); + if (ret) { + fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0"))) + }; + }; + return fmt; +} + diff --git a/src/views/BookClass.vue b/src/views/BookClass.vue index 015ef82..274c670 100644 --- a/src/views/BookClass.vue +++ b/src/views/BookClass.vue @@ -5,125 +5,174 @@
- +
@@ -184,7 +233,8 @@ import "@/assets/styles/book.css"; import { reactive, toRefs, onMounted, ref } from "vue"; import { useRouter, useRoute } from "vue-router"; -import { searchBooks } from "@/api/book"; +import { searchBooks, listCategorys } from "@/api/book"; +import { addDay, dateFormat } from "@/utils"; import Top from "@/components/common/Top"; import Navbar from "@/components/common/Navbar"; import Footer from "@/components/common/Footer"; @@ -200,18 +250,25 @@ export default { const router = useRouter(); const state = reactive({ + bookCategorys: [], books: [], searchCondition: {}, backgroud: true, total: 0, pageSize: 10, imgBaseUrl: process.env.VUE_APP_BASE_IMG_URL, + workDirectionOn: 0, + categoryOn: 0, + bookStatusOn: null, + wordCountOn: null, + updateTimeOn: null, + sortOn:null }); onMounted(() => { const key = route.query.key; state.searchCondition.keyword = key; state.searchCondition.pageSize = 10; - search(); + loadCategoryList(0); }); const search = async () => { @@ -235,12 +292,71 @@ export default { search(); }; + const loadCategoryList = async (workDirection) => { + const { data } = await listCategorys({ workDirection: workDirection }); + state.bookCategorys = data; + state.workDirectionOn = workDirection; + state.searchCondition.workDirection = workDirection; + state.categoryOn = 0; + state.searchCondition.categoryId = null; + search(); + }; + + const changeCategory = async (categoryId) => { + state.categoryOn = categoryId; + if (categoryId > 0) { + state.searchCondition.categoryId = categoryId; + } else { + state.searchCondition.categoryId = null; + } + search(); + }; + + const changeBookStatus = async (bookStatus) => { + state.bookStatusOn = bookStatus; + state.searchCondition.bookStatus = bookStatus; + search(); + }; + + const changeWordCount = async (wordCountMin, wordCountMax) => { + state.wordCountOn = wordCountMin; + state.searchCondition.wordCountMin = wordCountMin; + state.searchCondition.wordCountMax = wordCountMax; + + search(); + }; + + const changeUpdateTime = async (days) => { + state.updateTimeOn = days; + if (days) { + state.searchCondition.updateTimeMin = dateFormat( + "YYYY-mm-dd", + addDay(-days) + ); + } else { + state.searchCondition.updateTimeMin = null; + } + search(); + }; + + const changeSort = async (sort) => { + state.sortOn = sort; + state.searchCondition.sort = sort; + search(); + }; + return { ...toRefs(state), bookDetail, searchByK, search, handleCurrentChange, + loadCategoryList, + changeCategory, + changeBookStatus, + changeWordCount, + changeUpdateTime, + changeSort }; }, computed: {