sonTopic.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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 list = [];
  159. for (let i = 0; i < (res.data || []).length; i++) {
  160. const v = (res.data || [])[i];
  161. list.push({
  162. value: v.total_pv,
  163. name: v.platform
  164. })
  165. }
  166. let contrast = [
  167. {
  168. type: 'pie',
  169. radius: ['0%', '50%'],
  170. label: {
  171. position: "outside",
  172. formatter: '{b}\n{d}% ',
  173. },
  174. data: list,
  175. emphasis: {
  176. itemStyle: {
  177. shadowBlur: 10,
  178. shadowOffsetX: 0,
  179. shadowColor: 'rgba(0, 0, 0, 0.5)'
  180. }
  181. }
  182. }
  183. ];
  184. _this.setData({
  185. contrast
  186. })
  187. } else wx.showToast({
  188. title: '请重启小程序',
  189. icon: "error"
  190. })
  191. },
  192. data,
  193. fail: function (err) {
  194. _this.setData({
  195. error: '数据错误'
  196. })
  197. },
  198. complete: function (res) { }
  199. })
  200. },
  201. getAccount: function (data) {
  202. const _this = this;
  203. /**
  204. * @description
  205. * data
  206. * topic_name: 聚劲延安
  207. */
  208. wx.request({
  209. url: app.baseUrl + '/name',
  210. success: function (res) {
  211. if (res.statusCode === 200) {
  212. let list = res.data && res.data.length ? [res.data] : [];
  213. const setD = {};
  214. let isIntUser = {};
  215. let user = {
  216. 'digg_count': { name: '点赞', type: 'digg_count' },
  217. 'pv': { name: '浏览', type: 'pv' },
  218. 'comment_count': { name: '评论', type: 'comment_count' },
  219. 'forward_count': { name: '转发', type: 'forward_count' }
  220. };
  221. let userSort = [];
  222. (res.data || []).map(v => {
  223. !isIntUser.pv && v.pv && userSort.push(user.pv) && (isIntUser.pv = true);
  224. !isIntUser.digg_count && v.digg_count && userSort.push(user.digg_count) && (isIntUser.digg_count = true);
  225. !isIntUser.comment_count && v.comment_count && userSort.push(user.comment_count) && (isIntUser.comment_count = true);
  226. !isIntUser.forward_count && v.forward_count && userSort.push(user.forward_count) && (isIntUser.forward_count = true);
  227. })
  228. if (userSort.length)
  229. setD.userSort = userSort;
  230. setD[data.type] = list;
  231. _this.setData(setD)
  232. } else wx.showToast({
  233. title: '请重启小程序',
  234. icon: "error"
  235. })
  236. },
  237. data,
  238. fail: function (err) {
  239. wx.showToast({
  240. title: '请重启小程序',
  241. icon: "error"
  242. })
  243. },
  244. complete: function (res) { }
  245. })
  246. },
  247. getWorld: function (data) {
  248. const _this = this;
  249. wx.request({
  250. url: this.data.jsonURL,
  251. success: function (res) {
  252. if (res.statusCode === 200) {
  253. _this.setData({
  254. wordList: res.data || []
  255. })
  256. } else wx.showToast({
  257. title: '请重启小程序',
  258. icon: "error"
  259. })
  260. },
  261. data,
  262. fail: function (err) {
  263. _this.setData({
  264. error: '数据错误'
  265. })
  266. },
  267. complete: function (res) { }
  268. })
  269. },
  270. getWeibo: function (data, type) {
  271. const _this = this;
  272. /**
  273. * @description
  274. * data
  275. * topic_name: 聚劲延安
  276. */
  277. wx.request({
  278. url: app.baseUrl + '/time/v2',
  279. success: function (res) {
  280. if (res.statusCode === 200) {
  281. let server = res ? res.data : {};
  282. let p = {};
  283. let weiboBtn = {
  284. '6m': { name: '1小时', type: '6m' },
  285. '24h': { name: '24小时', type: '24h' },
  286. '7d': { name: '7天', type: '7d' },
  287. '30d': { name: '30天', type: '30d' },
  288. }
  289. if (type) {
  290. p["weibo" + type] = server[_this.data['select' + type]][type] || [];
  291. p["weiboBtnList" + type] = [];
  292. } else {
  293. p["weiboBtnListread"] = [];
  294. p["weiboBtnListme"] = [];
  295. p["weiboBtnListori"] = [];
  296. p.weiboori = server[_this.data['selectori']].ori || [];
  297. p.weiboread = server[_this.data['selectori']].read || [];
  298. p.weibome = server[_this.data['selectori']].me || [];
  299. }
  300. for (const key in weiboBtn) {
  301. if (weiboBtn.hasOwnProperty(key)) {
  302. const element = weiboBtn[key];
  303. if (type) {
  304. server[key] && server[key][type] && p["weiboBtnList" + type].push(element);
  305. } else {
  306. server[key] && server[key].read && p.weiboBtnListread.push(element);
  307. server[key] && server[key].me && p.weiboBtnListme.push(element);
  308. server[key] && server[key].ori && p.weiboBtnListori.push(element);
  309. }
  310. }
  311. }
  312. _this.setData(p)
  313. } else wx.showToast({
  314. title: '请重启小程序',
  315. icon: "error"
  316. })
  317. },
  318. data,
  319. fail: function (err) {
  320. _this.setData({
  321. error: '数据错误'
  322. })
  323. },
  324. complete: function (res) { }
  325. })
  326. },
  327. imgLoad: function (e) {
  328. var img_ratio = e.detail.height / e.detail.width;
  329. var rWidth = wx.getSystemInfoSync().windowWidth;
  330. rWidth > 441 && (rWidth = 441)
  331. this.setData({
  332. height: (rWidth * img_ratio).toFixed(0) - 0
  333. })
  334. },
  335. changeBar: function (type) {
  336. let detail = type.detail || {};
  337. let second_name = detail.title || this.data.pTitle;
  338. this.setData({
  339. type: detail.type,
  340. selectread: "30d",
  341. selectme: "30d",
  342. selectori: "30d",
  343. sonTitle: second_name
  344. })
  345. this.getData({ topic_name: second_name, season: app.select - 0 + 1 });
  346. this.getPing({ topic_name: second_name, season: app.select - 0 + 1 });
  347. this.getAccount({ topic_name: second_name, platform: "ALL", type: "all", season: app.select - 0 + 1 });
  348. this.getAccount({ topic_name: second_name, platform: "douyin", type: "douyin", season: app.select - 0 + 1 });
  349. this.getAccount({ topic_name: second_name, platform: "kuaishou", type: "kuaishou", season: app.select - 0 + 1 });
  350. this.getAccount({ topic_name: second_name, platform: "yangshi", type: "yangshi", season: app.select - 0 + 1 });
  351. // this.getWorld({ season: app.select - 0 + 1 });
  352. this.getWeibo({ topic_name: second_name, time: "30d", type: "yangshi", season: app.select - 0 + 1 });
  353. },
  354. showDetail: function (e) {
  355. let introduce = e.currentTarget.dataset.introduce || "";
  356. let detail = app.introduce[introduce] || {}
  357. console.log(introduce, detail)
  358. this.setData({
  359. detail: detail.value || "",
  360. diglogTitle: detail.content_desc || ""
  361. })
  362. }
  363. })