123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456 |
- <template>
- <div class="program">
- <el-card class="box-card">
- <el-form
- :model="form"
- size="small"
- :inline="true"
- label-width="120px"
- class="demo-form-inline"
- >
- <el-form-item>
- <template v-for="item in pListData" :key="item.platform">
- <el-button
- :class="
- 'colorBtn ' +
- btnGroup[item.platform].class +
- (form.platform == item.platform
- ? ' ' + btnGroup[item.platform].class + 'act'
- : '')
- "
- @click="() => tabChange(item)"
- >
- <span v-if="item.platform === '微信'" class="icon iconfont"
- ></span
- >
- <span
- v-if="item.platform === '微博'"
- class="icon iconfont weiboIcon1"
- ></span
- >
- <span v-if="item.platform === '快手'" class="icon iconfont"
- ></span
- >
- <span v-if="item.platform === '抖音'" class="icon iconfont"
- ></span
- >
- <span v-if="item.platform === 'B站'" class="icon iconfont"
- ></span
- >
- <span v-if="item.platform === '头条'" class="icon iconfont"
- ></span
- >
- {{ item.platform }}
- </el-button>
- </template>
- </el-form-item>
- <el-form-item label="日期">
- <el-date-picker
- v-model="form.dt"
- type="daterange"
- start-placeholder="开始时间"
- end-placeholder="结束时间"
- :disabled-date="time => disabledDate(time)"
- placeholder="日期"
- >
- </el-date-picker>
- </el-form-item>
- <el-form-item label="关键词">
- <el-input v-model="form.match" placeholder="检索关键词" clearable />
- </el-form-item>
- <el-form-item style="float: right">
- <el-button type="primary" @click="onSubmit" :loading="load">
- 查询
- </el-button>
- <el-button type="primary" @click="onExport">导出</el-button>
- </el-form-item>
- </el-form>
- </el-card>
- <br />
- <el-card class="box-card">
- <el-tabs v-model="activeTab" class="demo-tabs">
- <el-tab-pane label="传播数据" name="agg">
- <el-table
- :header-cell-style="{
- backgroundColor: '#f4f5f7',
- color: '#606266',
- }"
- ref="table1"
- align="center"
- :data="tableData"
- empty-text="暂无数据"
- style="width: 100%"
- @sort-change="sort_change"
- >
- <template v-for="(item, i) in agg" :key="i">
- <el-table-column
- align="center"
- :width="item.width"
- show-overflow-tooltip
- :prop="item.key"
- :label="item.label"
- :sortable="item.sortable"
- :sort-orders="
- item.sortable ? ['ascending', 'descending', null] : []
- "
- >
- <template #default="scope">
- {{
- item.type == 'number'
- ? formatter(scope.row[item.key])
- : scope.row[item.key]
- }}
- </template>
- </el-table-column>
- </template>
- </el-table>
- </el-tab-pane>
- <el-tab-pane label="稿件数据" name="list">
- <el-table
- :header-cell-style="{
- backgroundColor: '#f4f5f7',
- color: '#606266',
- }"
- ref="table2"
- align="center"
- empty-text="暂无数据"
- :data="tableList"
- style="width: 100%"
- @sort-change="sort_change"
- >
- <template v-for="(item, i) in list" :key="i">
- <el-table-column
- align="center"
- :width="item.width"
- show-overflow-tooltip
- :prop="item.key"
- :label="item.label"
- :sortable="item.sortable"
- :sort-orders="
- item.sortable ? ['ascending', 'descending', null] : []
- "
- >
- <template #default="scope">
- {{
- item.type == 'number'
- ? formatter(scope.row[item.key])
- : scope.row[item.key]
- }}
- </template>
- </el-table-column>
- </template>
- </el-table>
- <br />
- <el-pagination
- @current-change="cChange"
- background
- :page-size="pagesize || 10"
- layout="prev, pager, next"
- :total="total"
- />
- <br />
- </el-tab-pane>
- </el-tabs>
- </el-card>
- </div>
- </template>
- <script>
- // @ is an alias to /src
- const ElLoading = require('element-plus/lib/el-loading/index');
- import 'element-plus/lib/theme-chalk/el-loading.css';
- import { platformList, platformlistData, platform } from '@/api/index';
- import { formatter } from '@/utils/tool';
- import config from '@/config/index';
- let tableDataListOri = [];
- let sort = null;
- let sortLib = null;
- export default {
- name: 'RealData',
- data() {
- return {
- btnGroup: {
- 微信: {
- color: '#1cc393',
- class: 'weixin',
- },
- 微博: {
- color: '#ffb712',
- class: 'weibo',
- },
- 快手: {
- color: '#ffb712',
- class: 'kuaishou',
- },
- 抖音: {
- color: '#170b1a',
- class: 'douyin',
- },
- 头条: {
- color: '#de0517',
- class: 'toutiao',
- },
- B站: {
- color: '#ffb712',
- class: 'bzhan',
- },
- },
- page: 0,
- pagesize: 20,
- total: 0,
- load: false,
- activeTab: 'agg',
- form: {
- platform: '',
- dt: [],
- match: '',
- },
- formRael: { platform: '', dt: [] },
- tableData: [],
- pListData: [],
- };
- },
- mounted() {
- platformList().then(res => {
- const first = res[0] || { platform: '', dt: '' };
- this.form = {
- dt: [first.dt, first.dt],
- platform: first.platform,
- };
- this.formRael = {
- dt: [first.dt, first.dt],
- platform: first.platform || '',
- };
- this.pListData = res || [];
- this.onSubmit();
- });
- },
- computed: {
- agg() {
- if (!this.formRael.platform) return [];
- return config.tableCol.agg[this.formRael.platform];
- },
- list() {
- if (!this.formRael.platform) return [];
- return config.tableCol.list[this.formRael.platform];
- },
- tableList() {
- const out = [];
- for (
- let i = (this.page - 1) * this.pagesize;
- i < this.page * this.pagesize;
- i++
- ) {
- const v = tableDataListOri[i];
- v && out.push(v);
- }
- return out;
- },
- },
- methods: {
- formatter,
- tabChange(item) {
- let p = {
- platform: item.platform,
- dt: this.form.dt,
- match: this.form.match,
- };
- if (new Date(item.dt) - new Date(p.dt) < 0) p.dt = item.dt;
- this.form = p;
- this.$refs.table1.clearSort();
- this.$refs.table2.clearSort();
- sortLib = null;
- sort = null;
- this.onSubmit();
- },
- cChange(num) {
- this.page = num;
- },
- onExport() {
- if (!this.formRael.dt || this.formRael.dt.length != 2) return;
- const startd = this.dateFormat(this.formRael.dt[0] || 0);
- const starte = this.dateFormat(this.formRael.dt[1] || 0);
- let url =
- config.base.url2 +
- '/new-media/export?start=' +
- [startd.year, startd.month, startd.day].join('-') +
- '&end=' +
- [starte.year, starte.month, starte.day].join('-');
- if (this.formRael.sort) url += '&sort=' + this.formRael.sort;
- window.open(url);
- },
- disabledDate(time) {
- return time.getTime() > Date.now() - 86400000;
- },
- sort_change(type) {
- sort = type.prop;
- sortLib = type.order;
- this.onSubmit();
- },
- onSubmit() {
- const data = this.formatListData();
- this.page = 0;
- this.tableData = [];
- this.total = 0;
- this.load = true;
- const l = ElLoading.default.service();
- Promise.all([platform(data), platformlistData(data)])
- .then(list => {
- this.formRael = data;
- this.formRael.dt = [this.formRael.start, this.formRael.end];
- this.tableData = (list[0] || []).map((v, i) => {
- v.index = i + 1;
- return v;
- });
- tableDataListOri = (list[1] || []).map((v, i) => {
- v.index = i + 1;
- return v;
- });
- this.total = tableDataListOri.length;
- this.page = this.page + 1;
- this.load = false;
- l.close();
- })
- .catch(() => {
- this.load = false;
- l.close();
- });
- },
- dateFormat(date) {
- let D = new Date(date);
- let m = D.getMonth() + 1;
- let d = D.getDate();
- let h = D.getHours();
- let M = D.getMinutes();
- let s = D.getSeconds();
- m > 9 ? m : (m = '0' + m);
- d > 9 ? d : (d = '0' + d);
- h > 9 ? h : (h = '0' + h);
- M > 9 ? M : (M = '0' + M);
- s > 9 ? s : (s = '0' + s);
- return {
- year: D.getFullYear(),
- month: m,
- day: d,
- hour: h,
- minutes: M,
- seconds: s,
- };
- },
- formatListData() {
- const startd = this.form.dt[0] ? this.dateFormat(this.form.dt[0]) : false;
- const starte = this.form.dt[1] ? this.dateFormat(this.form.dt[1]) : false;
- const loginname = JSON.parse(
- window.parent.localStorage.userinfo || '{}'
- ).loginname;
- const p = {
- platform: this.form.platform || this.pListData[0],
- start: startd
- ? [startd.year, startd.month, startd.day].join('-')
- : undefined,
- end: starte
- ? [starte.year, starte.month, starte.day].join('-')
- : undefined,
- match: this.form.match,
- userId: loginname,
- };
- sort && (p.sort = sort);
- const sortLibType = {
- descending: 1,
- ascending: 0,
- };
- sortLib && (p.order = sortLibType[sortLib]);
- return p;
- },
- },
- components: {},
- };
- </script>
- <style>
- .colorBtn {
- background-color: #fff;
- color: #000;
- padding: 0 18px;
- width: 8em;
- height: 38px;
- line-height: 38px;
- font-size: 14px;
- }
- .weibo .icon {
- color: #ffb712;
- }
- .weiboact,
- .weibo:hover,
- .weibo:focus,
- .weiboact .icon,
- .weibo:hover .icon {
- background-color: #ffb712;
- border-color: #ffb712;
- color: #fff;
- }
- .toutiao .icon {
- color: #f04142;
- }
- .toutiaoact,
- .toutiao:hover,
- .toutiao:focus,
- .toutiaoact .icon,
- .toutiao:hover .icon {
- background-color: #f04142;
- border-color: #f04142;
- color: #fff;
- }
- .weixin .icon {
- color: #1cc393;
- }
- .weixinact,
- .weixin:hover,
- .weixin:focus,
- .weixinact .icon,
- .weixin:hover .icon {
- background-color: #1cc393;
- border-color: #1cc393;
- color: #fff;
- }
- .kuaishou .icon {
- color: #eb3661;
- }
- .kuaishouact,
- .kuaishou:hover,
- .kuaishou:focus,
- .kuaishou:focus,
- .kuaishouact .icon,
- .kuaishou:hover .icon {
- background-color: #eb3661;
- border-color: #eb3661;
- color: #fff;
- }
- .douyin .icon {
- color: #170b1a;
- }
- .douyinact,
- .douyin:hover,
- .douyin:focus,
- .douyinact .icon,
- .douyin:hover .icon {
- background-color: #170b1a;
- border-color: #170b1a;
- color: #fff;
- }
- .bzhan .icon {
- color: #fb7299;
- }
- .bzhanact,
- .bzhan:hover,
- .bzhan:focus,
- .bzhanact .icon,
- .bzhan:hover .icon {
- background-color: #fb7299;
- border-color: #fb7299;
- color: #fff;
- }
- </style>
|