formTrace.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <template>
  2. <div class="container">
  3. <div class="table">
  4. <slot :name="list.name"></slot>
  5. <el-table
  6. ref="table"
  7. style="width: 100%"
  8. :data="list.data"
  9. row-key="id"
  10. @row-click="getRowData"
  11. @selection-change="selectionChange"
  12. :cell-style="columnbackgroundStyle"
  13. empty-text="暂无数据"
  14. @cell-click="getRowList"
  15. :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
  16. >
  17. <!-- 是否多选 -->
  18. <el-table-column
  19. v-if="list.isSelection"
  20. :selecttable="list"
  21. type="selection"
  22. :width="100"
  23. align="center"
  24. />
  25. <!-- 是否需要序号 -->
  26. <el-table-column
  27. v-if="list.isIndex"
  28. type="index"
  29. label="序号"
  30. width="55"
  31. align="center"
  32. />
  33. <template v-for="item in list.titledata">
  34. <el-table-column
  35. :key="item.prop"
  36. :prop="item.prop"
  37. :label="item.label"
  38. align="center"
  39. show-overflow-tooltip
  40. :width="item.width || 100"
  41. />
  42. </template>
  43. <!-- 操作列 -->
  44. <el-table-column
  45. v-if="list.isOperation"
  46. v-bind="list.data && list.data.length ? { fixed: 'right' } : null"
  47. style="margin-right: 20px"
  48. class-name="handle-td"
  49. label-class-name="tc"
  50. :label="list.operation.label"
  51. align="center"
  52. >
  53. <!-- UI统一一排放3个,4个以上出现更多 -->
  54. <template slot-scope="scope">
  55. <!-- 三个一排的情况,去掉隐藏的按钮后的长度 -->
  56. <template v-if="list.operation.data.length > 0">
  57. <div class="btn">
  58. <div v-for="item in list.operation.data" :key="item.label">
  59. <template v-if="item.type !== 'icon'">
  60. <el-button
  61. v-bind="item"
  62. :type="item.type ? item.type : ''"
  63. size="mini"
  64. @click.native.prevent="
  65. item.handleRow(scope.$index, scope.row, item.label)
  66. "
  67. >
  68. {{ item.label }}
  69. </el-button>
  70. </template>
  71. <template v-else>
  72. <i
  73. :class="[icon, item.icon]"
  74. v-bind="item"
  75. @click="
  76. item.handleRow(scope.$index, scope.row, item.label)
  77. "
  78. />
  79. </template>
  80. </div>
  81. </div>
  82. </template>
  83. </template>
  84. </el-table-column>
  85. </el-table>
  86. <div class="page">
  87. <el-pagination
  88. style="
  89. display: flex;
  90. flex-direction: row-reverse;
  91. background-color: #fff;
  92. "
  93. v-if="list.pageData.total > 0"
  94. :current-page.sync="page"
  95. :page-sizes="list.pageData.pageSizes ? list.pageData.pageSizes : [10]"
  96. :page-size="list.pageData.pageSize"
  97. layout="total, sizes, prev, pager, next, jumper"
  98. :total="list.pageData.total"
  99. @size-change="handleSizeChange"
  100. @current-change="handleCurrentChange"
  101. />
  102. </div>
  103. </div>
  104. </div>
  105. </template>
  106. <script>
  107. export default {
  108. data() {
  109. return {
  110. page: 1,
  111. };
  112. },
  113. props: {
  114. // 表格数据和表格部分属性的对象
  115. // eslint-disable-next-line vue/require-default-prop
  116. list: {
  117. type: Object,
  118. },
  119. },
  120. created() {
  121. console.log(this.list);
  122. },
  123. mounted() {},
  124. methods: {
  125. columnbackgroundStyle({ row, column, rowIndex, columnIndex }) {
  126. if (column.type == "default") {
  127. if (column.label === "需求名称") {
  128. return "color:#0682CD;";
  129. }
  130. }
  131. // if (columnIndex == 1) {
  132. // //让下标为1的列数背景颜色显示为红色(颜色自定义根据大家需求来)
  133. // return 'color:#0682CD;'
  134. // }
  135. },
  136. selectionChange(val) {
  137. //多选数字回调
  138. this.$emit("num", val);
  139. },
  140. handleAdd(name) {
  141. this.$emit("toolMsg", name);
  142. },
  143. handleRow(index, row, lable) {},
  144. handleSizeChange(val) {
  145. this.$emit("changeSize", val);
  146. console.log(`每页 ${val} 条`);
  147. },
  148. handleCurrentChange(val) {
  149. this.$emit("changeNum", val);
  150. console.log(`当前页: ${val}`);
  151. },
  152. // 点击行即可选中
  153. getRowData(row) {
  154. this.$refs.table.toggleRowSelection(row);
  155. },
  156. getRowList(row, column, event, cell) {
  157. this.$emit("clickDemand", column.label, row);
  158. },
  159. },
  160. };
  161. </script>
  162. <style lang="scss" scoped>
  163. .btn {
  164. display: flex;
  165. justify-content: center;
  166. }
  167. .container {
  168. display: flex;
  169. flex-direction: column;
  170. justify-content: space-between;
  171. height: 100%;
  172. overflow: hidden;
  173. margin-bottom: 4%;
  174. .table {
  175. flex: 1;
  176. position: relative;
  177. ::v-deep.el-table {
  178. position: absolute;
  179. overflow-y: auto;
  180. }
  181. }
  182. }
  183. </style>