index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <div class="table-container">
  3. <slot name="files"></slot>
  4. <el-table
  5. v-loading="listLoading"
  6. :data="tableData"
  7. :row-key="rowKey"
  8. tooltip-effect="dark"
  9. style="width: 100%"
  10. :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
  11. :header-cell-style="{
  12. background: '#fafafa',
  13. color: '#333',
  14. 'font-weight': 700,
  15. }"
  16. :default-sort="{ prop: 'dec_code', order: 'descending' }"
  17. @selection-change="handleSelectionChange">
  18. <el-table-column
  19. v-if="selectionShow"
  20. type="selection"
  21. width="50"
  22. align="center"
  23. highlight-current-row
  24. fixed
  25. :reserve-selection="true"></el-table-column>
  26. <el-table-column
  27. v-if="serialShow"
  28. type="index"
  29. width="50"
  30. :label="$t('table_index')"></el-table-column>
  31. <template v-for="item in tableColumns">
  32. <el-table-column
  33. :align="item.align"
  34. v-if="!item.type"
  35. :key="item.prop"
  36. :prop="item.prop"
  37. :label="$t(item.label)"
  38. :formatter="item.formatter"
  39. :width="item.width"
  40. :min-width="item.minwidth"
  41. :sortable="item.sortable">
  42. </el-table-column>
  43. <el-table-column
  44. v-else
  45. :key="1 + item.prop"
  46. :prop="item.prop"
  47. :label="$t(item.label)"
  48. :formatter="item.formatter"
  49. :width="item.width"
  50. :sortable="item.sortable">
  51. <template slot-scope="{ row }">
  52. <!-- 图片 -->
  53. <el-image
  54. v-if="item.type == 'img'"
  55. :src="row[item.prop]"
  56. style="width: 80px; height: 80px" />
  57. <!-- 编辑输入框 -->
  58. <template v-else-if="item.type == 'input'">
  59. <el-input
  60. clearable
  61. v-model="row[item.prop]"
  62. class="edit-input"
  63. size="small"
  64. v-if="row.edit" />
  65. <span v-else>{{ row[item.prop] }}</span>
  66. <i
  67. class="iconfont icon-bianji"
  68. style="cursor: pointer"
  69. @click="toggleEdit(row)">
  70. </i>
  71. </template>
  72. <!-- 开关切换 -->
  73. <el-switch
  74. v-else-if="item.type == 'switch'"
  75. @change="toggleStatus(row)"
  76. v-model="row[item.prop]"
  77. active-color="#13ce66"
  78. inactive-color="#ff4949"
  79. active-text="ON"
  80. inactive-text="OFF"
  81. :active-value="1"
  82. :inactive-value="0"></el-switch>
  83. <!-- popover -->
  84. <el-popover
  85. v-else-if="item.type == 'popover'"
  86. width="300"
  87. trigger="hover"
  88. :content="row[item.prop]">
  89. <div slot="reference" class="ellipsis">{{ row[item.prop] }}</div>
  90. </el-popover>
  91. <template v-else-if="item.type == 'formatType'">
  92. {{ row[item.prop] | formatFilters(item.filterData) }}
  93. </template>
  94. <template v-else-if="item.type == 'button'">
  95. <slot
  96. name="button"
  97. :row="row"></slot>
  98. </template>
  99. </template>
  100. </el-table-column>
  101. </template>
  102. <!--region 按钮操作组-->
  103. <el-table-column
  104. fixed="right"
  105. :label="$t('table_operation')"
  106. :width="operateWith"
  107. v-if="handleShow">
  108. <template slot-scope="{ row }">
  109. <slot
  110. name="operation"
  111. :row="row"></slot>
  112. <!-- <el-button @click="openDetail(3, row)" type="text" size="medium"
  113. >{{ $t('btn_edit') }}</el-button
  114. >
  115. <el-button
  116. type="text"
  117. size="medium"
  118. style="color: #ff0000"
  119. @click="deleteListOpt(row.id)"
  120. >{{ $t('btn_delete') }}</el-button
  121. > -->
  122. </template>
  123. </el-table-column>
  124. </el-table>
  125. </div>
  126. </template>
  127. <script>
  128. export default {
  129. name: 'GlobalTable',
  130. filters: {
  131. formatFilters(val,filterData){
  132. return filterData[val];
  133. }
  134. },
  135. props: {
  136. tableData: Array,
  137. tableColumns: Array,
  138. listLoading: {
  139. type: Boolean,
  140. default: false,
  141. },
  142. rowKey: {
  143. type: String,
  144. default: 'id',
  145. },
  146. selectionShow: {
  147. type: Boolean,
  148. default: true,
  149. },
  150. serialShow: {
  151. type: Boolean,
  152. default: true,
  153. },
  154. handleShow: {
  155. type: Boolean,
  156. default: true,
  157. },
  158. operate: {
  159. // 按钮操作组
  160. type: Array,
  161. default: () => [],
  162. },
  163. operateWith: {
  164. type: String,
  165. default: '160',
  166. },
  167. },
  168. data() {
  169. return {}
  170. },
  171. methods: {
  172. // 修改input
  173. toggleEdit(row) {
  174. if (row.edit) {
  175. this.$emit('handleEditRank', row)
  176. // category
  177. // .editRank({ id: row.id, rank: +row.rank })
  178. // .then((response) => {});
  179. }
  180. row.edit = !row.edit
  181. },
  182. // 切换开关
  183. toggleStatus(row) {
  184. this.$emit('handleToggleStatus', row)
  185. // let status = row.status ? 1 : 0;
  186. // category
  187. // .editStatus({ id: row.id, status })
  188. // .then((response) => {
  189. // this._recursiveSetStatus(row, "status", row.status);
  190. // })
  191. // .catch((err) => {
  192. // row.status = !row.status;
  193. // });
  194. },
  195. // 多行选中
  196. handleSelectionChange(val) {
  197. this.$emit('handleSelectionChange', val)
  198. },
  199. },
  200. }
  201. </script>
  202. <style scoped>
  203. .edit-input {
  204. display: inline-block;
  205. width: 70px;
  206. }
  207. .icon-bianji {
  208. vertical-align: middle;
  209. margin-left: 10px;
  210. }
  211. </style>