topic.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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. },
  96. detached: function () {
  97. this.isUp && clearInterval(this.isUp);
  98. },
  99. /**
  100. * 组件的方法列表
  101. */
  102. methods: {
  103. lineChengeread: function (val) {
  104. this.setData({
  105. selectread: val.detail
  106. })
  107. this.getWeibo({ topic_name: this.data.title, time: val.detail, season: this.data.select - 0 + 1 }, "read")
  108. },
  109. lineChengeme: function (val) {
  110. this.setData({
  111. selectme: val.detail
  112. })
  113. this.getWeibo({ topic_name: this.data.title, time: val.detail, season: this.data.select - 0 + 1 }, "me")
  114. },
  115. lineChengeori: function (val) {
  116. this.setData({
  117. selectori: val.detail
  118. })
  119. this.getWeibo({ topic_name: this.data.title, time: val.detail, season: this.data.select - 0 + 1 }, "ori")
  120. },
  121. getData: function (data) {
  122. const _this = this;
  123. wx.request({
  124. url: app.baseUrl + '/overview',
  125. success: function (res) {
  126. if (res.statusCode === 200) {
  127. console.log(res.data )
  128. _this.setData({
  129. headData: res.data || {}
  130. })
  131. } else wx.showToast({
  132. title: '请重启小程序',
  133. icon: "error"
  134. })
  135. },
  136. data,
  137. fail: function (err) {
  138. wx.showToast({
  139. title: '请重启小程序',
  140. icon: "error"
  141. })
  142. },
  143. complete: function (res) { }
  144. })
  145. },
  146. getPing: function (data) {
  147. const _this = this;
  148. /**
  149. * @description
  150. * data
  151. * topic_name: 聚劲延安
  152. */
  153. wx.request({
  154. url: app.baseUrl + '/platform',
  155. success: function (res) {
  156. if (res.statusCode === 200) {
  157. let contrast = res.data && res.data.length ? [res.data] : [];
  158. let oldContrast = JSON.stringify(_this.data.contrast);
  159. let newContrast = JSON.stringify(contrast);
  160. if (oldContrast != newContrast)
  161. _this.setData({
  162. contrast
  163. })
  164. } else wx.showToast({
  165. title: '请重启小程序',
  166. icon: "error"
  167. })
  168. },
  169. data,
  170. fail: function (err) {
  171. _this.setData({
  172. error: '数据错误'
  173. })
  174. },
  175. complete: function (res) { }
  176. })
  177. },
  178. getAccount: function (data) {
  179. const _this = this;
  180. /**
  181. * @description
  182. * data
  183. * topic_name: 聚劲延安
  184. */
  185. wx.request({
  186. url: app.baseUrl + '/name',
  187. success: function (res) {
  188. if (res.statusCode === 200) {
  189. let list = res.data && res.data.length ? [res.data] : [];
  190. const setD = {};
  191. let isIntUser = {};
  192. let user = {
  193. 'pv': { name: '浏览', type: 'pv' },
  194. 'digg_count': { name: '点赞', type: 'digg_count' },
  195. 'comment_count': { name: '评论', type: 'comment_count' },
  196. 'forward_count': { name: '转发', type: 'forward_count' }
  197. };
  198. let userSort = [];
  199. (res.data || []).map(v => {
  200. !isIntUser.pv && v.pv && userSort.push(user.pv) && (isIntUser.pv = true);
  201. !isIntUser.digg_count && v.digg_count && userSort.push(user.digg_count) && (isIntUser.digg_count = true);
  202. !isIntUser.comment_count && v.comment_count && userSort.push(user.comment_count) && (isIntUser.comment_count = true);
  203. !isIntUser.forward_count && v.forward_count && userSort.push(user.forward_count) && (isIntUser.forward_count = true);
  204. })
  205. if (userSort.length) {
  206. setD[data.type] = list;
  207. setD.userSort = userSort;
  208. } else {
  209. setD[data.type] = [];
  210. setD.userSort = [];
  211. }
  212. let oldType = JSON.stringify(_this.data[data.type]);
  213. let newType = JSON.stringify(list);
  214. if (oldType != newType)
  215. _this.setData(setD)
  216. } else wx.showToast({
  217. title: '请重启小程序',
  218. icon: "error"
  219. })
  220. },
  221. data,
  222. fail: function (err) {
  223. _this.setData({
  224. error: '数据错误'
  225. })
  226. },
  227. complete: function (res) { }
  228. })
  229. },
  230. getWorld: function (data) {
  231. const _this = this;
  232. /**
  233. * @description
  234. * data
  235. * topic_name: 聚劲延安
  236. */
  237. wx.request({
  238. url: this.data.jsonURL,
  239. success: function (res) {
  240. if (res.statusCode === 200) {
  241. _this.setData({
  242. wordList: res.data || []
  243. })
  244. } else wx.showToast({
  245. title: '请重启小程序',
  246. icon: "error"
  247. })
  248. },
  249. data,
  250. fail: function (err) {
  251. _this.setData({
  252. error: '数据错误'
  253. })
  254. },
  255. complete: function (res) { }
  256. })
  257. },
  258. getWeibo: function (data, type) {
  259. const _this = this;
  260. /**
  261. * @description
  262. * data
  263. * topic_name: 聚劲延安
  264. */
  265. wx.request({
  266. url: app.baseUrl + '/time/v2',
  267. success: function (res) {
  268. if (res.statusCode === 200) {
  269. let server = res && res.data ? res.data : {};
  270. let p = {};
  271. let weiboBtn = {
  272. '6m': { name: '1小时', type: '6m' },
  273. '24h': { name: '24小时', type: '24h' },
  274. '7d': { name: '7天', type: '7d' },
  275. '30d': { name: '30天', type: '30d' },
  276. }
  277. if (type) {
  278. p["weibo" + type] = server[_this.data['select' + type]][type] || [];
  279. p["weiboBtnList" + type] = [];
  280. } else {
  281. p["weiboBtnListread"] = [];
  282. p["weiboBtnListme"] = [];
  283. p["weiboBtnListori"] = [];
  284. let pOri = server[_this.data['selectori']] || {};
  285. p.weiboori = pOri.ori || [];
  286. p.weiboread = pOri.read || [];
  287. p.weibome = pOri.me || [];
  288. }
  289. for (const key in weiboBtn) {
  290. if (weiboBtn.hasOwnProperty(key)) {
  291. const element = weiboBtn[key];
  292. if (type) {
  293. server[key] && server[key][type] && p["weiboBtnList" + type].push(element);
  294. } else {
  295. server[key] && server[key].read && p.weiboBtnListread.push(element);
  296. server[key] && server[key].me && p.weiboBtnListme.push(element);
  297. server[key] && server[key].ori && p.weiboBtnListori.push(element);
  298. }
  299. }
  300. }
  301. _this.setData(p)
  302. } else wx.showToast({
  303. title: '请重启小程序',
  304. icon: "error"
  305. })
  306. },
  307. data,
  308. fail: function (err) {
  309. _this.setData({
  310. error: '数据错误'
  311. })
  312. },
  313. complete: function (res) { }
  314. })
  315. },
  316. imgLoad: function (e) {
  317. var img_ratio = e.detail.height / e.detail.width;
  318. var rWidth = wx.getSystemInfoSync().windowWidth;
  319. rWidth > 441 && (rWidth = 441)
  320. this.setData({
  321. height: (rWidth * img_ratio).toFixed(0) - 0
  322. })
  323. },
  324. toSecond: function () {
  325. if (!toUrl) return;
  326. toUrl = false;
  327. let asciiList = encodeURIComponent(JSON.stringify(this.data.sonList));
  328. let title = encodeURIComponent(this.data.title);
  329. wx.navigateTo({
  330. url: "/pages/sonTopic/sonTopic?sonList=" + asciiList + "&title=" + title + "&type=" + this.data.type,
  331. complete: function (res) {
  332. toUrl = true;
  333. }
  334. })
  335. },
  336. toLive: function () {
  337. if (!toUrl) return;
  338. toUrl = false;
  339. let title = encodeURIComponent(this.data.title);
  340. wx.navigateTo({
  341. url: "/pages/liveData/liveData?title=" +title,
  342. complete: function (res) {
  343. toUrl = true;
  344. }
  345. })
  346. },
  347. showDetail: function (e) {
  348. let introduce = e.currentTarget.dataset.introduce || "";
  349. let detail = app.introduce[this.data.title + "_" + introduce] || {}
  350. console.log(introduce,this)
  351. this.setData({
  352. detail: (detail.value || ""),
  353. diglogTitle: (detail.content_desc || "")
  354. })
  355. }
  356. }
  357. })