123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335 |
- <template>
- <div class="yukang">
- <van-cell-group>
- <van-cell :title="'直播时间:' + base.live_time" />
- </van-cell-group>
- <div class="mainBody" style="padding-bottom: 50px">
- <div>
- <van-row>
- <van-col span="12" class="van-hairline--right">
- <div class="title">
- 性别
- </div>
- <canvas
- ref="chart"
- :width="canvasRegion.width / 2"
- :height="canvasRegion.height"
- ></canvas>
- </van-col>
- <van-col span="12">
- <div class="title">
- 年龄
- </div>
- <canvas
- ref="chartage"
- :width="canvasRegion.width / 2"
- :height="canvasRegion.height"
- ></canvas>
- </van-col>
- </van-row>
- <b-canvas
- keyName="value"
- :transposed="true"
- :height="300"
- :legend="true"
- :list="platformSort"
- ></b-canvas>
- </div>
- <!-- 实时走势 -->
- <c-canvas
- v-if="BulletChat.peopleList.length"
- :showListBtn="true"
- :list="BulletChat.peopleList"
- ></c-canvas>
- <c-canvas
- v-if="ScreenMan.peopleList.length"
- :list="ScreenMan.peopleList"
- :showListBtn="true"
- ></c-canvas>
- <c-canvas
- v-if="flow.peopleList.length"
- :showListBtn="true"
- :list="flow.peopleList"
- ></c-canvas>
- </div>
- </div>
- </template>
- <script>
- import cCanvas from "@/components/chart";
- import bCanvas from "@/components/bChart";
- import { getlive } from "@/api/getList.js";
- import { Col as vanCol, Row as vanRow, Cell as vanCell, CellGroup as vanCellGroup } from "vant";
- import "vant/lib/cell/style";
- import "vant/lib/cell-group/style";
- import "vant/lib/col/style";
- import "vant/lib/row/style";
- import F2 from "@antv/f2";
- export default {
- name: "App",
- components: {
- vanCellGroup,
- vanCell,
- cCanvas,
- bCanvas,
- vanCol,
- vanRow,
- },
- data() {
- return {
- canvasRegion: {
- width: 0,
- height: 0,
- },
- base: {},
- platformSort: [],
- BulletChat: { peopleList: [] },
- flow: { peopleList: [] },
- ScreenMan: { peopleList: [] },
- };
- },
- mounted() {
- let w = document.body.clientWidth || 0;
- let h = document.body.clientHeight / 3;
- this.canvasRegion = {
- width: w > 1200 ? 1200 : w,
- height: h,
- };
- },
- created() {
- let q = this.$route.query;
- getlive({
- topic: q.title,
- platform: q.platform,
- }).then(res => {
- let oriData = res || {};
- let trend = oriData.trend || {};
- this.base = {
- live_time: oriData.detail ? oriData.detail.time || "" : ""
- };
- let gender = [];
- let oriGender = oriData.fans.gender || [];
- for (let i = 0; i < oriGender.length; i++) {
- const v = oriGender[i];
- gender.push({
- name: v.gender,
- percent: v.rate.replace("%", "") * 1,
- a: "1",
- });
- }
- let age = [];
- let oriAge = oriData.fans.age || [];
- for (let i = 0; i < oriAge.length; i++) {
- const v = oriAge[i];
- age.push({
- name: v.item,
- percent: v.percent * 100,
- a: "1",
- });
- }
- this.pie(gender, "chart");
- this.pie(age, "chartage");
- let cityList = [];
- let oriCity = oriData.fans.area["全部"] || [];
- oriCity.map(v => {
- cityList.push({
- nickname: v.Name.replace("市", ""),
- value: v.Ratio.toFixed(2) - 0,
- });
- });
- this.platformSort = cityList;
- let flow = {
- title: "实时流量",
- subTitle: "",
- id: "id" + 10,
- canvasId: "canvasId" + 10,
- type: "line",
- yType: "value",
- xType: "time",
- peopleList: [],
- };
- let BulletChat = {
- title: "累计粉丝量",
- subTitle: "",
- id: "id" + 12,
- canvasId: "canvasId" + 12,
- type: "line",
- yType: "value",
- xType: "time",
- peopleList: [],
- };
- let ScreenMan = {
- title: "点赞走势",
- subTitle: "",
- id: "id" + 13,
- canvasId: "canvasId" + 13,
- type: "line",
- yType: "value",
- xType: "time",
- peopleList: [],
- };
- // 实时流量
- flow.subTitle =
- "在线人数峰值:" +
- ((trend.user || {}).user_count || 0) +
- " 出现时间:" +
- ((trend.user || {}).crawl_date || "") +
- " 平均人数:" +
- ((trend.user || {}).avg_user_count || 0);
- // 累计粉丝量
- BulletChat.subTitle =
- "粉丝峰值:" +
- ((trend.fans || {}).club_info_total_fans_count || 0) +
- " 出现在:" +
- ((trend.fans || {}).crawl_date || "");
- // 点赞走势
- ScreenMan.subTitle =
- "点赞峰值:" +
- ((trend.like || {}).add_like_count || 0) +
- " 出现在:" +
- ((trend.like || {}).crawl_date || "");
- // 趋势图数据
- for (let i = 0; i < (oriData.detail.watch || []).length; i++) {
- const v = (oriData.detail.watch || [])[i];
- let time = this.formatTime(v.x);
- flow.peopleList.push({
- value: v.watch || 0,
- type: "实时流量",
- date: time,
- });
- BulletChat.peopleList.push({
- value: v.bsc || 0,
- type: "弹幕数",
- date: time,
- });
- ScreenMan.peopleList.push({
- value: v.bsuc || 0,
- type: "弹幕人数",
- date: time,
- });
- }
- this.BulletChat = BulletChat;
- this.flow = flow;
- this.ScreenMan = ScreenMan;
- });
- },
- computed: {},
- methods: {
- pie(gender, ele) {
- const chart = new F2.Chart({
- el: this.$refs[ele],
- pixelRatio: window.devicePixelRatio,
- });
- chart.source(gender, {
- percent: {
- formatter: function formatter(val) {
- return val * 100 + "%";
- },
- },
- });
- chart.legend({
- position: "right",
- itemFormatter: function itemFormatter(val) {
- return val;
- },
- });
- chart.tooltip(false);
- chart.coord("polar", {
- transposed: true,
- radius: 0.85,
- });
- chart.axis(false);
- chart
- .interval()
- .position("a*percent")
- .color("name", [
- "#1890FF",
- "#13C2C2",
- "#2FC25B",
- "#FACC14",
- "#F04864",
- "#8543E0",
- ])
- .adjust("stack")
- .style({
- lineWidth: 1,
- stroke: "#fff",
- lineJoin: "round",
- lineCap: "round",
- })
- .animate({
- appear: {
- duration: 1200,
- easing: "bounceOut",
- },
- });
- chart.render();
- },
- formatTime(time) {
- let t = new Date(time);
- let hour = t.getHours();
- let min = t.getMinutes();
- let sec = t.getSeconds();
- hour = hour > 9 ? hour : '0' + hour;
- min = min > 9 ? min : '0' + min;
- sec = sec > 9 ? sec : '0' + sec;
- return hour + ":" + min + ":" + sec;
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- .yukang {
- font-family: "Open Sans", -apple-system, BlinkMacSystemFont, "Helvetica Neue",
- Helvetica, Segoe UI, Arial, Roboto, "PingFang SC", "miui",
- "Hiragino Sans GB", "Microsoft Yahei", sans-serif;
- color: #2c3e50;
- font-weight: 400;
- .title {
- width: 100%;
- padding: 10px 16px;
- box-sizing: border-box;
- overflow: hidden;
- color: #323233;
- font-size: 14px;
- line-height: 24px;
- background-color: #fff;
- }
- .userType {
- position: relative;
- .textGroup {
- z-index: 1;
- position: absolute;
- overflow: hidden;
- top: 15px;
- right: 10px;
- font-size: 0;
- color: #1989fa;
- &::after {
- border-radius: 3px;
- border-color: #1989fa;
- }
- .text {
- padding: 0 3px;
- display: inline-block;
- text-align: center;
- cursor: pointer;
- font-size: 14px;
- }
- .act {
- background-color: #1989fa;
- color: #fff;
- }
- }
- }
- .title{
- color: #323233;
- font-size: 14px;
- }
- }
- </style>
|