1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
| <template> <page-layout :filter-model="listQuery" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @search="handleFilter" @reset="resetQuery" @pagination="getList" > <!-- 筛选区域 --> <template #filter> <el-form-item label="应用:"> <el-select v-model="listQuery.appId" placeholder="请选择应用" clearable style="width: 200px" @change="handleFilter" > <el-option v-for="item in appOptions" :key="item.value" :label="item.label" :value="item.value" /> </el-select> </el-form-item> <el-form-item label="广告位类型:"> <el-select v-model="listQuery.adType" placeholder="请选择广告位类型" clearable style="width: 200px" @change="handleFilter" > <el-option v-for="item in adTypeOptions" :key="item.value" :label="item.label" :value="item.value" /> </el-select> </el-form-item> <el-form-item label="日期:"> <el-date-picker v-model="listQuery.dateRange" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" :picker-options="pickerOptions" style="width: 350px" @change="handleFilter" /> </el-form-item> </template>
<!-- 表格区域(默认插槽) --> <el-table v-loading="listLoading" :data="list" element-loading-text="加载中..." border fit stripe highlight-current-row style="width: 100%" > <el-table-column label="日期" align="center" width="180"> <template slot-scope="scope"> <span>{{ scope.row.date }}</span> </template> </el-table-column> <el-table-column label="应用" align="center" width="180"> <template slot-scope="scope"> <span>{{ scope.row.appName }}</span> </template> </el-table-column> <el-table-column label="广告位类型" align="center" width="180"> <template slot-scope="scope"> <span>{{ scope.row.adTypeName }}</span> </template> </el-table-column> <el-table-column label="展示量" align="center"> <template slot-scope="scope"> <span>{{ scope.row.showCount }}</span> </template> </el-table-column> <el-table-column label="点击量" align="center"> <template slot-scope="scope"> <span>{{ scope.row.clickCount }}</span> </template> </el-table-column> <el-table-column label="点击率" align="center"> <template slot-scope="scope"> <span>{{ (scope.row.ctr * 100).toFixed(2) }}%</span> </template> </el-table-column> <el-table-column label="收入(元)" align="center"> <template slot-scope="scope"> <span>{{ scope.row.revenue.toFixed(2) }}</span> </template> </el-table-column> </el-table> </page-layout> </template>
<script> import { getCodeReportData } from '@/api/report' import PageLayout from '@/components/PageLayout' import dayjs from 'dayjs'
/** * 代码数据报表组件 * @component */ export default { name: 'ReportCodeData', components: { PageLayout }, data() { return { list: [], total: 0, listLoading: true, // 搜索条件 listQuery: { page: 1, limit: 20, appId: undefined, adType: undefined, dateRange: [dayjs().format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')] // 默认今天 }, // 日期选择器配置 pickerOptions: { shortcuts: [ { text: '今天', onClick(picker) { const today = new Date() picker.$emit('pick', [today, today]) } }, { text: '昨天', onClick(picker) { const yesterday = new Date() yesterday.setDate(yesterday.getDate() - 1) picker.$emit('pick', [yesterday, yesterday]) } }, { text: '最近一周', onClick(picker) { const end = new Date() const start = new Date() start.setDate(start.getDate() - 7) picker.$emit('pick', [start, end]) } }, { text: '最近一个月', onClick(picker) { const end = new Date() const start = new Date() start.setMonth(start.getMonth() - 1) picker.$emit('pick', [start, end]) } } ] }, // 应用选项 appOptions: [ { value: '1', label: '应用A' }, { value: '2', label: '应用B' }, { value: '3', label: '应用C' } ], // 广告位类型选项 adTypeOptions: [ { value: '1', label: '横幅广告' }, { value: '2', label: '插屏广告' }, { value: '3', label: '开屏广告' }, { value: '4', label: '信息流广告' } ] } }, created() { this.getList() }, methods: { /** * 获取数据列表 */ getList() { this.listLoading = true // 处理查询参数 const params = { page: this.listQuery.page, limit: this.listQuery.limit, appId: this.listQuery.appId, adType: this.listQuery.adType, startDate: this.listQuery.dateRange ? this.listQuery.dateRange[0] : undefined, endDate: this.listQuery.dateRange ? this.listQuery.dateRange[1] : undefined }
getCodeReportData(params).then(response => { this.list = response.data.items this.total = response.data.total this.listLoading = false }).catch(() => { this.listLoading = false }) }, /** * 处理搜索事件 */ handleFilter() { this.listQuery.page = 1 this.getList() }, /** * 重置搜索条件 */ resetQuery() { this.listQuery = { page: 1, limit: 20, appId: undefined, adType: undefined, dateRange: [dayjs().format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')] // 重置为今天 } this.getList() } } } </script>
|