WeightTable.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <script lang="ts" setup>
  2. /**
  3. * @Name: WeightTable.vue
  4. * @Description: 特征词与权重表格
  5. * @Author: Cheney
  6. */
  7. import { usePagination } from '/@/utils/usePagination';
  8. import * as api from './api';
  9. import emitter from '/@/utils/emitter';
  10. import { useElTableData } from '/@/utils/useElTableData';
  11. import FileUploader from '/@/components/FileUploader/index.vue';
  12. import { Upload } from '@element-plus/icons-vue';
  13. const { tableData, total, currentPage, pageSize, handlePageChange } = usePagination(fetchTableData);
  14. const filter = inject<Ref>('filter');
  15. const loading = ref(false);
  16. emitter.on('QueryPage-query', () => {
  17. fetchTableData();
  18. });
  19. onBeforeMount(() => {
  20. pageSize.value = 20;
  21. });
  22. onBeforeUnmount(() => {
  23. emitter.all.clear();
  24. });
  25. async function fetchTableData() {
  26. const query = {
  27. marketplace_Ids: filter.value.marketIds,
  28. report_type: filter.value.reportType,
  29. date_start: filter.value.reportDate[0],
  30. date_end: filter.value.reportDate[1],
  31. page: currentPage.value,
  32. limit: pageSize.value
  33. };
  34. const { success, data } = await useElTableData(api.getTableData, query, tableData, total, loading);
  35. tableData.value = data || [];
  36. if (!success) {
  37. return;
  38. } else if (data && data.length > 0) {
  39. tableData.value = tableData.value.flatMap(obj =>
  40. Object.entries(obj).map(([ keyword, weight ]) => ({ keyword, weight }))
  41. );
  42. }
  43. }
  44. function handleUploadSuccess() {
  45. console.log('success=> ');
  46. }
  47. function handleUploadError() {
  48. console.log('Error=> ');
  49. }
  50. </script>
  51. <template>
  52. <el-card shadow="hover" style="border: none; margin-bottom: 10px">
  53. <el-descriptions title="/ 特征词与权重 /">
  54. <template #extra>
  55. <FileUploader
  56. :api="api.uploadFile"
  57. :icon="Upload"
  58. plain
  59. round
  60. type="warning"
  61. :showFileList="false"
  62. @upload-success="handleUploadSuccess"
  63. @upload-error="handleUploadError"
  64. >文件上传
  65. </FileUploader>
  66. </template>
  67. </el-descriptions>
  68. <el-card shadow="never">
  69. <el-table v-loading="loading" :data="tableData" height="600" style="width: 100%">
  70. <el-table-column align="center" type="index" width="60">
  71. <template #header>
  72. <span>序号</span>
  73. </template>
  74. </el-table-column>
  75. <el-table-column align="center" label="关键词" prop="keyword">
  76. <template #default="{ row }">
  77. <span class="font-semibold">{{ row.keyword }}</span>
  78. </template>
  79. </el-table-column>
  80. <el-table-column align="center" label="权重值" prop="weight">
  81. <template #default="{ row }">
  82. <span class="font-semibold">{{ row.weight }}</span>
  83. </template>
  84. </el-table-column>
  85. </el-table>
  86. <div class="mt-3.5 flex justify-end">
  87. <el-pagination
  88. v-model:current-page="currentPage"
  89. v-model:page-size="pageSize"
  90. :page-sizes="[10, 20, 30, 50, 100, 200]"
  91. :total="total"
  92. layout="sizes, prev, pager, next, total"
  93. @change="handlePageChange"/>
  94. </div>
  95. </el-card>
  96. </el-card>
  97. </template>
  98. <style scoped></style>