sonTopic.js 11 KB

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