topic.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. // pages/home/components/contrast/contrast.js
  2. const app = getApp();
  3. let toUrl = true;
  4. Component({
  5. /**
  6. * 组件的属性列表
  7. */
  8. isUp: undefined,
  9. properties: {
  10. imgURL: {
  11. type: String,
  12. value: ""
  13. },
  14. sonList: {
  15. type: Array,
  16. value: []
  17. },
  18. isShow: {
  19. type: Boolean,
  20. value: false,
  21. },
  22. isUpdata: {
  23. type: Boolean,
  24. value: false,
  25. observer: function (newUp) {
  26. if (!newUp) return;
  27. let n = this.data.title;
  28. this.isUp && clearInterval(this.isUp);
  29. this.isUp = setInterval(() => {
  30. // this.getData({ topic_name: n, season: this.data.select - 0 + 1 });
  31. this.getPing({ topic_name: n, season: this.data.select - 0 + 1 });
  32. this.getAccount({ topic_name: n, platform: "ALL", type: "all", season: this.data.select - 0 + 1 });
  33. }, 3000);
  34. }
  35. },
  36. select: {
  37. type: String,
  38. value: ""
  39. },
  40. title: {
  41. type: String,
  42. value: "",
  43. observer: function (newShow) {
  44. !this.data.isUpdata && this.isUp && clearInterval(this.isUp);
  45. let n = newShow;
  46. this.setData({
  47. selectread: "30d",
  48. selectme: "30d",
  49. selectori: "30d",
  50. })
  51. this.getData({ topic_name: n, season: this.data.select - 0 + 1 });
  52. this.getPing({ topic_name: n, season: this.data.select - 0 + 1 });
  53. this.getAccount({ topic_name: n, platform: "ALL", type: "all", season: this.data.select - 0 + 1 });
  54. this.getAccount({ topic_name: n, platform: "douyin", type: "douyin", season: this.data.select - 0 + 1 });
  55. this.getAccount({ topic_name: n, platform: "kuaishou", type: "kuaishou", season: this.data.select - 0 + 1 });
  56. this.getAccount({ topic_name: n, platform: "yangshi", type: "yangshi", season: this.data.select - 0 + 1 });
  57. // this.getWorld({ season: this.data.select - 0 + 1 });
  58. this.getWeibo({ topic_name: n, time: "30d", season: this.data.select - 0 + 1 })
  59. }
  60. },
  61. type: {
  62. type: String,
  63. value: ""
  64. },
  65. jsonURL: {
  66. type: String,
  67. value: ""
  68. },
  69. },
  70. /**
  71. * 组件的初始数据
  72. */
  73. data: {
  74. error: "",
  75. detail: "",
  76. nameTitle: "",
  77. diglogTitle: "",
  78. headData: {},
  79. contrast: [],
  80. all: [],
  81. douyin: [],
  82. kuaishou: [],
  83. yangshi: [],
  84. wordList: [],
  85. weiboori: [],
  86. weiboread: [],
  87. weibome: [],
  88. selectread: "30d",
  89. selectme: "30d",
  90. selectori: "30d",
  91. weiboBtnListread: [],
  92. weiboBtnListme: [],
  93. weiboBtnListori: [],
  94. height: 0,
  95. pla: [
  96. // {
  97. // name: "抖音",
  98. // type: "douyin"
  99. // },
  100. // {
  101. // name: "快手",
  102. // type: "kuaishou"
  103. // },
  104. ]
  105. },
  106. detached: function () {
  107. this.isUp && clearInterval(this.isUp);
  108. },
  109. /**
  110. * 组件的方法列表
  111. */
  112. methods: {
  113. platform(e){
  114. wx.navigateTo({
  115. url: '/pages/platform/index?type=' + e.currentTarget.dataset.id + "&title=" + this.data.title,
  116. })
  117. },
  118. lineChengeread: function (val) {
  119. this.setData({
  120. selectread: val.detail
  121. })
  122. this.getWeibo({ topic_name: this.data.title, time: val.detail, season: this.data.select - 0 + 1 }, "read")
  123. },
  124. lineChengeme: function (val) {
  125. this.setData({
  126. selectme: val.detail
  127. })
  128. this.getWeibo({ topic_name: this.data.title, time: val.detail, season: this.data.select - 0 + 1 }, "me")
  129. },
  130. lineChengeori: function (val) {
  131. this.setData({
  132. selectori: val.detail
  133. })
  134. this.getWeibo({ topic_name: this.data.title, time: val.detail, season: this.data.select - 0 + 1 }, "ori")
  135. },
  136. getData: function (data) {
  137. const _this = this;
  138. wx.request({
  139. url: app.baseUrl + '/overview',
  140. success: function (res) {
  141. if (res.statusCode === 200) {
  142. _this.setData({
  143. headData: res.data || {}
  144. })
  145. } else wx.showToast({
  146. title: '请重启小程序',
  147. icon: "error"
  148. })
  149. },
  150. data,
  151. fail: function (err) {
  152. wx.showToast({
  153. title: '请重启小程序',
  154. icon: "error"
  155. })
  156. },
  157. complete: function (res) { }
  158. })
  159. },
  160. getPing: function (data) {
  161. const _this = this;
  162. /**
  163. * @description
  164. * data
  165. * topic_name: 聚劲延安
  166. */
  167. wx.request({
  168. url: app.baseUrl + '/platform',
  169. success: function (res) {
  170. if (res.statusCode === 200) {
  171. let list = [];
  172. for (let i = 0; i < (res.data || []).length; i++) {
  173. const v = (res.data || [])[i];
  174. list.push({
  175. value: v.total_pv,
  176. name: v.platform
  177. })
  178. }
  179. let contrast = [
  180. {
  181. type: 'pie',
  182. radius: ['0%', '50%'],
  183. label: {
  184. position: "outside",
  185. formatter: '{b}\n{d}% ',
  186. },
  187. data: list,
  188. emphasis: {
  189. itemStyle: {
  190. shadowBlur: 10,
  191. shadowOffsetX: 0,
  192. shadowColor: 'rgba(0, 0, 0, 0.5)'
  193. }
  194. }
  195. }
  196. ];
  197. _this.setData({
  198. contrast
  199. })
  200. } else wx.showToast({
  201. title: '请重启小程序',
  202. icon: "error"
  203. })
  204. },
  205. data,
  206. fail: function (err) {
  207. _this.setData({
  208. error: '数据错误'
  209. })
  210. },
  211. complete: function (res) { }
  212. })
  213. },
  214. getAccount: function (data) {
  215. const _this = this;
  216. /**
  217. * @description
  218. * data
  219. * topic_name: 聚劲延安
  220. */
  221. wx.request({
  222. url: app.baseUrl + '/name',
  223. success: function (res) {
  224. if (res.statusCode === 200) {
  225. let list = res.data && res.data.length ? [res.data] : [];
  226. const setD = {};
  227. let isIntUser = {};
  228. console.log(list)
  229. let user = {
  230. 'pv': { name: '浏览', type: 'pv' },
  231. 'digg_count': { name: '点赞', type: 'digg_count' },
  232. 'comment_count': { name: '评论', type: 'comment_count' },
  233. 'forward_count': { name: '转发', type: 'forward_count' }
  234. };
  235. let userSort = [];
  236. (res.data || []).map(v => {
  237. !isIntUser.pv && v.pv && userSort.push(user.pv) && (isIntUser.pv = true);
  238. !isIntUser.digg_count && v.digg_count && userSort.push(user.digg_count) && (isIntUser.digg_count = true);
  239. !isIntUser.comment_count && v.comment_count && userSort.push(user.comment_count) && (isIntUser.comment_count = true);
  240. !isIntUser.forward_count && v.forward_count && userSort.push(user.forward_count) && (isIntUser.forward_count = true);
  241. })
  242. if (userSort.length) {
  243. setD[data.type] = list;
  244. setD.userSort = userSort;
  245. } else {
  246. setD[data.type] = [];
  247. setD.userSort = [];
  248. }
  249. let oldType = JSON.stringify(_this.data[data.type]);
  250. let newType = JSON.stringify(list);
  251. if (oldType != newType)
  252. _this.setData(setD)
  253. } else wx.showToast({
  254. title: '请重启小程序',
  255. icon: "error"
  256. })
  257. },
  258. data,
  259. fail: function (err) {
  260. _this.setData({
  261. error: '数据错误'
  262. })
  263. },
  264. complete: function (res) { }
  265. })
  266. },
  267. getWorld: function (data) {
  268. const _this = this;
  269. /**
  270. * @description
  271. * data
  272. * topic_name: 聚劲延安
  273. */
  274. wx.request({
  275. url: this.data.jsonURL,
  276. success: function (res) {
  277. if (res.statusCode === 200) {
  278. _this.setData({
  279. wordList: res.data || []
  280. })
  281. } else wx.showToast({
  282. title: '请重启小程序',
  283. icon: "error"
  284. })
  285. },
  286. data,
  287. fail: function (err) {
  288. _this.setData({
  289. error: '数据错误'
  290. })
  291. },
  292. complete: function (res) { }
  293. })
  294. },
  295. getWeibo: function (data, type) {
  296. const _this = this;
  297. /**
  298. * @description
  299. * data
  300. * topic_name: 聚劲延安
  301. */
  302. wx.request({
  303. url: app.baseUrl + '/time/v2',
  304. success: function (res) {
  305. if (res.statusCode === 200) {
  306. let server = res && res.data ? res.data : {};
  307. let p = {};
  308. let weiboBtn = {
  309. '6m': { name: '1小时', type: '6m' },
  310. '24h': { name: '24小时', type: '24h' },
  311. '7d': { name: '7天', type: '7d' },
  312. '30d': { name: '30天', type: '30d' },
  313. }
  314. if (type) {
  315. p["weibo" + type] = server[_this.data['select' + type]][type] || [];
  316. p["weiboBtnList" + type] = [];
  317. } else {
  318. p["weiboBtnListread"] = [];
  319. p["weiboBtnListme"] = [];
  320. p["weiboBtnListori"] = [];
  321. let pOri = server[_this.data['selectori']] || {};
  322. p.weiboori = pOri.ori || [];
  323. p.weiboread = pOri.read || [];
  324. p.weibome = pOri.me || [];
  325. }
  326. for (const key in weiboBtn) {
  327. if (weiboBtn.hasOwnProperty(key)) {
  328. const element = weiboBtn[key];
  329. if (type) {
  330. server[key] && server[key][type] && p["weiboBtnList" + type].push(element);
  331. } else {
  332. server[key] && server[key].read && p.weiboBtnListread.push(element);
  333. server[key] && server[key].me && p.weiboBtnListme.push(element);
  334. server[key] && server[key].ori && p.weiboBtnListori.push(element);
  335. }
  336. }
  337. }
  338. _this.setData(p)
  339. } else wx.showToast({
  340. title: '请重启小程序',
  341. icon: "error"
  342. })
  343. },
  344. data,
  345. fail: function (err) {
  346. _this.setData({
  347. error: '数据错误'
  348. })
  349. },
  350. complete: function (res) { }
  351. })
  352. },
  353. imgLoad: function (e) {
  354. var img_ratio = e.detail.height / e.detail.width;
  355. var rWidth = wx.getSystemInfoSync().windowWidth;
  356. rWidth > 441 && (rWidth = 441)
  357. this.setData({
  358. height: (rWidth * img_ratio).toFixed(0) - 0
  359. })
  360. },
  361. toSecond: function () {
  362. if (!toUrl) return;
  363. toUrl = false;
  364. let asciiList = encodeURIComponent(JSON.stringify(this.data.sonList));
  365. let title = encodeURIComponent(this.data.title);
  366. wx.navigateTo({
  367. url: "/pages/sonTopic/sonTopic?sonList=" + asciiList + "&title=" + title + "&type=" + this.data.type,
  368. complete: function (res) {
  369. toUrl = true;
  370. }
  371. })
  372. },
  373. toLive: function (e) {
  374. if (!toUrl) return;
  375. toUrl = false;
  376. let title = this.data.title;
  377. let type = this.data.headData.has_live_douyin_data ? "douyin" : this.data.headData.has_live_kuaishou_data ? "kuaishou" : "";
  378. let url = "/pages/live/live?title=" + title + "&season=" + (this.data.select - 0 + 1) + "&isdou=" + this.data.headData.has_live_douyin_data + "&iskuai=" + this.data.headData.has_live_kuaishou_data + "&type=" + type;
  379. // let url = "/pages/live/live?title=" + title + "&season=" + (this.data.select - 0 + 1) + "&isdou=true&iskuai=true&type=douyin";
  380. wx.navigateTo({
  381. url,
  382. complete: function (res) {
  383. toUrl = true;
  384. }
  385. })
  386. },
  387. showDetail: function (e) {
  388. let introduce = e.currentTarget.dataset.introduce || "";
  389. let detail = app.introduce[this.data.title + "_" + introduce] || {}
  390. this.setData({
  391. detail: (detail.value || ""),
  392. diglogTitle: (detail.content_desc || "")
  393. })
  394. }
  395. }
  396. })