Table.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <div class="app-container">
  3. <!-- 表格数据 -->
  4. <el-table v-loading="loading" :data="data" @selection-change="handleSelectionChange">
  5. <el-table-column type="selection" width="55" align="center" v-if="isSelect" fixed/>
  6. <template v-for="item in column" :key="item.prop">
  7. <el-table-column v-if="item.type === 'img'" :label="item.label" :prop="item.tableProp || item.prop"
  8. :width="item.width">
  9. <template #default="scope">
  10. <el-button type="primary" link @click="onClick(scope.row,item.tableProp || item.prop)">
  11. 查看
  12. </el-button>
  13. </template>
  14. </el-table-column>
  15. <el-table-column v-else-if="item.type === 'dict'" :label="item.label" :prop="item.tableProp || item.prop"
  16. :width="item.width">
  17. <template #default="scope">
  18. <dict-tag v-if="item.dict" :options="item.dict" :value="String(scope.row[item.tableProp || item.prop])" />
  19. </template>
  20. </el-table-column>
  21. <el-table-column v-else-if="item.type === 'render'" :label="item.label" :prop="item.prop"
  22. :width="item.width">
  23. <template #default="scope">
  24. <span>{{ item.render(scope.row) }}</span>
  25. </template>
  26. </el-table-column>
  27. <el-table-column v-else :label="item.label" :prop="item.tableProp || item.prop"
  28. :width="item.width" show-overflow-tooltip ></el-table-column>
  29. </template>
  30. <el-table-column label="操作" class-name="small-padding fixed-width" v-if="isScope" fixed="right" min-width="120">
  31. <template #default="scope">
  32. <el-space wrap>
  33. <div v-for="item in scopeBtns" :key="item.key">
  34. <template v-if="item.show">
  35. <template v-if="item.hasPermi">
  36. <el-button link :type="item.type"
  37. @click="item.func(scope.row)" v-if="item.show(scope.row)"> {{ item.label }}</el-button>
  38. </template>
  39. <template v-else>
  40. <el-button link :type="item.type"
  41. @click="item.func(scope.row)" v-if="item.show(scope.row)"> {{ item.label }}</el-button>
  42. </template>
  43. </template>
  44. <template v-else-if="item.hasPermi">
  45. <el-button link :type="item.type"
  46. @click="item.func(scope.row)" v-hasPermi="item.hasPermi"> {{ item.label }}</el-button>
  47. </template>
  48. <template v-else>
  49. <el-button link :type="item.type"
  50. @click="item.func(scope.row)" > {{ item.label }}</el-button>
  51. </template>
  52. </div>
  53. </el-space>
  54. </template>
  55. </el-table-column>
  56. </el-table>
  57. <el-dialog v-model="dialogVisible" title="图片查看" :before-close="handleClose">
  58. <div class="img-box">
  59. <el-space wrap>
  60. <div v-for="(imgItem, imgIndex) in images" :key="imgIndex">
  61. <el-image :src="imgItem" />
  62. </div>
  63. </el-space>
  64. </div>
  65. <template #footer>
  66. <div class="dialog-footer">
  67. <el-button @click="dialogVisible = false">取消</el-button>
  68. <el-button type="primary" @click="dialogVisible = false">
  69. 确定
  70. </el-button>
  71. </div>
  72. </template>
  73. </el-dialog>
  74. </div>
  75. </template>
  76. <script setup>
  77. import { ref } from 'vue'
  78. import { provide,inject } from 'vue'
  79. const props = defineProps({
  80. column: {
  81. type: Object,
  82. default: [],
  83. required: true
  84. },
  85. loading: {
  86. type: Boolean,
  87. default: false,
  88. required: false
  89. },
  90. data: {
  91. type: Array,
  92. default: [],
  93. required: true
  94. },
  95. scopeBtns: {
  96. type: Array,
  97. default: [],
  98. },
  99. tableKey: {
  100. type: String,
  101. default: 'id',
  102. },
  103. isSelect:{
  104. type: Boolean,
  105. default: true
  106. },
  107. isScope:{
  108. type: Boolean,
  109. default: true
  110. }
  111. })
  112. const ids = ref([])
  113. const dialogVisible = ref(false)
  114. const images = ref([]);
  115. const injects = inject('selectChange');
  116. /** 多选框选中数据 */
  117. const handleSelectionChange = (selection,row) => {
  118. console.log('selection', selection);
  119. injects(selection)
  120. ids.value = selection.map(item => item[props.tableKey]);
  121. console.log('ids', ids);
  122. }
  123. const resetIds = () => {
  124. ids.value = []
  125. }
  126. const onClick = (row,pro) => {
  127. console.log('row', row,pro,typeof pro);
  128. dialogVisible.value = true;
  129. if(typeof pro === 'object'){
  130. images.value = pro.map(item =>{
  131. return row[item]
  132. })
  133. console.log('pro',aa);
  134. return;
  135. }
  136. if (row[pro]) {
  137. images.value = row[pro].split(',');
  138. }
  139. }
  140. defineExpose({
  141. ids,
  142. resetIds
  143. })
  144. </script>
  145. <style lang='scss' scoped>
  146. .img-box {
  147. display: flex;
  148. align-items: center;
  149. justify-content: center;
  150. min-height: 300px;
  151. width: 100%;
  152. height: 100%;
  153. }
  154. </style>