const request = require('./WXHttpRequest.js'); const url = require('./const.js'); const loginSchedule = require('./loginSchedule.js'); const HOST = url.apiUrl; const HOSTTwo = url.apiUrlTwo; function genAPIUrl(action) { return HOST + action; } function genAPIUrlTwo(action) { return HOSTTwo + action; } // function genData(data) { // debugger; // let commonData = { // platform_type: PLATFORM // } // for (let key in commonData) { // data[key] = commonData[key]; // } // return data; // } //没有登录的提示 function showModal() { wx.showModal({ title: '提示', content: '需要获取您的公开信息(昵称、头像等),请从小程序列表删除快乐学堂小助手后再次扫码进入,允许授权后可正常使用', showCancel: false, success: function (res) { if (res.confirm) { console.log('用户点击确定') } else if (res.cancel) { console.log('用户点击取消') } } }) } module.exports = { // 获取我的data getMySchedule(header) { let url = genAPIUrl('wx/ucenter'); return request.getInstance().url(url).header(header).send(); }, //获取推荐课程 getRecommendSchedule(header) { let url = genAPIUrl('wx/course/recommend'); return request.getInstance().url(url).header(header).send(); }, //发送上传图片 getSendSchedule(header, data) { let url = genAPIUrl('wx/posts'); return request.getInstance().url(url).header(header).data(data).method('POST').send(); }, //获取分享作品list getProductionSchedule(header, data) { let url = genAPIUrl('wx/posts/reply'); return request.getInstance().url(url).header(header).data(data).method('GET').send(); }, //保存评论 getDiscussSchedule(header, data) { let url = genAPIUrl('wx/reply'); return request.getInstance().url(url).header(header).data(data).method('POST').send(); }, //分享查询单条 getOneSchedule(header, data) { let url = genAPIUrl('wx/posts/one'); return request.getInstance().url(url).header(header).data(data).method('GET').send(); }, //各个科目信息 getEachSchedule(header, data) { let url = genAPIUrl('wx/course'); return request.getInstance().url(url).header(header).data(data).method('GET').send(); }, //各个排名 getFriendSchedule(urls, header) { let url = genAPIUrl(urls); return request.getInstance().url(url).header(header).method('GET').send(); }, //更改昵称 getSetNameSchedule(header, data) { let url = genAPIUrl('wx/ucenter/user/update'); return request.getInstance().url(url).header(header).data(data).method('GET').send(); }, //分享后点赞 getLikeSchedule(header, data) { let url = genAPIUrl('wx/posts/attribute'); return request.getInstance().url(url).header(header).data(data).method('GET').send(); }, //取消小点 cancelDian(header, data) { let url = genAPIUrl('wx/posts/readCount'); return request.getInstance().url(url).header(header).data(data).method('GET').send(); }, //获取错题本 getErrorsSchedule(header, data) { let url = genAPIUrl('wx/question/wrong'); return request.getInstance().url(url).header(header).data(data).method('GET').send(); }, //记录用户操作 getStatisticsOpt (header, data) { let url = genAPIUrl('wx/statistics/opt'); return request.getInstance().url(url).header(header).data(data).method('POST').send(); }, //获取用户答题指数 getExponentSchedule(header) { let url = genAPIUrl('wx/question/exponent'); return request.getInstance().url(url).header(header).method('GET').send(); }, //获取二维码 getqrCode(data) { let url = genAPIUrl('wx/qrCode/postsCache'); return request.getInstance().url(url).header({ uid: wx.getStorageSync('uid') }).data(data).method('GET').send(); }, //操作留言 setMessage(data) { let url = genAPIUrl('wx/posts'); return request.getInstance().url(url).header({ uid: wx.getStorageSync('uid') }).data(data).method('PUT').send(); }, /**另一个小程序接口调用从此处开始 */ // 获取课程表列表 getClassSchedule() { let url = genAPIUrlTwo('wx/classSchedule/list'); return request.getInstance().url(url).send(); }, // 课程表详情列表 getClassScheduleWeekly(itemId, userId) { if (!userId) { loginSchedule.getOpenidSessionKeyTwo(function (res) { wx.navigateBack(); wx.navigateTo({ url: `/pages/schedule/scheduleSubject/scheduleSubject?scene=sc&id=${itemId}` }) }, function (res) { wx.navigateBack() }); } let url = genAPIUrlTwo(`wx/classSchedule/weekly/${itemId}`); //let data = genData({ userId }) return request.getInstance().data({ userId }).url(url).send(); }, // 课程表详情列表二维码 getClassScheduleWeeklyQR(itemId, userId, showId) { if (!userId) { loginSchedule.getOpenidSessionKeyTwo(function (res) { wx.navigateBack() wx.navigateTo({ url: `/pages/schedule/scheduleSubject/scheduleSubject?scene=sc&id=${itemId}&showId=${showId}` }) }, function (res) { wx.navigateBack() showModal() }); } let url = genAPIUrlTwo(`wx/classSchedule/weekly/${itemId}`); //let data = genData({ userId, showId }) return request.getInstance().data({ userId, showId }).url(url).send(); }, // 课程表详情问答列表 getQAList(userId, columnId, columnType, pageNo, pageSize) { let url = genAPIUrlTwo(`wx/posts`); let data = { userId, columnId, columnType, pageNo, pageSize } return request.getInstance().url(url).data(data).send(); }, // 添加问题 addQuestion(userId, columnId, columnType, title, columnNames) { let url = genAPIUrlTwo(`wx/posts`); let header = {'content-type': 'application/x-www-form-urlencoded'} let data = { userId, columnId, columnType, title, columnNames } return request.getInstance().url(url).header(header).method('POST').data(data).send(); }, // 添加问题回复 addReply(userId, postsId, content, columnNames) { let url = genAPIUrlTwo(`wx/posts/addReply`); let header = {'content-type': 'application/x-www-form-urlencoded'} let data = { userId, postsId, content, columnNames } return request.getInstance().url(url).header(header).method('POST').data(data).send(); }, // 问题点赞 addPraise(userId, id) { let url = genAPIUrlTwo(`wx/posts/like`); let header = {'content-type': 'application/x-www-form-urlencoded'} let data = { userId, id } return request.getInstance().url(url).header(header).method('POST').data(data).send(); }, // 问题取消点赞 cancelPraise(userId, id) { let url = genAPIUrlTwo(`wx/posts/unlike`); let header = {'content-type': 'application/x-www-form-urlencoded'} let data = { userId, id } return request.getInstance().url(url).header(header).method('POST').data(data).send(); }, // 直播课资料列表 getMaterials(columnId) { let url = genAPIUrlTwo(`wx/classSchedule/courseware/${columnId}`); return request.getInstance().url(url).send(); }, // 课程表资料列表 getScheduleMaterials(userId, itemId) { let url = genAPIUrlTwo(`wx/classSchedule/courseware/${itemId}`); let data = { userId } return request.getInstance().url(url).data(data).send(); }, // 添加收藏 toggleCollection(userId, favoritesCode, favoritesType, name) { let url = genAPIUrlTwo('wx/favorites') let header = {'content-type': 'application/x-www-form-urlencoded'} let data = { userId, favoritesCode, favoritesType, name } return request.getInstance().url(url).method('POST').header(header).data(data).send() }, // 获取teacherID title goal getScheduleGoal(itemId) { let url = genAPIUrlTwo(`wx/classSchedule/goal/${itemId}`); return request.getInstance().url(url).send(); }, // 课程表详情中的课程表和学习目标 getScheduleDetailGoalSchedule(itemId, type, userId) { let url = genAPIUrlTwo(`wx/classSchedule/info/${itemId}`); let data = { type, userId } return request.getInstance().url(url).data(data).send(); }, //6.5错题 getScheduleErr(qid) { let data = { qid } return request.getInstance().url('https://schedule.api.ai160.com/customer/question/getAnalysis').data(data).send(); }, }