sonTopic.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. // pages/sonTopic/sonTopic.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. userSort: [],
  9. sonTitle: "",
  10. imgURL: "",
  11. pTitle: "",
  12. pId: "",
  13. type: "",
  14. tabList: [],
  15. error: "",
  16. headData: {},
  17. contrast: [],
  18. all: [],
  19. douyin: [],
  20. kuaishou: [],
  21. yangshi: [],
  22. wordList: [],
  23. weiboori: [],
  24. weiboread: [],
  25. weibome: [],
  26. selectread: "30d",
  27. selectme: "30d",
  28. selectori: "30d",
  29. weiboBtnListread: [],
  30. weiboBtnListme: [],
  31. weiboBtnListori: [],
  32. height: 0,
  33. isShow: false,
  34. loading: true,
  35. },
  36. /**
  37. * 生命周期函数--监听页面加载
  38. */
  39. onLoad: function (options) {
  40. let sonlist = options.sonList ? JSON.parse(decodeURIComponent(options.sonList)) : [];
  41. let title = options.title ? decodeURIComponent(options.title) : "";
  42. let second_name = sonlist[0] ? sonlist[0].name : "";
  43. let imgURL = sonlist[0] ? sonlist[0].worldImgURL : "";
  44. let type = sonlist[0] ? sonlist[0].type : "";
  45. this.setData({
  46. pTitle: title,
  47. pId: options.type,
  48. tabList: sonlist,
  49. imgURL,
  50. type,
  51. sonTitle: second_name
  52. })
  53. this.getData({ topic_name: second_name || title });
  54. this.getPing({ topic_name: second_name || title });
  55. this.getAccount({ topic_name: second_name || title, platform: "ALL", type: "all" });
  56. this.getAccount({ topic_name: second_name || title, platform: "douyin", type: "douyin" });
  57. this.getAccount({ topic_name: second_name || title, platform: "kuaishou", type: "kuaishou" });
  58. this.getAccount({ topic_name: second_name || title, platform: "yangshi", type: "yangshi" });
  59. // this.getWorld();
  60. this.getWeibo({ topic_name: second_name || title, time: "30d", type: "yangshi" });
  61. },
  62. /**
  63. * 生命周期函数--监听页面初次渲染完成
  64. */
  65. onReady: function () { },
  66. /**
  67. * 生命周期函数--监听页面显示
  68. */
  69. onShow: function () {
  70. this.setData({
  71. isShow: true
  72. })
  73. },
  74. /**
  75. * 生命周期函数--监听页面隐藏
  76. */
  77. onHide: function () {
  78. this.setData({
  79. isShow: false
  80. })
  81. },
  82. /**
  83. * 生命周期函数--监听页面卸载
  84. */
  85. onUnload: function () {
  86. },
  87. /**
  88. * 页面相关事件处理函数--监听用户下拉动作
  89. */
  90. onPullDownRefresh: function () {
  91. },
  92. /**
  93. * 页面上拉触底事件的处理函数
  94. */
  95. onReachBottom: function () {
  96. },
  97. /**
  98. * 用户点击右上角分享
  99. */
  100. onShareAppMessage: function () {
  101. },
  102. lineChengeread: function (val) {
  103. this.setData({
  104. selectread: val.detail
  105. })
  106. this.getWeibo({ topic_name: this.data.sonTitle, time: val.detail, type: "weiboread" }, "read")
  107. },
  108. lineChengeme: function (val) {
  109. this.setData({
  110. selectme: val.detail
  111. })
  112. this.getWeibo({ topic_name: this.data.sonTitle, time: val.detail, type: "weibome" }, "me")
  113. },
  114. lineChengeori: function (val) {
  115. this.setData({
  116. selectori: val.detail
  117. })
  118. this.getWeibo({ topic_name: this.data.sonTitle, time: val.detail, type: "weiboori" }, "ori")
  119. },
  120. getData: function (data) {
  121. const _this = this;
  122. wx.request({
  123. url: app.baseUrl + '/overview',
  124. success: function (res) {
  125. if (res.statusCode === 200) {
  126. _this.setData({
  127. headData: res.data || {}
  128. })
  129. } else _this.setData({
  130. error: '请重启后查看'
  131. })
  132. },
  133. data,
  134. fail: function (err) {
  135. _this.setData({
  136. error: '数据错误'
  137. })
  138. },
  139. complete: function (res) { }
  140. })
  141. },
  142. getPing: function (data) {
  143. const _this = this;
  144. /**
  145. * @description
  146. * data
  147. * topic_name: 聚劲延安
  148. */
  149. wx.request({
  150. url: app.baseUrl + '/platform',
  151. success: function (res) {
  152. if (res.statusCode === 200) {
  153. let contrast = res.data && res.data.length ? [res.data] : [];
  154. _this.setData({
  155. contrast
  156. })
  157. } else _this.setData({
  158. error: '请重启后查看'
  159. })
  160. },
  161. data,
  162. fail: function (err) {
  163. _this.setData({
  164. error: '数据错误'
  165. })
  166. },
  167. complete: function (res) { }
  168. })
  169. },
  170. getAccount: function (data) {
  171. const _this = this;
  172. /**
  173. * @description
  174. * data
  175. * topic_name: 聚劲延安
  176. */
  177. wx.request({
  178. url: app.baseUrl + '/name',
  179. success: function (res) {
  180. if (res.statusCode === 200) {
  181. let list = res.data && res.data.length ? [res.data] : [];
  182. const setD = {};
  183. let isIntUser = {};
  184. let user = {
  185. 'digg_count': { name: '点赞', type: 'digg_count' },
  186. 'pv': { name: '浏览', type: 'pv' },
  187. 'comment_count': { name: '评论', type: 'comment_count' },
  188. 'forward_count': { name: '转发', type: 'forward_count' }
  189. };
  190. let userSort = [];
  191. (res.data || []).map(v => {
  192. !isIntUser.pv && v.pv && userSort.push(user.pv) && (isIntUser.pv = true);
  193. !isIntUser.digg_count && v.digg_count && userSort.push(user.digg_count) && (isIntUser.digg_count = true);
  194. !isIntUser.comment_count && v.comment_count && userSort.push(user.comment_count) && (isIntUser.comment_count = true);
  195. !isIntUser.forward_count && v.forward_count && userSort.push(user.forward_count) && (isIntUser.forward_count = true);
  196. })
  197. if (userSort.length)
  198. setD.userSort = userSort;
  199. setD[data.type] = list;
  200. _this.setData(setD)
  201. } else _this.setData({
  202. error: '请重启后查看'
  203. })
  204. },
  205. data,
  206. fail: function (err) {
  207. _this.setData({
  208. error: '数据错误'
  209. })
  210. },
  211. complete: function (res) { }
  212. })
  213. },
  214. getWorld: function (data) {
  215. const _this = this;
  216. wx.request({
  217. url: this.data.jsonURL,
  218. success: function (res) {
  219. if (res.statusCode === 200) {
  220. _this.setData({
  221. wordList: res.data || []
  222. })
  223. } else _this.setData({
  224. error: '请重启后查看'
  225. })
  226. },
  227. data,
  228. fail: function (err) {
  229. _this.setData({
  230. error: '数据错误'
  231. })
  232. },
  233. complete: function (res) { }
  234. })
  235. },
  236. getWeibo: function (data, type) {
  237. const _this = this;
  238. /**
  239. * @description
  240. * data
  241. * topic_name: 聚劲延安
  242. */
  243. wx.request({
  244. url: app.baseUrl + '/time/v2',
  245. success: function (res) {
  246. if (res.statusCode === 200) {
  247. let server = res ? res.data : {};
  248. let p = {};
  249. let weiboBtn = {
  250. '6m': { name: '1小时', type: '6m' },
  251. '24h': { name: '24小时', type: '24h' },
  252. '7d': { name: '7天', type: '7d' },
  253. '30d': { name: '30天', type: '30d' },
  254. }
  255. if (type) {
  256. console.log(server, _this.data['select' + type], type)
  257. p["weibo" + type] = server[_this.data['select' + type]][type] || [];
  258. p["weiboBtnList" + type] = [];
  259. } else {
  260. p["weiboBtnListread"] = [];
  261. p["weiboBtnListme"] = [];
  262. p["weiboBtnListori"] = [];
  263. p.weiboori = server[_this.data['selectori']].ori || [];
  264. p.weiboread = server[_this.data['selectori']].read || [];
  265. p.weibome = server[_this.data['selectori']].me || [];
  266. }
  267. for (const key in weiboBtn) {
  268. if (weiboBtn.hasOwnProperty(key)) {
  269. const element = weiboBtn[key];
  270. if (type) {
  271. server[key] && server[key][type] && p["weiboBtnList" + type].push(element);
  272. } else {
  273. server[key] && server[key].read && p.weiboBtnListread.push(element);
  274. server[key] && server[key].me && p.weiboBtnListme.push(element);
  275. server[key] && server[key].ori && p.weiboBtnListori.push(element);
  276. }
  277. }
  278. }
  279. _this.setData(p)
  280. } else _this.setData({
  281. error: '请重启后查看'
  282. })
  283. },
  284. data,
  285. fail: function (err) {
  286. _this.setData({
  287. error: '数据错误'
  288. })
  289. },
  290. complete: function (res) { }
  291. })
  292. },
  293. imgLoad: function (e) {
  294. var img_ratio = e.detail.height / e.detail.width;
  295. var rWidth = wx.getSystemInfoSync().windowWidth;
  296. rWidth > 441 && (rWidth = 441)
  297. this.setData({
  298. height: (rWidth * img_ratio).toFixed(0) - 0
  299. })
  300. },
  301. changeBar: function (type) {
  302. let detail = type.detail || {};
  303. let second_name = detail.title || this.data.pTitle;
  304. this.setData({
  305. type: detail.type,
  306. selectread: "30d",
  307. selectme: "30d",
  308. selectori: "30d",
  309. sonTitle: second_name
  310. })
  311. this.getData({ topic_name: second_name });
  312. this.getPing({ topic_name: second_name });
  313. this.getAccount({ topic_name: second_name, platform: "ALL", type: "all" });
  314. this.getAccount({ topic_name: second_name, platform: "douyin", type: "douyin" });
  315. this.getAccount({ topic_name: second_name, platform: "kuaishou", type: "kuaishou" });
  316. this.getAccount({ topic_name: second_name, platform: "yangshi", type: "yangshi" });
  317. // this.getWorld();
  318. this.getWeibo({ topic_name: second_name, time: "30d", type: "yangshi" });
  319. }
  320. })