dataTable.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <!--
  2. * @Author: your name
  3. * @Date: 2024-10-28 16:46:38
  4. * @LastEditTime: 2024-11-14 15:55:59
  5. * @LastEditors: bogon
  6. * @Description: In User Settings Edit
  7. * @FilePath: /performance-test/src/views/performance/components/custonAsCom/dataTable.vue
  8. -->
  9. <template>
  10. <div class="dataTableContent" v-loading="loading">
  11. <el-tabs
  12. v-if="tabData.length > 0"
  13. v-model="activeName"
  14. @tab-click="handleClick"
  15. class="tabsBox"
  16. >
  17. <template v-for="(tabItem, ind) in tabData">
  18. <el-tab-pane
  19. :label="tabItem.filename"
  20. :name="String(tabItem.filename + tabItem.fileId)"
  21. :key="tabItem.fileData + ind + 'tabPane'"
  22. >
  23. <el-row
  24. type="flex"
  25. class="row-bg"
  26. justify="end"
  27. :key="tabItem.filename + ind + 'row'"
  28. >
  29. <el-button type="primary" @click="handleEditTable(tabItem.fileId)"
  30. >编辑</el-button
  31. >
  32. </el-row>
  33. <template v-if="tabItem.fileData && tabItem.fileData.length > 0">
  34. <el-table
  35. :data="tabItem.fileData"
  36. border
  37. height="600"
  38. style="width: 100%"
  39. :key="ind + tabItem.fileData"
  40. >
  41. <el-table-column
  42. :width="
  43. Object.keys(tabItem.fileData[0]).length > 6 ? 200 : null
  44. "
  45. v-for="(tableTitle, index) in Object.keys(tabItem.fileData[0])"
  46. :key="index + 'title'"
  47. :prop="tableTitle"
  48. :label="tableTitle"
  49. >
  50. </el-table-column>
  51. </el-table>
  52. </template>
  53. <template v-else>
  54. <el-empty :image-size="200" description="数据正在计算"></el-empty>
  55. </template>
  56. </el-tab-pane>
  57. </template>
  58. </el-tabs>
  59. <el-empty v-else :image-size="200"></el-empty>
  60. </div>
  61. </template>
  62. <script>
  63. import {
  64. getDataFromIndexedDB,
  65. checkObjectStoreExists,
  66. } from "@/utils/indexedDb";
  67. import { mapMutations, mapState } from "vuex";
  68. export default {
  69. data() {
  70. return {
  71. activeName: "",
  72. tabData: [],
  73. tableData: [],
  74. loading: true,
  75. };
  76. },
  77. // computed: {
  78. // ...mapState("dragChart", {
  79. // triggerGetData: "triggerGetData",
  80. // }),
  81. // },
  82. // watch: {
  83. // triggerGetData: function (newVal) {
  84. // if (newVal) {
  85. // console.log(newVal, "newVal dataTable");
  86. // this.setTriggerGetData(false);
  87. // this.getIndexDbData();
  88. // // 重置 triggerGetData 状态为 false
  89. // }
  90. // },
  91. // },
  92. mounted() {
  93. //判断indexedDb中是否存在这个数据表
  94. checkObjectStoreExists("FileDataDB", "files")
  95. .then((exists) => {
  96. if (exists) {
  97. console.log("对象存储 'files' 存在!");
  98. this.getIndexDbData();
  99. } else {
  100. this.loading = false;
  101. console.log("对象存储 'files' 不存在!");
  102. }
  103. })
  104. .catch((error) => {
  105. console.error("检查对象存储时出错:", error);
  106. });
  107. },
  108. methods: {
  109. ...mapMutations("dragChart", ["setTriggerGetData"]),
  110. async getIndexDbData() {
  111. // this.loading = true;
  112. console.log("触发了这个事件");
  113. const jsonData = await getDataFromIndexedDB();
  114. this.tabData = jsonData;
  115. console.log(jsonData, "jsonData dataTable");
  116. this.activeName =
  117. jsonData &&
  118. jsonData[0] &&
  119. String(jsonData[0].filename + jsonData[0].fileId);
  120. this.loading = false;
  121. },
  122. handleClick(tab, event) {},
  123. handleEditTable(id) {
  124. this.$router.push({
  125. path: "/home/performance/luckySheet",
  126. query: { id },
  127. });
  128. },
  129. },
  130. };
  131. </script>
  132. <style scoped lang="scss">
  133. .dataTableContent {
  134. .tabsBox {
  135. margin: 0 15px;
  136. ::v-deep .el-tabs__item {
  137. padding: 0 20px !important;
  138. }
  139. .row-bg {
  140. margin-bottom: 10px;
  141. }
  142. }
  143. }
  144. </style>