index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. <template>
  2. <div style="padding-bottom: 1em">
  3. <table class="local_table">
  4. <tr>
  5. <td v-if="baseData.total_pv !== -1">总浏览量</td>
  6. <td v-if="baseData.total_pv !== -1">
  7. {{ baseData.total_pv | formatnum }}
  8. </td>
  9. <td v-if="baseData.total_ori !== -1">原创量</td>
  10. <td v-if="baseData.total_ori !== -1">
  11. {{ baseData.total_ori | formatnum }}
  12. </td>
  13. </tr>
  14. <tr>
  15. <td v-if="baseData.total_digg !== -1">总点赞数</td>
  16. <td v-if="baseData.total_digg !== -1">
  17. {{ baseData.total_digg | formatnum }}
  18. </td>
  19. <td v-if="baseData.total_comment !== -1">总评论数</td>
  20. <td v-if="baseData.total_comment !== -1">
  21. {{ baseData.total_comment | formatnum }}
  22. </td>
  23. </tr>
  24. <tr>
  25. <td v-if="baseData.total_forward !== -1">总转发量</td>
  26. <td v-if="baseData.total_forward !== -1">
  27. {{ baseData.total_forward | formatnum }}
  28. </td>
  29. <td v-if="baseData.live_uv !== -1">直播观看人数</td>
  30. <td v-if="baseData.live_uv !== -1">
  31. {{ baseData.live_uv | formatnum }}
  32. </td>
  33. </tr>
  34. <tr>
  35. <td v-if="baseData.live_add_fans !== -1">新增粉丝数</td>
  36. <td v-if="baseData.live_add_fans !== -1">
  37. {{ baseData.live_add_fans | formatnum }}
  38. </td>
  39. <td v-if="baseData.live_comment !== -1">直播评论数</td>
  40. <td v-if="baseData.live_comment !== -1">
  41. {{ baseData.live_comment | formatnum }}
  42. </td>
  43. </tr>
  44. </table>
  45. <br v-if="baseData.has_live_douyin_data" />
  46. <van-button
  47. v-if="baseData.has_live_douyin_data"
  48. plain
  49. hairline
  50. type="info"
  51. style="margin: 0 5px"
  52. size="normal"
  53. @click="show = true"
  54. round
  55. >直播</van-button
  56. >
  57. <br v-if="baseData.has_live_douyin_data" />
  58. <div v-if="cakeList.length" class="title">平台对比</div>
  59. <canvas
  60. v-if="cakeList.length"
  61. id="cake"
  62. class="canvas"
  63. :width="client.width"
  64. :height="client.height"
  65. ></canvas>
  66. <div v-if="userSort.length" class="title">账号排名</div>
  67. <canvas
  68. v-if="userSort.length"
  69. id="account"
  70. class="canvas"
  71. :width="client.width"
  72. :height="client.height"
  73. ></canvas>
  74. <div v-if="baseData.word_cloud_url" class="title">词云</div>
  75. <van-image v-if="baseData.word_cloud_url" :src="baseData.word_cloud_url">
  76. <template v-slot:loading>
  77. <van-loading type="spinner" size="20" />
  78. </template>
  79. </van-image>
  80. <!-- <canvas
  81. id="keyCloud"
  82. class="canvas"
  83. :width="client.width"
  84. :height="client.height"
  85. ></canvas> -->
  86. <div v-if="douyin.length" class="title">抖音-评论排行</div>
  87. <canvas
  88. v-if="douyin.length"
  89. id="douyinComment"
  90. class="canvas"
  91. :width="client.width"
  92. :height="client.height"
  93. ></canvas>
  94. <div v-if="douyin.length" class="title">抖音-点赞排行</div>
  95. <canvas
  96. v-if="douyin.length"
  97. id="douyinDigg"
  98. class="canvas"
  99. :width="client.width"
  100. :height="client.height"
  101. ></canvas>
  102. <div v-if="douyin.length" class="title">抖音-粉丝量排行</div>
  103. <canvas
  104. v-if="douyin.length"
  105. id="douyinMplatformFollowers"
  106. class="canvas"
  107. :width="client.width"
  108. :height="client.height"
  109. ></canvas>
  110. <div v-if="kuaishou.length" class="title">快手-播放量排行</div>
  111. <canvas
  112. v-if="kuaishou.length"
  113. id="kuaishouPlay"
  114. class="canvas"
  115. :width="client.width"
  116. :height="client.height"
  117. ></canvas>
  118. <div v-if="kuaishou.length" class="title">快手-评论排行</div>
  119. <canvas
  120. v-if="kuaishou.length"
  121. id="kuaishouComment"
  122. class="canvas"
  123. :width="client.width"
  124. :height="client.height"
  125. ></canvas>
  126. <div v-if="read.length" class="title">微博-阅读量趋势</div>
  127. <canvas
  128. v-if="read.length"
  129. id="weiboRead"
  130. class="canvas"
  131. :width="client.width"
  132. :height="client.height"
  133. ></canvas>
  134. <div v-if="me.length" class="title">微博-讨论趋势</div>
  135. <canvas
  136. v-if="me.length"
  137. id="weiboMe"
  138. class="canvas"
  139. :width="client.width"
  140. :height="client.height"
  141. ></canvas>
  142. <div v-if="ori.length" class="title">微博-原创趋势</div>
  143. <canvas
  144. v-if="ori.length"
  145. id="weiboOri"
  146. class="canvas"
  147. :width="client.width"
  148. :height="client.height"
  149. ></canvas>
  150. <div v-if="yangshi.length" class="title">央视-浏览排行</div>
  151. <canvas
  152. v-if="yangshi.length"
  153. id="yangshiPv"
  154. class="canvas"
  155. :width="client.width"
  156. :height="client.height"
  157. ></canvas>
  158. <van-popup safe-area-inset-bottom v-model="show" round position="bottom">
  159. 123
  160. </van-popup>
  161. </div>
  162. </template>
  163. <style scoped></style>
  164. <script>
  165. import {
  166. getAllPlatform,
  167. getPlatform,
  168. getList,
  169. } from "@/api/getList.js";
  170. import filters from "@/utils/filters/index";
  171. import {
  172. Image as vanImage,
  173. Loading as vanLoading,
  174. Popup as vanPopup,
  175. Button as vanButton,
  176. } from "vant";
  177. import "vant/lib/image/style";
  178. import "vant/lib/popup/style";
  179. import "vant/lib/button/style";
  180. import F2 from "@antv/f2";
  181. export default {
  182. components: {
  183. vanImage,
  184. vanLoading,
  185. vanPopup,
  186. vanButton,
  187. },
  188. data() {
  189. return {
  190. initCanvas: {
  191. cake: undefined,
  192. account: undefined,
  193. },
  194. baseData: {},
  195. client: {
  196. width: 0,
  197. height: 0,
  198. },
  199. userSort: [],
  200. douyin: [],
  201. kuaishou: [],
  202. weibo: {},
  203. me: [],
  204. ori: [],
  205. read: [],
  206. yangshi: [],
  207. cakeList: [],
  208. show: false,
  209. };
  210. },
  211. created() {
  212. this.init();
  213. },
  214. methods: {
  215. init() {
  216. let titles = this.$route.query.title.split(" / ");
  217. let title = titles[titles.length - 1];
  218. // let title = encodeURIComponent(titles[titles.length - 1]);
  219. let clientWidth = document.body.clientWidth || 0;
  220. this.client = {
  221. width: clientWidth,
  222. height: (clientWidth / 16) * 9,
  223. };
  224. this.baseData = JSON.parse(this.$route.query.data);
  225. getAllPlatform({
  226. season: this.$route.query.season,
  227. topic_name: title,
  228. }).then(res => {
  229. this.cakeList = res || [];
  230. if (!this.cakeList.length) return;
  231. this.$nextTick(() => {
  232. this.cake(res || []);
  233. });
  234. });
  235. getPlatform({
  236. season: this.$route.query.season,
  237. topic_name: title,
  238. platform: "ALL",
  239. type: "all",
  240. }).then(res => {
  241. this.userSort = (res || []).map(v => {
  242. return {
  243. name: v.nickname,
  244. digg_count: v.digg_count,
  245. comment_count: v.comment_count,
  246. forward_count: v.forward_count,
  247. };
  248. });
  249. if (!this.userSort.length) return;
  250. this.$nextTick(() => {
  251. let list = this.userSort.sort((a, b) => b.digg_count - a.digg_count);
  252. this.account(list, "digg_count", "account");
  253. });
  254. });
  255. getPlatform({
  256. season: this.$route.query.season,
  257. topic_name: title,
  258. platform: "douyin",
  259. type: "douyin",
  260. }).then(res => {
  261. this.douyin = (res || []).map(v => {
  262. return {
  263. name: v.nickname,
  264. digg_count: v.digg_count,
  265. comment_count: v.comment_count,
  266. mplatform_followers_count: v.mplatform_followers_count,
  267. };
  268. });
  269. if (!this.douyin.length) return;
  270. this.$nextTick(() => {
  271. // 点赞
  272. let list = this.douyin.sort((a, b) => b.digg_count - a.digg_count);
  273. this.account(list, "digg_count", "douyinDigg");
  274. // 评论
  275. let listComment = this.douyin.sort(
  276. (a, b) => b.comment_count - a.comment_count
  277. );
  278. this.account(listComment, "comment_count", "douyinComment");
  279. // 粉丝量
  280. let listFollowers = this.douyin.sort(
  281. (a, b) => b.mplatform_followers_count - a.mplatform_followers_count
  282. );
  283. this.account(
  284. listFollowers,
  285. "mplatform_followers_count",
  286. "douyinMplatformFollowers"
  287. );
  288. });
  289. });
  290. getPlatform({
  291. season: this.$route.query.season,
  292. topic_name: title,
  293. platform: "kuaishou",
  294. type: "kuaishou",
  295. }).then(res => {
  296. this.kuaishou = (res || []).map(v => {
  297. return {
  298. name: v.nickname,
  299. pv: v.pv,
  300. comment_count: v.comment_count,
  301. };
  302. });
  303. if (!this.kuaishou.length) return;
  304. this.$nextTick(() => {
  305. // 播放量
  306. let list = this.kuaishou.sort((a, b) => b.pv - a.pv);
  307. this.account(list, "pv", "kuaishouPlay");
  308. // 评论
  309. let listComment = this.kuaishou.sort(
  310. (a, b) => b.comment_count - a.comment_count
  311. );
  312. this.account(listComment, "comment_count", "kuaishouComment");
  313. });
  314. });
  315. getPlatform({
  316. season: this.$route.query.season,
  317. topic_name: title,
  318. platform: "yangshi",
  319. type: "yangshi",
  320. }).then(res => {
  321. this.yangshi = (res || []).map(v => {
  322. return {
  323. name: v.nickname,
  324. pv: v.pv,
  325. };
  326. });
  327. if (!this.yangshi.length) return;
  328. this.$nextTick(() => {
  329. // 播放量
  330. let list = this.yangshi.sort((a, b) => b.pv - a.pv);
  331. this.account(list, "pv", "yangshiPv");
  332. });
  333. });
  334. getList({
  335. topic_name: title,
  336. time: "30d",
  337. season: this.$route.query.season,
  338. }).then(res => {
  339. this.weibo = res || {};
  340. let weiboSelect = this.weibo["30d"] || { me: [], read: [], ori: [] };
  341. this.me = weiboSelect.me || [];
  342. this.read = weiboSelect.read || [];
  343. this.ori = weiboSelect.ori || [];
  344. this.$nextTick(() => {
  345. this.me.length && this.line(this.me, "value", "weiboMe");
  346. this.read.length && this.line(this.read, "value", "weiboRead");
  347. this.ori.length && this.line(this.ori, "value", "weiboOri");
  348. });
  349. });
  350. },
  351. cake(list) {
  352. let data = list.map(v => {
  353. return {
  354. name: v.platform,
  355. percent: v.total_pv,
  356. a: "1",
  357. };
  358. });
  359. const chart = new F2.Chart({
  360. id: "cake",
  361. pixelRatio: window.devicePixelRatio,
  362. });
  363. chart.source(data, {
  364. percent: {
  365. formatter: function formatter(val) {
  366. return val * 100 + "%";
  367. },
  368. },
  369. });
  370. chart.tooltip(false);
  371. chart.coord("polar", {
  372. transposed: true,
  373. radius: 1,
  374. });
  375. chart.axis(false);
  376. chart.legend({
  377. position: "left",
  378. });
  379. chart
  380. .interval()
  381. .position("a*percent")
  382. .color("name", ["#13C2C2", "#2FC25B", "#FACC14", "#F04864", "#8543E0"])
  383. .adjust("stack")
  384. .style({
  385. lineWidth: 1,
  386. stroke: "#fff",
  387. lineJoin: "round",
  388. lineCap: "round",
  389. })
  390. .animate({
  391. appear: {
  392. duration: 1200,
  393. easing: "bounceOut",
  394. },
  395. });
  396. chart.render();
  397. this.initCanvas.cake = chart;
  398. },
  399. account(list, key, id) {
  400. // F2 对数据源格式的要求,仅仅是 JSON 数组,数组的每个元素是一个标准 JSON 对象。
  401. let data = [];
  402. let len = list.length > 10 ? 10 : list.length;
  403. for (let i = 0; i < len; i++) {
  404. const v = list[i];
  405. const li = v.name.split("");
  406. let nickname = li
  407. .map((val, i) => {
  408. i !== 0 && (i + 1) % 2 === 0 && (val = val + "\n");
  409. return val;
  410. })
  411. .join("");
  412. data.push({
  413. name: nickname,
  414. value: v[key],
  415. });
  416. }
  417. // Step 1: 创建 Chart 对象
  418. const chart = new F2.Chart({
  419. id,
  420. pixelRatio: window.devicePixelRatio, // 指定分辨率
  421. });
  422. chart.legend(false);
  423. chart.axis("value", {
  424. label: function label(text) {
  425. return { text: filters.formatNum(text) };
  426. },
  427. });
  428. // Step 2: 载入数据源
  429. chart.source(data);
  430. // Step 3:创建图形语法,绘制柱状图
  431. chart
  432. .interval()
  433. .position("name*value")
  434. .color("name", ["#13C2C2"]);
  435. // Step 4: 渲染图表
  436. chart.render();
  437. // 绘制柱状图文本
  438. const offset = -5;
  439. const canvas = chart.get("canvas");
  440. const group = canvas.addGroup();
  441. data.forEach(function(obj) {
  442. const point = chart.getPosition(obj);
  443. let val = filters.formatNum(obj.value);
  444. group.addShape("text", {
  445. attrs: {
  446. x: point.x,
  447. y: point.y + offset,
  448. text: val,
  449. textAlign: "center",
  450. textBaseline: "bottom",
  451. fill: "#808080",
  452. },
  453. });
  454. });
  455. this.initCanvas[id] = chart;
  456. },
  457. line(list, key, id) {
  458. let data = [];
  459. let len = list.length;
  460. for (let i = 0; i < len; i++) {
  461. const v = list[i];
  462. data.push({
  463. name: v.time,
  464. value: v[key],
  465. });
  466. }
  467. const chart = new F2.Chart({
  468. id,
  469. pixelRatio: window.devicePixelRatio,
  470. });
  471. chart.source(data, {
  472. name: {
  473. tickCount: 3,
  474. range: [0, 1],
  475. },
  476. value: {
  477. tickCount: 5,
  478. min: 0,
  479. },
  480. });
  481. chart.axis("name", {
  482. label: function label(text, index, total) {
  483. const textCfg = {};
  484. if (index === 0) {
  485. textCfg.textAlign = "left";
  486. } else if (index === total - 1) {
  487. textCfg.textAlign = "right";
  488. }
  489. return textCfg;
  490. },
  491. });
  492. chart.axis("value", {
  493. label: function label(text) {
  494. return { text: filters.formatNum(text) };
  495. },
  496. });
  497. chart.tooltip({
  498. showCrosshairs: true,
  499. });
  500. chart
  501. .area()
  502. .position("name*value")
  503. .color("l(90) 0:#1890FF 1:#f7f7f7")
  504. .shape("smooth");
  505. chart
  506. .line()
  507. .position("name*value")
  508. .color("l(90) 0:#1890FF 1:#f7f7f7")
  509. .shape("smooth");
  510. chart.render();
  511. this.initCanvas[id] = chart;
  512. },
  513. },
  514. };
  515. </script>