当前位置:   article > 正文

vue+element-ui实现表格里嵌套表格_vue多条表单数据,点击哪行,哪行增加一个table表格

vue多条表单数据,点击哪行,哪行增加一个table表格

 

效果图:点击某行数据展开另一个嵌套在里面的table

核心代码:

从后台请求的数据格式:

代码实现:

  1. <template>
  2. <div>
  3. <div class="assetnum">
  4. <div class="assetbox br pr30">
  5. <div class="assettitle">
  6. <span>
  7. 已发现资产(数量:
  8. <strong>{{tableData2.length}}</strong>
  9. </span>
  10. </div>
  11. <div class="mytable">
  12. <el-table ref="table2" :data="tableData2" style="width: 100%">
  13. <el-table-column width="50">
  14. <template slot-scope="scope">
  15. <i class="iconfont icon-tubiaozhizuomoban" @click="toogleExpand2(scope.row)"></i>
  16. </template>
  17. </el-table-column>
  18. <el-table-column class="sectable" prop="items" type="expand" width="1">
  19. <template slot-scope="scope">
  20. <el-table :data="scope.row.items" stripe style="width: 100%">
  21. <el-table-column type="index"></el-table-column>
  22. <el-table-column prop="port" label="端口"></el-table-column>
  23. <el-table-column prop="protocol" label="协议"></el-table-column>
  24. <el-table-column prop="service" label="服务"></el-table-column>
  25. <el-table-column prop="software" label="软件"></el-table-column>
  26. </el-table>
  27. </template>
  28. </el-table-column>
  29. <el-table-column label="IP" prop="ip">
  30. <template slot-scope="scope">
  31. <span class="ipbtn">IP</span>
  32. {{scope.row.ip}}
  33. </template>
  34. </el-table-column>
  35. <el-table-column label="资产类型" prop="catagory">
  36. <template slot-scope="scope">
  37. <span v-if="scope.row.catagory=='host'">
  38. <i class="iconfont icon-zhuji1"></i>
  39. </span>
  40. <span v-if="scope.row.catagory=='db'">
  41. <i class="iconfont icon-weibiaoti-database"></i>
  42. </span>
  43. {{scope.row.catagory}}
  44. </template>
  45. </el-table-column>
  46. <el-table-column label="标准系统" prop="type">
  47. <template slot-scope="scope">
  48. <span v-if="scope.row.type=='windows'">
  49. <img src="../../../../assets/img/windows.png" alt />
  50. </span>
  51. <span v-if="scope.row.type=='RedHat'">
  52. <img src="../../../../assets/img/redhat.png" alt />
  53. </span>
  54. <span v-if="scope.row.type=='mysql'">
  55. <img src="../../../../assets/img/Oracle.png" alt />
  56. </span>
  57. <span v-if="scope.row.type=='CentOS'">
  58. <img src="../../../../assets/img/centos.png" alt />
  59. </span>
  60. {{scope.row.type}}
  61. </template>
  62. </el-table-column>
  63. </el-table>
  64. </div>
  65. </div>
  66. <div class="assetbox pl30">
  67. <div class="assettitle">
  68. <span>
  69. 不存活资产(数量:
  70. <strong>{{tableData3.length}}</strong>
  71. </span>
  72. </div>
  73. <div class="mytable">
  74. <el-table ref="table" :data="tableData3" style="width: 100%">
  75. <el-table-column width="50">
  76. <template slot-scope="scope">
  77. <i class="iconfont icon-tubiaozhizuomoban" @click="toogleExpand(scope.row)"></i>
  78. </template>
  79. </el-table-column>
  80. <el-table-column class="sectable" type="expand" width="1">
  81. <template>
  82. <el-table :data="tableData3.items" stripe style="width: 100%">
  83. <el-table-column type="index"></el-table-column>
  84. <el-table-column prop="port" label="端口"></el-table-column>
  85. <el-table-column prop="xy" label="协议"></el-table-column>
  86. <el-table-column prop="server" label="服务"></el-table-column>
  87. <el-table-column prop="software" label="软件"></el-table-column>
  88. </el-table>
  89. </template>
  90. </el-table-column>
  91. <el-table-column label="IP" prop="ip">
  92. <template slot-scope="scope">
  93. <span class="ipbtn">IP</span>
  94. {{scope.row.ip}}
  95. </template>
  96. </el-table-column>
  97. <el-table-column label="资产类型" prop="catagory">
  98. <template slot-scope="scope">
  99. <span v-if="scope.row.catagory=='host'">
  100. <i class="iconfont icon-zhuji1"></i>
  101. </span>
  102. <span v-if="scope.row.catagory=='db'">
  103. <i class="iconfont icon-weibiaoti-database"></i>
  104. </span>
  105. {{scope.row.catagory}}
  106. </template>
  107. </el-table-column>
  108. <el-table-column label="标准系统" prop="type">
  109. <template slot-scope="scope">
  110. <span v-if="scope.row.type=='windows'">
  111. <img src="../../../../assets/img/windows.png" alt />
  112. </span>
  113. <span v-if="scope.row.type=='RedHat'">
  114. <img src="../../../../assets/img/redhat.png" alt />
  115. </span>
  116. <span v-if="scope.row.type=='Oracle'">
  117. <img src="../../../../assets/img/Oracle.png" alt />
  118. </span>
  119. <span v-if="scope.row.type=='CentOS'">
  120. <img src="../../../../assets/img/centos.png" alt />
  121. </span>
  122. {{scope.row.type}}
  123. </template>
  124. </el-table-column>
  125. </el-table>
  126. </div>
  127. </div>
  128. <div></div>
  129. </div>
  130. </div>
  131. </template>
  132. <script>
  133. export default {
  134. data() {
  135. return {
  136. value2: [],
  137. value3: [],
  138. tableData2: [],
  139. tableData3: [],
  140. };
  141. },
  142. activated() {
  143. this.getDataList();
  144. },
  145. methods: {
  146. toogleExpand(row) {
  147. let $table = this.$refs.table;
  148. $table.toggleRowExpansion(row);
  149. },
  150. toogleExpand2(row) {
  151. let $table = this.$refs.table2;
  152. $table.toggleRowExpansion(row);
  153. console.log(this.$route.params.taskId)
  154. },
  155. getDataList(){
  156. //获取上一层页面点击要查看的任务ID
  157. var ids = this.$route.params.taskId;
  158. //发送请求给后台
  159. this.$http({
  160. url: this.$http.adornUrl("/ads/task/detail"),
  161. method: "get",
  162. params: this.$http.adornParams({
  163. taskId: ids
  164. })
  165. }).then(({ data }) => {
  166. if (data && data.code === 0) {
  167. let arr1 = data.data;
  168. let hadData = [];
  169. let noData = [];
  170. //对获取的数据利用status判断进行分类,再放进两个不同的数组中
  171. arr1.map(function(item,index){
  172. if(item.status == 1){
  173. hadData.push(item)
  174. }else{
  175. noData.push(item)
  176. }
  177. })
  178. //赋值给已发现资产
  179. this.tableData2 = hadData ;
  180. //赋值给不存活资产
  181. this.tableData3 = noData ;
  182. console.log(this.tableData2)
  183. } else {
  184. }
  185. });
  186. }
  187. }
  188. };
  189. </script>

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/76813
推荐阅读
相关标签