topic.js 10 KB

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