topic.js 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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 });
  31. this.getPing({ topic_name: n });
  32. this.getAccount({ topic_name: n, platform: "ALL", type: "all" });
  33. }, 3000);
  34. }
  35. },
  36. title: {
  37. type: String,
  38. value: "",
  39. observer: function (newShow) {
  40. !this.data.isUpdata && this.isUp && clearInterval(this.isUp);
  41. let n = newShow;
  42. this.setData({
  43. selectread: "30d",
  44. selectme: "30d",
  45. selectori: "30d",
  46. })
  47. this.getData({ topic_name: n });
  48. this.getPing({ topic_name: n });
  49. this.getAccount({ topic_name: n, platform: "ALL", type: "all" });
  50. this.getAccount({ topic_name: n, platform: "douyin", type: "douyin" });
  51. this.getAccount({ topic_name: n, platform: "kuaishou", type: "kuaishou" });
  52. this.getAccount({ topic_name: n, platform: "yangshi", type: "yangshi" });
  53. // this.getWorld();
  54. this.getWeibo({ topic_name: n, time: "30d" })
  55. }
  56. },
  57. type: {
  58. type: String,
  59. value: ""
  60. },
  61. jsonURL: {
  62. type: String,
  63. value: ""
  64. },
  65. },
  66. // created(){
  67. // console.log("实例刚刚被创建时执行")
  68. // },
  69. // attached(){
  70. // console.log("实例进入页面节点树时执行")
  71. // },
  72. // ready() {
  73. // console.log("组件布局完成后执行", this.data.title)
  74. // },
  75. // moved(){
  76. // console.log("组件实例被移动到节点树另一个位置时执行")
  77. // },
  78. // detached(){
  79. // console.log("组件实例被从页面节点树移除时执行")
  80. // },
  81. /**
  82. * 组件的初始数据
  83. */
  84. data: {
  85. error: "",
  86. headData: {},
  87. contrast: [],
  88. all: [],
  89. douyin: [],
  90. kuaishou: [],
  91. yangshi: [],
  92. wordList: [],
  93. weiboori: [],
  94. weiboread: [],
  95. weibome: [],
  96. selectread: "30d",
  97. selectme: "30d",
  98. selectori: "30d",
  99. weiboBtnListread: [],
  100. weiboBtnListme: [],
  101. weiboBtnListori: [],
  102. height: 0
  103. },
  104. detached: function () {
  105. this.isUp && clearInterval(this.isUp);
  106. },
  107. /**
  108. * 组件的方法列表
  109. */
  110. methods: {
  111. lineChengeread: function (val) {
  112. this.setData({
  113. selectread: val.detail
  114. })
  115. this.getWeibo({ topic_name: this.data.title, time: val.detail }, "read")
  116. },
  117. lineChengeme: function (val) {
  118. this.setData({
  119. selectme: val.detail
  120. })
  121. this.getWeibo({ topic_name: this.data.title, time: val.detail }, "me")
  122. },
  123. lineChengeori: function (val) {
  124. this.setData({
  125. selectori: val.detail
  126. })
  127. this.getWeibo({ topic_name: this.data.title, time: val.detail }, "ori")
  128. },
  129. getData: function (data) {
  130. const _this = this;
  131. /**
  132. * @description
  133. * data
  134. * topic_name: 聚劲延安
  135. */
  136. wx.request({
  137. url: app.baseUrl + '/overview',
  138. success: function (res) {
  139. if (res.statusCode === 200) {
  140. let oldHead = JSON.stringify(_this.data.headData);
  141. let newHead = JSON.stringify(res.data || {});
  142. if (oldHead != newHead)
  143. _this.setData({
  144. headData: res.data || {}
  145. })
  146. } else _this.setData({
  147. error: '请重启后查看'
  148. })
  149. },
  150. data,
  151. fail: function (err) {
  152. _this.setData({
  153. error: '数据错误'
  154. })
  155. },
  156. complete: function (res) { }
  157. })
  158. },
  159. getPing: function (data) {
  160. const _this = this;
  161. /**
  162. * @description
  163. * data
  164. * topic_name: 聚劲延安
  165. */
  166. wx.request({
  167. url: app.baseUrl + '/platform',
  168. success: function (res) {
  169. if (res.statusCode === 200) {
  170. let contrast = res.data && res.data.length ? [res.data] : [];
  171. let oldContrast = JSON.stringify(_this.data.contrast);
  172. let newContrast = JSON.stringify(contrast);
  173. if (oldContrast != newContrast)
  174. _this.setData({
  175. contrast
  176. })
  177. } else _this.setData({
  178. error: '请重启后查看'
  179. })
  180. },
  181. data,
  182. fail: function (err) {
  183. _this.setData({
  184. error: '数据错误'
  185. })
  186. },
  187. complete: function (res) { }
  188. })
  189. },
  190. getAccount: function (data) {
  191. const _this = this;
  192. /**
  193. * @description
  194. * data
  195. * topic_name: 聚劲延安
  196. */
  197. wx.request({
  198. url: app.baseUrl + '/name',
  199. success: function (res) {
  200. if (res.statusCode === 200) {
  201. let list = res.data && res.data.length ? [res.data] : [];
  202. const setD = {};
  203. let isIntUser = {};
  204. let user = {
  205. 'pv': { name: '浏览', type: 'pv' },
  206. 'digg_count': { name: '点赞', type: 'digg_count' },
  207. 'comment_count': { name: '评论', type: 'comment_count' },
  208. 'forward_count': { name: '转发', type: 'forward_count' }
  209. };
  210. let userSort = [];
  211. (res.data || []).map(v => {
  212. !isIntUser.pv && v.pv && userSort.push(user.pv) && (isIntUser.pv = true);
  213. !isIntUser.digg_count && v.digg_count && userSort.push(user.digg_count) && (isIntUser.digg_count = true);
  214. !isIntUser.comment_count && v.comment_count && userSort.push(user.comment_count) && (isIntUser.comment_count = true);
  215. !isIntUser.forward_count && v.forward_count && userSort.push(user.forward_count) && (isIntUser.forward_count = true);
  216. })
  217. if (userSort.length) {
  218. setD[data.type] = list;
  219. setD.userSort = userSort;
  220. } else {
  221. setD[data.type] = [];
  222. setD.userSort = [];
  223. }
  224. let oldType = JSON.stringify(_this.data[data.type]);
  225. let newType = JSON.stringify(list);
  226. if (oldType != newType)
  227. _this.setData(setD)
  228. } else _this.setData({
  229. error: '请重启后查看'
  230. })
  231. },
  232. data,
  233. fail: function (err) {
  234. _this.setData({
  235. error: '数据错误'
  236. })
  237. },
  238. complete: function (res) { }
  239. })
  240. },
  241. getWorld: function (data) {
  242. const _this = this;
  243. /**
  244. * @description
  245. * data
  246. * topic_name: 聚劲延安
  247. */
  248. wx.request({
  249. url: this.data.jsonURL,
  250. success: function (res) {
  251. if (res.statusCode === 200) {
  252. _this.setData({
  253. wordList: res.data || []
  254. })
  255. } else _this.setData({
  256. 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 ? 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. let pOri = server[_this.data['selectori']] || {};
  295. p.weiboori = pOri.ori || [];
  296. p.weiboread = pOri.read || [];
  297. p.weibome = pOri.me || [];
  298. }
  299. for (const key in weiboBtn) {
  300. if (weiboBtn.hasOwnProperty(key)) {
  301. const element = weiboBtn[key];
  302. if (type) {
  303. server[key] && server[key][type] && p["weiboBtnList" + type].push(element);
  304. } else {
  305. server[key] && server[key].read && p.weiboBtnListread.push(element);
  306. server[key] && server[key].me && p.weiboBtnListme.push(element);
  307. server[key] && server[key].ori && p.weiboBtnListori.push(element);
  308. }
  309. }
  310. }
  311. _this.setData(p)
  312. } else _this.setData({
  313. 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. toSecond: function () {
  334. if (!toUrl) return;
  335. toUrl = false;
  336. let asciiList = encodeURIComponent(JSON.stringify(this.data.sonList));
  337. let title = encodeURIComponent(this.data.title);
  338. wx.navigateTo({
  339. url: "/pages/sonTopic/sonTopic?sonList=" + asciiList + "&title=" + title + "&type=" + this.data.type,
  340. complete: function (res) {
  341. toUrl = true;
  342. }
  343. })
  344. }
  345. }
  346. })