sonTopic.js 10 KB

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