index.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <template>
  2. <div class="app-container">
  3. <!-- Tab 切换 -->
  4. <el-tabs v-model="activeTab" @tab-click="handleTabClick">
  5. <el-tab-pane label="公司" name="company"></el-tab-pane>
  6. <el-tab-pane label="项目" name="project"></el-tab-pane>
  7. <el-tab-pane label="课程" name="course"></el-tab-pane>
  8. <el-tab-pane label="公开课" name="common"></el-tab-pane>
  9. </el-tabs>
  10. <!-- 查询条件 -->
  11. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  12. <!-- 公司选择 -->
  13. <el-form-item label="公司" v-if="activeTab === 'all' || activeTab === 'company'">
  14. <el-select v-model="queryParams.companyId" placeholder="请选择公司" filterable clearable size="small">
  15. <el-option v-for="(option, index) in companyList" :key="index" :value="option.dictValue" :label="option.dictLabel"></el-option>
  16. </el-select>
  17. </el-form-item>
  18. <!-- 项目选择 -->
  19. <el-form-item label="项目" v-if="activeTab === 'all' || activeTab === 'project'">
  20. <el-select v-model="queryParams.project" placeholder="请选择项目" filterable clearable size="small">
  21. <el-option v-for="dict in projectOptions" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue" />
  22. </el-select>
  23. </el-form-item>
  24. <!-- 课程选择 -->
  25. <el-form-item label="课程" v-if="activeTab === 'all' || activeTab === 'course'">
  26. <el-select v-model="queryParams.courseId" placeholder="请选择课程" filterable clearable size="small">
  27. <el-option v-for="dict in courseLists" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue" />
  28. </el-select>
  29. </el-form-item>
  30. <el-form-item label="公开课" v-if="activeTab === 'all' || activeTab === 'common'">
  31. <el-select v-model="queryParams.courseId" placeholder="请选择课程" filterable clearable size="small">
  32. <el-option v-for="dict in courseLists" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue" />
  33. </el-select>
  34. </el-form-item>
  35. <!-- 时间选择 -->
  36. <el-form-item label="年月">
  37. <el-date-picker
  38. v-model="timeRange"
  39. type="daterange"
  40. placeholder="选择年月"
  41. :value-format="'yyyy-MM-dd'"
  42. :picker-options="pickerOptions"
  43. @change="handleDateData"
  44. ></el-date-picker>
  45. </el-form-item>
  46. <el-form-item>
  47. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  48. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  49. <el-button type="warning" plain icon="el-icon-download" size="mini" :loading="exportLoading" @click="handleExport" >导出</el-button>
  50. </el-form-item>
  51. </el-form>
  52. <!-- 表格 -->
  53. <el-table border v-loading="loading" :data="courseTrafficLogList" @selection-change="handleSelectionChange">
  54. <el-table-column type="selection" width="55" align="center" />
  55. <!-- 公司列 -->
  56. <el-table-column label="公司" align="center" prop="companyName" v-if="activeTab === 'all' || activeTab === 'company'" />
  57. <!-- 项目列 -->
  58. <el-table-column label="项目" align="center" prop="projectName" v-if="activeTab === 'all' || activeTab === 'project'" />
  59. <!-- 课程列 -->
  60. <el-table-column label="课程" align="center" prop="courseName" v-if="activeTab === 'all' || activeTab === 'course'||activeTab === 'common'" />
  61. <el-table-column label="日期" align="center" prop="month" />
  62. <el-table-column label="使用流量" align="center">
  63. <template slot-scope="scope">
  64. <span>{{ formatTrafficData(scope.row.totalInternetTraffic) }}</span>
  65. </template>
  66. </el-table-column>
  67. </el-table>
  68. <!-- 分页 -->
  69. <pagination
  70. v-show="total > 0"
  71. :total="total"
  72. :page.sync="queryParams.pageNum"
  73. :limit.sync="queryParams.pageSize"
  74. @pagination="getList"
  75. />
  76. </div>
  77. </template>
  78. <script>
  79. import { listCourseTrafficLog, exportCourseTrafficLog } from "@/api/course/courseTrafficLog";
  80. import { courseList } from "@/api/course/courseRedPacketLog";
  81. import { allList } from "@/api/company/company";
  82. export default {
  83. data() {
  84. return {
  85. activeTab: "company", // 默认 tab
  86. timeRange: null, // 时间范围单独绑定
  87. companyList: [],
  88. projectOptions: [],
  89. pickerOptions: {
  90. shortcuts: [
  91. {
  92. text: '今日',
  93. onClick(picker) {
  94. const start = new Date();
  95. const end = new Date();
  96. picker.$emit('pick', [start, end]);
  97. }
  98. },
  99. {
  100. text: '昨日',
  101. onClick(picker) {
  102. const start = new Date();
  103. start.setDate(start.getDate() - 1);
  104. const end = new Date(start);
  105. picker.$emit('pick', [start, end]);
  106. }
  107. },
  108. {
  109. text: '本周',
  110. onClick(picker) {
  111. const now = new Date();
  112. const day = now.getDay() || 7;
  113. const start = new Date(now);
  114. start.setDate(now.getDate() - day + 1);
  115. const end = new Date();
  116. picker.$emit('pick', [start, end]);
  117. }
  118. },
  119. {
  120. text: '本月',
  121. onClick(picker) {
  122. const start = new Date(new Date().setDate(1));
  123. const end = new Date();
  124. picker.$emit('pick', [start, end]);
  125. }
  126. }
  127. ]
  128. },
  129. courseLists: [],
  130. loading: false,
  131. exportLoading: false,
  132. showSearch: true,
  133. total: 0,
  134. courseTrafficLogList: [],
  135. queryParams: {
  136. tabType: "", // 当前 tab 类型
  137. startDate: null,
  138. endDate: null,
  139. pageNum: 1,
  140. pageSize: 10,
  141. companyId: null,
  142. project: null,
  143. courseId: null
  144. }
  145. };
  146. },
  147. created() {
  148. courseList().then(res => this.courseLists = res.list);
  149. this.getDicts("sys_course_project").then(res => this.projectOptions = res.data);
  150. this.getAllCompany();
  151. this.getList();
  152. },
  153. methods: {
  154. handleTabClick(tab) {
  155. this.queryParams.tabType = tab.name;
  156. this.queryParams.pageNum = 1;
  157. // 清理互斥参数
  158. if (tab.name !== "project") this.queryParams.project = null;
  159. if (tab.name !== "course") this.queryParams.courseId = null;
  160. if (tab.name !== "company") this.queryParams.companyId = null;
  161. this.getList();
  162. },
  163. handleDateData() {
  164. if (this.timeRange) {
  165. this.queryParams.startDate = this.timeRange[0];
  166. this.queryParams.endDate = this.timeRange[1];
  167. } else {
  168. this.queryParams.startDate = null;
  169. this.queryParams.endDate = null;
  170. }
  171. },
  172. getAllCompany() {
  173. allList().then(res => this.companyList = res.rows);
  174. },
  175. getList() {
  176. this.loading = true;
  177. listCourseTrafficLog(this.queryParams).then(res => {
  178. this.courseTrafficLogList = res.rows;
  179. this.total = res.total;
  180. }).finally(() => {
  181. this.loading = false;
  182. });
  183. },
  184. handleQuery() {
  185. this.queryParams.tabType = this.activeTab
  186. this.queryParams.pageNum = 1;
  187. this.getList();
  188. },
  189. resetQuery() {
  190. this.timeRange = null;
  191. this.queryParams = {
  192. ...this.queryParams,
  193. startDate: null,
  194. endDate: null,
  195. companyId: null,
  196. project: null,
  197. courseId: null,
  198. pageNum: 1,
  199. };
  200. this.getList();
  201. },
  202. formatTrafficData(traffic) {
  203. return `${(traffic / (1024 ** 3)).toFixed(4)} GB`;
  204. },
  205. handleSelectionChange(selection) {
  206. this.ids = selection.map(item => item.logId);
  207. },
  208. handleExport() {
  209. this.$confirm("确认导出数据?", "提示").then(() => {
  210. this.exportLoading = true;
  211. return exportCourseTrafficLog(this.queryParams);
  212. }).then(res => {
  213. this.download(res.msg);
  214. }).finally(() => {
  215. this.exportLoading = false;
  216. });
  217. },
  218. }
  219. };
  220. </script>