diff --git a/.gitignore b/.gitignore index e43b0f988953ae3a84b00331d0ccf5f7d51cb3cf..e63f4fb0c5b4cf64ded2f9b6b0dc128f3822bff6 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.DS_Store +.DS_Store +/nbproject/private/ \ No newline at end of file diff --git a/app.js b/app.js index 382ba808fd4b12eeaa51796f3802910f7975d451..b7c75c81280dbdac47fbe9ce299749239eb9b1d2 100644 --- a/app.js +++ b/app.js @@ -2,38 +2,61 @@ App({ onLaunch: function () { //调用API从本地缓存中获取数据 - var user_oauth = wx.getStorageSync('user-oauth') || {} - - //if (!user_oauth) { - wx.redirectTo({ 'url': '/pages/user/login' }); - //} - this.accessToken = user_oauth.access_token; - this.user = wx.getStorageSync('user') || {}; + var logs = wx.getStorageSync('logs') || []; + logs.unshift(Date.now()); + wx.setStorageSync('logs', logs); }, - getUserInfo: function (cb) { - var that = this - if (this.globalData.userInfo) { - typeof cb == "function" && cb(this.globalData.userInfo) + getAccessToken: function (cb) { + var that = this; + if (that.accessToken) { + typeof cb == "function" && cb(this.accessToken); } else { - //调用登录接口 - /*wx.login({ - success: function () { - wx.getUserInfo({ - success: function (res) { - that.globalData.userInfo = res.userInfo - typeof cb == "function" && cb(that.globalData.userInfo) - } - }) - } - })*/ + wx.request({ + url: 'https://api.cnblogs.com/token', //仅为示例,并非真实的接口地址 + method: 'POST', + data: { + username: 'g9dDrMoMV4DzZrOAMcAnCegdisk20T6ddm6ySsUrbpdeID7bL9iV5QcjRISv/2/QfwK5SGClWe7YX8FAghw0jZYTtjUnB1kyPN5H712oKmxiVKMLzm35Yd6kYu5dql/FsCGujeEuzIxN9Mu92g1Xve92jZDz8nLIPe4vhk3nt1I=', + password: 'kTYhPUx6wxSTwWicd+7w5vhIgx6m0QzMYR5LCWmgICSmy+qWJbjpqi4U2/U0i0dSxFVnF9f1iyW9poPbW1xgHcQ46SGwQSRLv2SNnqwMEWph5DzGnMQzE1w7C5hVDMS2YwS8RgAO+U5euG778uCWAu/SejzeCf+37HqJrjN1IzQ=', + grant_type: 'password' + }, + header: { + 'content-type': 'application/x-www-form-urlencoded', + 'Authorization': 'Basic NTMxMmI0ZDMtODk3YS00ZWFjLTlkZmMtZWJiYzNkMTYwYmY1Ok5MdWtlRHRlMDktMkV5ZjBhbnFsZXpOeVZGTTVSb0N0SjF0d3dLTXZRalcwdFNWYmlzR3Y2MXRjblVnbjFfaHMyWTZrcU8yQ0xheDVlOTIw' + }, + success: function (res) { + that.accessToken = res.data.accessToken; + typeof cb == "function" && cb(that.globalData.accessToken); + }, + fail: function () { + console.log('获取token失败!'); + } + }); } }, - cnbConfig: { - apiPrefix: "https://api.cnblogs.com/", - clientId: "5312b4d3-897a-4eac-9dfc-ebbc3d160bf5", - clientSecret: "NLukeDte09-2Eyf0anqlezNyVFM5RoCtJ1twwKMvQjW0tSVbisGv61tcnUgn1_hs2Y6kqO2CLax5e920", - publicKey: "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCp0wHYbg/NOPO3nzMD3dndwS0MccuMeXCHgVlGOoYyFwLdS24Im2e7YyhB0wrUsyYf0/nhzCzBK8ZC9eCWqd0aHbdgOQT6CuFQBMjbyGYvlVYU2ZP7kG9Ft6YV6oc9ambuO7nPZh+bvXH0zDKfi02prknrScAKC0XhadTHT3Al0QIDAQAB" + getUserInfo: function (cb) { + var that = this; + var accessToken = that.accessToken; + if (this.user) { + typeof cb == "function" && cb(this.user); + } else { + wx.request({ + url: 'https://api.cnblogs.com/api/Users', //仅为示例,并非真实的接口地址 + method: 'GET', + data: { + }, + header: { + 'Authorization': 'Bearer ' + accessToken + }, + success: function (res) { + that.user = res.data; + typeof cb == "function" && cb(that.user); + }, + fail: function () { + console.log('获取用户信息失败!'); + } + }); + } }, - accessToken: '', - user: {} -}) \ No newline at end of file + user: null, + accessToken: 'oIyW4j2T6YdaCs6ou-4iosGlp_2E4rs-IV7WRYj8kYJiU1np6jaL_HMZ9daHoVGaTFaF63mWgf80-7VqA3KGHPh7Nkp4gisDz26iTgc3i1IOQeZZMc15W2ytqi1SslFf9qlaIqY3QW7bHUEhY3ViaA052_15JX5yLNhJUuo1TW6TioDrZTp1w4378DBAh9zlyo9RColn6w3e3_3xXaoU3g' +}); diff --git a/app.json b/app.json index 01b66a6659e236a4d16c166296950bc08cd737f7..102a00d304052538d20c70ebf526e8f0665e2e16 100644 --- a/app.json +++ b/app.json @@ -1,7 +1,11 @@ { "pages": [ "pages/index/index", + "pages/status/index", + "pages/status/detail", "pages/question/index", + "pages/question/view", + "pages/question/comments", "pages/user/login", "pages/user/index", "pages/status/index", @@ -38,4 +42,4 @@ } ] } -} \ No newline at end of file +} diff --git a/pages/question/comments.js b/pages/question/comments.js index 363a125f65f1a1d5fab3a3a636dff35be3f7af47..be224950c48a3be0a6a343892f52a7f8891e2839 100644 --- a/pages/question/comments.js +++ b/pages/question/comments.js @@ -2,35 +2,28 @@ var app = getApp(); Page({ data:{ - commonts:{} + commentInput:'', + answer:{}, + commonts:{}, + userInfo: {} }, onLoad:function(options){ // 页面初始化 options为页面跳转所带来的参数 var that = this; - //获取回答详情 - wx.request({ - url: 'https://api.cnblogs.com/api/questions/answers/'+options.id+'/comments', - method: 'GET', - data: { - }, - header: { - 'Authorization': 'Bearer '+ app.accessToken - }, - success: function (res) { - var data = {}; - data.status = true; - data.data = res.data; - if(res.data.length < 1){ - data.status = false; - } - that.setData({ - commonts: data - }); - }, - fail: function () { - console.log('获取用户信息失败!'); - } + app.getUserInfo(function (userInfo) { + //更新数据 + that.setData({ + userInfo: userInfo }); + }); + var data ={}; + data.Id = options.id; + data.Qid = options.qid; + data.Content = options.content; + that.setData({ + answer: data + }); + getComments(that,options.id); }, onReady:function(){ // 页面渲染完成 @@ -43,5 +36,84 @@ Page({ }, onUnload:function(){ // 页面关闭 + }, + comment:function(e){ + var that = this; + var questionId=e.target.dataset.questionId; + var answerId=e.target.dataset.answerId; + if(!answerId){ + + } + console.log(this.data.commentInput) + wx.request({ + url: 'https://api.cnblogs.com/api/questions/'+questionId+'/answers/'+answerId+'/comments', //仅为示例,并非真实的接口地址 + method: 'POST', + data: { + "Content": this.data.commentInput + }, + header: { + 'Authorization': 'Bearer '+ app.accessToken + }, + success: function (res) { + getComments(that,answerId); + }, + fail: function () { + console.log('获取用户信息失败!'); + } + }); + }, + delete:function(e){ + var that = this; + var questionId=e.target.dataset.questionId; + var answerId=e.target.dataset.answerId; + var commentId=e.target.dataset.commentId; + if(!answerId){ + + } + wx.request({ + url: 'https://api.cnblogs.com/api/questions/'+questionId+'/answers/'+answerId+'/comments/'+commentId, //仅为示例,并非真实的接口地址 + method: 'DELETE', + data: { + + }, + header: { + 'Authorization': 'Bearer '+ app.accessToken + }, + success: function (res) { + getComments(that,answerId); + }, + fail: function () { + console.log('获取用户信息失败!'); + } + }); + }, + listenCommentInput:function(event){ + this.data.commentInput = event.detail.value; } -}) \ No newline at end of file +}); +//获取回答相关评论 +function getComments(that, answer_id) { + wx.request({ + url: 'https://api.cnblogs.com/api/questions/answers/' + answer_id + '/comments', + method: 'GET', + data: { + }, + header: { + 'Authorization': 'Bearer ' + app.accessToken + }, + success: function (res) { + var data = {}; + data.status = true; + data.data = res.data; + if (res.data.length < 1) { + data.status = false; + } + that.setData({ + commonts: data + }); + }, + fail: function () { + console.log('获取用户信息失败!'); + } + }); +} \ No newline at end of file diff --git a/pages/question/comments.wxml b/pages/question/comments.wxml index 6e5f5a4af224fa1fabfd3d8a418c31a7b830a502..7b0e5a81bbcb42ab86eb23e94a230666b84db049 100644 --- a/pages/question/comments.wxml +++ b/pages/question/comments.wxml @@ -1,20 +1,21 @@ - {{question.Title}} - {{question.Content}} + {{answer.Content}} 评论 - + - {{commont.Content}} + {{comment.Content}} - {{item.PostUserInfo.UserName}}| - 园豆:{{item.PostUserInfo.QScore}}| - {{item.DateAdded}}| + @{{comment.PostUserInfo.UserName}} + 园豆:{{comment.PostUserInfo.QScore}} + {{comment.DateAdded}} + 修改 + 删除 @@ -27,11 +28,11 @@ -