|
@@ -97,7 +97,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts" name="ProTable">
|
|
|
-import { ref, provide, onMounted, unref, computed, reactive, PropType, watch, shallowRef } from 'vue';
|
|
|
+import { ref, provide, onMounted, unref, computed, reactive, PropType, watch } from 'vue';
|
|
|
import { ElMessage, ElMessageBox, ElTable } from 'element-plus';
|
|
|
import { useSelection } from '@/hooks/useSelection';
|
|
|
import { ColumnProps, TypeProps } from '@/components/ProTable/interface';
|
|
@@ -164,7 +164,7 @@ const props = defineProps({
|
|
|
type: String,
|
|
|
default: 'total, sizes, prev, pager, next, jumper',
|
|
|
},
|
|
|
- withParent:{// 导出是否带有子父级关系
|
|
|
+ exportWithParent:{// 导出是否带有子父级关系
|
|
|
type: Boolean,
|
|
|
default: false
|
|
|
}
|
|
@@ -302,13 +302,29 @@ const updateColSetting = (test: ColumnProps[]) => {
|
|
|
const newColumnsProp = exportNewColumns.map((item) => item.prop);
|
|
|
emit('updateColSetting', exportNewColumns, newColumnsProp);
|
|
|
};
|
|
|
+// 递归获取isShow的列保持子父级关系
|
|
|
+ const getIsShowColumns = (columns: any[]) => {
|
|
|
+ let exportNewColumns = [];
|
|
|
+ columns.forEach((item) => {
|
|
|
+ if (item.isShow) {
|
|
|
+ if (item._children) {
|
|
|
+ getIsShowColumns(item._children);
|
|
|
+ } else {
|
|
|
+ exportNewColumns.push(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return exportNewColumns;
|
|
|
+};
|
|
|
// 导出当前页
|
|
|
const exportCurrent = () => {
|
|
|
let exportNewColumns: any = [];
|
|
|
let exportNewColumnsProp = [];
|
|
|
let flatColSetting = [];
|
|
|
- if(props.withParent){ // 导出带子父级关系
|
|
|
-
|
|
|
+ if(props.exportWithParent){ // 导出带子父级关系
|
|
|
+ exportNewColumns = getIsShowColumns(colSetting);
|
|
|
+ console.log(exportNewColumns,colSetting,'111')
|
|
|
+ // 保留子父级关系 递归查询
|
|
|
}else{
|
|
|
flatColSetting = flatColumnsFunc(colSetting);
|
|
|
exportNewColumns = flatColSetting.filter((item: any) => item.isShow);
|
|
@@ -332,8 +348,9 @@ const exportAll = () => {
|
|
|
let exportNewColumns: any = [];
|
|
|
let exportNewColumnsProp = [];
|
|
|
let flatColSetting = [];
|
|
|
- if(props.withParent){ // 导出带子父级关系
|
|
|
-
|
|
|
+ if(props.exportWithParent){ // 导出带子父级关系
|
|
|
+ exportNewColumns = getIsShowColumns(tableColumns);
|
|
|
+ console.log(exportNewColumns,tableColumns,'111')
|
|
|
}else{
|
|
|
flatColSetting = flatColumnsFunc(colSetting);
|
|
|
exportNewColumns = flatColSetting.filter((item: any) => item.isShow);
|