import {request} from '@/utils/request.js' const loadingTime = 500; const showLog = false; const api = { wxLogin(data) { return request('/login/wechat_mobile_login', data, 'post', true); }, mobileLogin(data) { return request('/login/mobile_login', data, 'post', true); }, getCode(data) { return request('/code/phone', data, 'post', true); }, getHomeData(data) { //首页数据 return request('/index', data, 'get', true); }, getClassify(id) { //获取分类详情 return request('/class/' + id, {}, 'get', true); }, getClassifyList() { //获取分类详情 return request('/class/list', {}, 'get', false); }, getQuestionPage(data) { //获取问题列表-分页 return request('/question/page', data, 'post', true, 'application/json'); }, queryList(data) { const listCount = 24; return _queryList(data, listCount); } }; function _queryList(data, listCount, showNews = false ,random = false, showChat = false) { if (!data.pageNo || !data.pageSize) { return _callQueryResult([]); } let pageNo = parseInt(data.pageNo); let pageSize = parseInt(data.pageSize); let type = data.type || 0; if (pageNo < 0 || pageSize <= 0) { return _callQueryResult([]); } if (showLog) { console.log('%c\n----------请求开始--------', 'color:green;'); console.info(`请求参数:【pageNo:${pageNo},pageSize:${pageSize}】`) console.log('%c----------请求结束--------\n', 'color:green;'); } uni.showLoading({ title: '加载中...' }) if (pageNo == 0) { pageNo = 1; } var totalPagingList = []; for (let i = 0; i < listCount; i++) { if (!showChat) { const item = { 'title': (i + 1).toString(), 'detail': '测试信息' + type }; if (showNews) { item.detail = getNews(random); } totalPagingList.push(item); } else { const item = { 'name': '哆啦A梦', 'icon': '/static/duola.jpg', 'content': getNews(true), 'isMe': false }; totalPagingList.push(item); } } let pageNoIndex = (pageNo - 1) * pageSize; if (pageNoIndex + pageSize <= totalPagingList.length) { return _callQueryResult(totalPagingList.splice(pageNoIndex, pageSize)); } else if (pageNoIndex < totalPagingList.length) { return _callQueryResult(totalPagingList.splice(pageNoIndex, totalPagingList.length - pageNoIndex)); } else { return _callQueryResult([]); } } function _callQueryResult(arg) { return new Promise((resolve, reject) => { setTimeout(() => { uni.hideLoading(); if (showLog) { console.log('%c\n----------响应开始--------', 'color:#0113fa;'); // #ifdef H5 console.table(arg); // #endif // #ifndef H5 console.log(arg); // #endif console.log('%c----------响应结束--------\n', 'color:#0113fa;'); } resolve({ data: { list: arg } }); }, loadingTime) }) } export default api