| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416 |
- "use strict";
- const common_vendor = require("../common/vendor.js");
- const utils_config = require("./config.js");
- const BASE_URL = utils_config.config.BASE_URL;
- function request(url, method = "GET", data = {}) {
- return new Promise((resolve, reject) => {
- if (method !== "GET") {
- common_vendor.index.showLoading({
- title: "请求中...",
- mask: false
- });
- }
- common_vendor.index.request({
- url: BASE_URL + url,
- method,
- data,
- header: {
- "Content-Type": "application/json"
- },
- timeout: utils_config.config.TIMEOUT,
- success: (res) => {
- if (method !== "GET") {
- common_vendor.index.hideLoading();
- }
- if (res.statusCode === 200) {
- if (res.data.code === 200) {
- resolve(res.data);
- } else {
- reject(new Error(res.data.message || "请求失败"));
- }
- } else {
- reject(new Error("网络请求失败,状态码:" + res.statusCode));
- }
- },
- fail: (err) => {
- if (method !== "GET") {
- common_vendor.index.hideLoading();
- }
- common_vendor.index.__f__("error", "at utils/api.js:53", "API请求失败:", err);
- reject(new Error("网络请求失败,请检查网络连接"));
- }
- });
- });
- }
- function get(url, data = {}) {
- return request(url, "GET", data);
- }
- function post(url, data = {}) {
- return request(url, "POST", data);
- }
- function put(url, data = {}) {
- return request(url, "PUT", data);
- }
- function del(url, data = {}) {
- return request(url, "DELETE", data);
- }
- function login(username, password) {
- return post("/user/login", {
- username,
- password
- });
- }
- function register(data) {
- return post("/user/register", data);
- }
- function getBooks(params) {
- return get("/book/list", params);
- }
- function getBookById(id, userId) {
- const params = {};
- if (userId !== void 0 && userId !== null) {
- params.userId = userId;
- }
- return get(`/book/${id}`, params);
- }
- function getTodayRecommend(limit = 8) {
- return get("/book/today-recommend", {
- limit
- });
- }
- function getBestsellers(limit = 10) {
- return get("/book/bestsellers", {
- limit
- });
- }
- function getAllBooks(page = 1, size = 10) {
- return get("/book/all", {
- page,
- size
- });
- }
- function getRankingBooks(limit = 10) {
- return get("/book/ranking", {
- limit
- });
- }
- function getPopularBooks(limit = 10) {
- return get("/book/popular", {
- limit
- });
- }
- function getNewBooks(limit = 10) {
- return get("/book/new", {
- limit
- });
- }
- function getVipBooks(page = 1, size = 10) {
- return get("/book/vip", {
- page,
- size
- });
- }
- function getFeaturedList(limit = 4) {
- return get("/book/featured-list", {
- limit
- });
- }
- function getAllCategories() {
- return get("/category/list");
- }
- function getMoreRecommend(limit = 6) {
- return get("/book/more-recommend", {
- limit
- });
- }
- function getUserProfile(userId) {
- return get("/user/profile", { userId });
- }
- function updateUserProfile(payload) {
- return request("/user/profile", "PUT", payload);
- }
- function addToBookshelf(userId, bookId) {
- return post("/bookshelf/add", {
- userId,
- bookId
- });
- }
- function getBookshelfList(userId) {
- return get("/bookshelf/list", {
- userId
- });
- }
- function checkInBookshelf(userId, bookId) {
- return get("/bookshelf/check", {
- userId,
- bookId
- });
- }
- function addAudiobookToBookshelf(userId, audiobookId) {
- return post("/audiobook-bookshelf/add", {
- userId,
- audiobookId
- });
- }
- function removeAudiobookFromBookshelf(userId, audiobookId) {
- return request("/audiobook-bookshelf/remove", "DELETE", {
- userId,
- audiobookId
- });
- }
- function getAudiobookBookshelfList(userId) {
- return get("/audiobook-bookshelf/list", {
- userId
- });
- }
- function checkAudiobookInBookshelf(userId, audiobookId) {
- return get("/audiobook-bookshelf/check", {
- userId,
- audiobookId
- });
- }
- function getRecentAudiobooks(limit = 8) {
- return get("/audiobook/recent", {
- limit
- });
- }
- function getPopularAudiobooks(limit = 10) {
- return get("/audiobook/popular", {
- limit
- });
- }
- function getRecommendAudiobooks(limit = 10) {
- return get("/audiobook/recommend", {
- limit
- });
- }
- function getRankingAudiobooks(limit = 10) {
- return get("/audiobook/ranking", {
- limit
- });
- }
- function getAudiobookDetail(id, userId = null) {
- const params = userId ? { userId } : {};
- return get(`/audiobook/${id}`, params);
- }
- function getChapterDetail(chapterId, userId) {
- const params = {};
- if (userId !== void 0 && userId !== null) {
- params.userId = userId;
- }
- return get(`/audiobook/chapter/${chapterId}`, params);
- }
- function recordListeningHistory(userId, audiobookId, chapterId) {
- return post("/audiobook/history", {
- userId,
- audiobookId,
- chapterId
- });
- }
- function saveListeningProgress(userId, audiobookId, chapterId, currentPosition, duration) {
- return post("/audiobook/progress", {
- userId,
- audiobookId,
- chapterId,
- currentPosition,
- duration
- });
- }
- function getListeningProgress(userId, chapterId) {
- return get("/audiobook/progress", {
- userId,
- chapterId
- });
- }
- function playChapter(audiobookId, chapterId) {
- return post("/audiobook/play", {
- audiobookId,
- chapterId
- });
- }
- function getBookChapters(bookId) {
- return get("/chapter/list", {
- bookId
- });
- }
- function getBookChapterDetail(chapterId) {
- return get(`/chapter/${chapterId}`);
- }
- function searchBooks(keyword, page = 1, size = 20) {
- return get("/book/search", {
- keyword,
- page,
- size
- });
- }
- function getPopularKeywords(limit = 10) {
- return get("/book/popular-keywords", {
- limit
- });
- }
- function searchAudiobooks({ keyword, page = 1, size = 20, categoryId, status, isVip, isFree } = {}) {
- const params = { keyword, page, size };
- if (categoryId !== void 0 && categoryId !== null)
- params.categoryId = categoryId;
- if (status !== void 0 && status !== null)
- params.status = status;
- if (isVip !== void 0 && isVip !== null)
- params.isVip = isVip;
- if (isFree !== void 0 && isFree !== null)
- params.isFree = isFree;
- return get("/audiobook/list", params);
- }
- function getBannersByCode(code) {
- return get("/banner/list", { code });
- }
- function getAllRankingGroups() {
- return get("/ranking/groups");
- }
- function getRankingByCode(code, categoryId = null) {
- const params = { code };
- if (categoryId !== null && categoryId !== void 0) {
- params.categoryId = categoryId;
- }
- return get("/ranking/list", params);
- }
- function recordBrowsingHistory(userId, bookId) {
- return post("/browsing-history/record", {
- userId,
- bookId
- });
- }
- function getBrowsingHistory(userId) {
- return get("/browsing-history/list", {
- userId
- });
- }
- function clearBrowsingHistory(userId) {
- return del("/browsing-history/clear", {
- userId
- });
- }
- function addComment(userId, bookId, content) {
- return post("/comment/add", {
- userId,
- bookId,
- content
- });
- }
- function getComments(bookId, userId = null) {
- const params = { bookId };
- if (userId !== null && userId !== void 0) {
- params.userId = userId;
- }
- return get("/comment/list", params);
- }
- function toggleCommentLike(userId, commentId) {
- return post("/comment/like", {
- userId,
- commentId
- });
- }
- function recordSearchHistory(userId, keyword) {
- return post("/search-history/record", {
- userId,
- keyword
- });
- }
- function getSearchHistory(userId, limit = 10) {
- return get("/search-history/list", {
- userId,
- limit
- });
- }
- function clearSearchHistory(userId) {
- return del("/search-history/clear", {
- userId
- });
- }
- function submitFeedback(feedbackData) {
- return post("/feedback/submit", feedbackData);
- }
- function getMessages(userId, isRead, type, page = 1, size = 20) {
- const params = { userId };
- if (isRead !== void 0 && isRead !== null) {
- params.isRead = isRead;
- }
- if (type) {
- params.type = type;
- }
- params.page = page;
- params.size = size;
- return get("/message/list", params);
- }
- function markMessageAsRead(id) {
- return put(`/message/read/${id}`, {});
- }
- function getVipPlans() {
- return get("/vip/plans");
- }
- function purchaseVip(purchaseData) {
- return post("/vip/purchase", purchaseData);
- }
- function getVipRecords(userId, paymentStatus, page = 1, size = 10) {
- const params = { userId, page, size };
- if (paymentStatus !== void 0 && paymentStatus !== null) {
- params.paymentStatus = paymentStatus;
- }
- return get("/vip/records", params);
- }
- exports.addAudiobookToBookshelf = addAudiobookToBookshelf;
- exports.addComment = addComment;
- exports.addToBookshelf = addToBookshelf;
- exports.checkAudiobookInBookshelf = checkAudiobookInBookshelf;
- exports.checkInBookshelf = checkInBookshelf;
- exports.clearBrowsingHistory = clearBrowsingHistory;
- exports.clearSearchHistory = clearSearchHistory;
- exports.getAllBooks = getAllBooks;
- exports.getAllCategories = getAllCategories;
- exports.getAllRankingGroups = getAllRankingGroups;
- exports.getAudiobookBookshelfList = getAudiobookBookshelfList;
- exports.getAudiobookDetail = getAudiobookDetail;
- exports.getBannersByCode = getBannersByCode;
- exports.getBestsellers = getBestsellers;
- exports.getBookById = getBookById;
- exports.getBookChapterDetail = getBookChapterDetail;
- exports.getBookChapters = getBookChapters;
- exports.getBooks = getBooks;
- exports.getBookshelfList = getBookshelfList;
- exports.getBrowsingHistory = getBrowsingHistory;
- exports.getChapterDetail = getChapterDetail;
- exports.getComments = getComments;
- exports.getFeaturedList = getFeaturedList;
- exports.getListeningProgress = getListeningProgress;
- exports.getMessages = getMessages;
- exports.getMoreRecommend = getMoreRecommend;
- exports.getNewBooks = getNewBooks;
- exports.getPopularAudiobooks = getPopularAudiobooks;
- exports.getPopularBooks = getPopularBooks;
- exports.getPopularKeywords = getPopularKeywords;
- exports.getRankingAudiobooks = getRankingAudiobooks;
- exports.getRankingBooks = getRankingBooks;
- exports.getRankingByCode = getRankingByCode;
- exports.getRecentAudiobooks = getRecentAudiobooks;
- exports.getRecommendAudiobooks = getRecommendAudiobooks;
- exports.getSearchHistory = getSearchHistory;
- exports.getTodayRecommend = getTodayRecommend;
- exports.getUserProfile = getUserProfile;
- exports.getVipBooks = getVipBooks;
- exports.getVipPlans = getVipPlans;
- exports.getVipRecords = getVipRecords;
- exports.login = login;
- exports.markMessageAsRead = markMessageAsRead;
- exports.playChapter = playChapter;
- exports.purchaseVip = purchaseVip;
- exports.recordBrowsingHistory = recordBrowsingHistory;
- exports.recordListeningHistory = recordListeningHistory;
- exports.recordSearchHistory = recordSearchHistory;
- exports.register = register;
- exports.removeAudiobookFromBookshelf = removeAudiobookFromBookshelf;
- exports.saveListeningProgress = saveListeningProgress;
- exports.searchAudiobooks = searchAudiobooks;
- exports.searchBooks = searchBooks;
- exports.submitFeedback = submitFeedback;
- exports.toggleCommentLike = toggleCommentLike;
- exports.updateUserProfile = updateUserProfile;
- //# sourceMappingURL=../../.sourcemap/mp-weixin/utils/api.js.map
|