index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <div class="container1">
  3. <div class="header">
  4. <Search
  5. ref="searchref"
  6. :searchOptions="searchOptons"
  7. @data-list="getTableData"
  8. />
  9. </div>
  10. <div class="table">
  11. <!-- <el-button class="btn" style="margin-bottom: 5px" @click="showPrint"
  12. >打印</el-button
  13. > -->
  14. <el-table
  15. :data="tableData"
  16. border
  17. :style="{ height: maxHeight - 40 + 'px' }"
  18. >
  19. <el-table-column prop="reportCode" label="报告编码" />
  20. <el-table-column prop="reportName" label="报告名称" />
  21. <el-table-column prop="creator" label="创建人" />
  22. <el-table-column prop="created" label="创建时间" />
  23. <el-table-column
  24. align="center"
  25. width="160"
  26. prop=""
  27. label="操作"
  28. id="opear"
  29. >
  30. <template #default="{ row }">
  31. <el-button
  32. type="primary"
  33. class="btn"
  34. style="height: 25px"
  35. @click="toLook(row)"
  36. link
  37. >查看</el-button
  38. >
  39. </template>
  40. </el-table-column>
  41. </el-table>
  42. <Pagination />
  43. </div>
  44. <ReportView v-model="showStatus" :tableData="tableData" />
  45. </div>
  46. </template>
  47. <script setup>
  48. import Search from "@/components/Search/index.vue";
  49. import ReportView from "@/components/ReportView/index.vue";
  50. import { useDictionaryStore } from "@/store";
  51. import { getData } from "@/api/report";
  52. import Pagination from "@/components/Pagination/index.vue";
  53. const searchref = ref(null);
  54. const showPrint = () => {
  55. showStatus.value = true;
  56. };
  57. const toLook = (row) => {
  58. const fullUrl = window.location.href;
  59. const parts = fullUrl.split("/");
  60. const thirdSlashIndex = 2;
  61. const truncatedUrl = parts.slice(0, thirdSlashIndex + 1).join("/");
  62. window.open(truncatedUrl + "/" + row.fileUrl, "_blank");
  63. };
  64. const currentOption = reactive({
  65. total: 0,
  66. page: 1,
  67. limit: 10,
  68. pageSizes: [10, 20, 40],
  69. });
  70. const getCurrentMonthStartAndEndDates = () => {
  71. // 获取当前日期
  72. let now = new Date();
  73. // 获取当前月份的第一天
  74. let startDate = new Date(now.getFullYear(), now.getMonth(), 1);
  75. // 获取当前月份的最后一天
  76. let endDate = new Date(now.getFullYear(), now.getMonth() + 1, 0);
  77. // 格式化日期为'YYYY-MM-DD'格式
  78. function formatDate(date) {
  79. let year = date.getFullYear();
  80. let month = String(date.getMonth() + 1).padStart(2, "0");
  81. let day = String(date.getDate()).padStart(2, "0");
  82. return `${year}-${month}-${day}`;
  83. }
  84. // 返回包含开始和结束日期的数组
  85. return [formatDate(startDate), formatDate(endDate)];
  86. };
  87. const tableData = ref([]);
  88. const getTableData = async () => {
  89. const { data } = await getData({
  90. pageNo: currentOption.page,
  91. pageSize: currentOption.limit,
  92. startTime: searchref.value.searchForm.time
  93. ? searchref.value.searchForm.time[0]
  94. : null,
  95. endTime: searchref.value.searchForm.time
  96. ? searchref.value.searchForm.time[1]
  97. : null,
  98. reportCode: searchref.value.searchForm.reportCode,
  99. reportName: searchref.value.searchForm.reportName,
  100. });
  101. tableData.value = data.records;
  102. currentOption.total = data.totalCount;
  103. };
  104. const showStatus = ref(false);
  105. const searchOptons = [
  106. {
  107. label: "创建时间",
  108. prop: "time",
  109. type: "daterange",
  110. },
  111. {
  112. label: "报告编号",
  113. prop: "reportCode",
  114. type: "input",
  115. },
  116. {
  117. label: "报告名称",
  118. prop: "reportName",
  119. type: "input",
  120. },
  121. ];
  122. const maxHeight = ref(null);
  123. const setHeight = () => {
  124. maxHeight.value = document.querySelector(".table").clientHeight - 30;
  125. };
  126. onMounted(async () => {
  127. searchref.value.searchForm.time = getCurrentMonthStartAndEndDates();
  128. setHeight();
  129. getTableData();
  130. });
  131. </script>
  132. <style scoped lang="scss">
  133. .btn {
  134. height: 25px;
  135. }
  136. .container1 {
  137. background-color: white;
  138. width: 100%;
  139. height: 100%;
  140. padding: 20px;
  141. display: flex;
  142. flex-direction: column;
  143. .header {
  144. width: 100%;
  145. height: auto;
  146. }
  147. .table {
  148. flex: 1;
  149. padding-bottom: 20px;
  150. }
  151. }
  152. </style>