| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- <template>
- <div class="app-container">
- <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
- <el-form-item label="日期">
- <el-date-picker
- v-model="timeRange"
- type="daterange"
- placeholder="选择日期"
- :value-format="'yyyy-MM-dd'"
- :picker-options="pickerOptions"
- @change="handleDateData"
- ></el-date-picker>
- </el-form-item>
- <el-form-item>
- <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
- <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
- <el-button
- type="warning"
- plain
- icon="el-icon-download"
- size="mini"
- :loading="exportLoading"
- @click="handleExport"
- v-hasPermi="['course:miniappTraffic:export']"
- >导出</el-button>
- </el-form-item>
- </el-form>
- <el-table border v-loading="loading" :data="trafficList" show-summary :summary-method="getSummaries">
- <el-table-column label="日期" align="center" prop="statDate" />
- <el-table-column label="使用流量" align="center">
- <template slot-scope="scope">
- <span>{{ formatTrafficData(scope.row.totalInternetTraffic) }}</span>
- </template>
- </el-table-column>
- </el-table>
- <pagination
- v-show="total > 0"
- :total="total"
- :page.sync="queryParams.pageNum"
- :limit.sync="queryParams.pageSize"
- @pagination="getList"
- />
- </div>
- </template>
- <script>
- import { listMiniappTraffic, exportMiniappTraffic } from "@/api/course/miniappTraffic";
- export default {
- name: "MiniappTraffic",
- data() {
- return {
- timeRange: null,
- pickerOptions: {
- shortcuts: [
- {
- text: '今日',
- onClick(picker) {
- const start = new Date();
- const end = new Date();
- picker.$emit('pick', [start, end]);
- }
- },
- {
- text: '昨日',
- onClick(picker) {
- const start = new Date();
- start.setDate(start.getDate() - 1);
- const end = new Date(start);
- picker.$emit('pick', [start, end]);
- }
- },
- {
- text: '本周',
- onClick(picker) {
- const now = new Date();
- const day = now.getDay() || 7;
- const start = new Date(now);
- start.setDate(now.getDate() - day + 1);
- const end = new Date();
- picker.$emit('pick', [start, end]);
- }
- },
- {
- text: '本月',
- onClick(picker) {
- const start = new Date(new Date().setDate(1));
- const end = new Date();
- picker.$emit('pick', [start, end]);
- }
- }
- ]
- },
- loading: false,
- exportLoading: false,
- showSearch: true,
- total: 0,
- trafficList: [],
- queryParams: {
- startDate: null,
- endDate: null,
- pageNum: 1,
- pageSize: 31
- }
- };
- },
- created() {
- this.initCurrentMonth();
- this.getList();
- },
- methods: {
- formatDate(date) {
- const year = date.getFullYear();
- const month = String(date.getMonth() + 1).padStart(2, '0');
- const day = String(date.getDate()).padStart(2, '0');
- return `${year}-${month}-${day}`;
- },
- initCurrentMonth() {
- const today = new Date();
- const start = new Date(today.getFullYear(), today.getMonth(), 1);
- const startStr = this.formatDate(start);
- const endStr = this.formatDate(today);
- this.timeRange = [startStr, endStr];
- this.queryParams.startDate = startStr;
- this.queryParams.endDate = endStr;
- },
- getSummaries(param) {
- const { columns, data } = param;
- const sums = [];
- columns.forEach((column, index) => {
- if (index === 0) {
- sums[index] = '合计';
- return;
- }
- if (index === columns.length - 1) {
- if (data && data.length > 0) {
- const total = data.reduce((prev, item) => prev + (Number(item.totalInternetTraffic) || 0), 0);
- sums[index] = this.formatTrafficData(total);
- } else {
- sums[index] = '0.0000 GB';
- }
- } else {
- sums[index] = '';
- }
- });
- return sums;
- },
- handleDateData() {
- if (this.timeRange) {
- this.queryParams.startDate = this.timeRange[0];
- this.queryParams.endDate = this.timeRange[1];
- } else {
- this.queryParams.startDate = null;
- this.queryParams.endDate = null;
- }
- },
- getList() {
- this.loading = true;
- listMiniappTraffic(this.queryParams).then(res => {
- this.trafficList = res.rows || [];
- this.total = res.total || 0;
- }).finally(() => {
- this.loading = false;
- });
- },
- handleQuery() {
- this.queryParams.pageNum = 1;
- this.getList();
- },
- resetQuery() {
- this.initCurrentMonth();
- this.queryParams.pageNum = 1;
- this.getList();
- },
- formatTrafficData(traffic) {
- return `${((Number(traffic) || 0) / (1024 ** 3)).toFixed(4)} GB`;
- },
- handleExport() {
- this.$confirm("确认导出数据?", "提示").then(() => {
- this.exportLoading = true;
- return exportMiniappTraffic(this.queryParams);
- }).then(res => {
- this.download(res.msg);
- }).finally(() => {
- this.exportLoading = false;
- });
- }
- }
- };
- </script>
|