|
|
@ -218,11 +218,11 @@ |
|
|
|
</template> |
|
|
|
|
|
|
|
<script setup lang="ts"> |
|
|
|
import { ref, reactive, computed, onMounted, nextTick, toRaw, useAttrs, getCurrentInstance, provide, watchEffect } from 'vue'; |
|
|
|
import { ref, reactive, computed, onMounted, nextTick, toRaw, useAttrs, getCurrentInstance, provide, watchEffect, watch } from 'vue'; |
|
|
|
import { axios, Environment, NotifyManager, TreeBuilder, VueTools, Tools } from '@/platform'; |
|
|
|
import { useQuasar, getCssVar, exportFile } from 'quasar'; |
|
|
|
import { IconEnum } from '@/platform/enums'; |
|
|
|
import { extractTableColumnsProps, arrayToMap, OperatorTypeEnum, isEmpty, PageStatusEnum } from '@/platform/components/utils'; |
|
|
|
import { arrayToMap, OperatorTypeEnum, isEmpty, PageStatusEnum } from '@/platform/components/utils'; |
|
|
|
import TreeGridRow from './TreeGridRow.vue'; |
|
|
|
import GridConfig from './GridConfig.vue'; |
|
|
|
|
|
|
@ -395,7 +395,61 @@ const dialogRef = ref(); |
|
|
|
const drawerRef = ref(); |
|
|
|
const dialogFormRef = ref(); |
|
|
|
const infoRef = ref(); |
|
|
|
const tableColumnsMap = arrayToMap('name', props.columns); |
|
|
|
const tableColumns = ref(props.columns); |
|
|
|
const tableColumnsMap = ref(arrayToMap('name', tableColumns.value)); |
|
|
|
const columnStyle = (item: any) => { |
|
|
|
let style = ''; |
|
|
|
if (item.hasOwnProperty('style')) { |
|
|
|
style = item.style; |
|
|
|
} |
|
|
|
if (item.hasOwnProperty('width')) { |
|
|
|
if (typeof item.width === 'number') { |
|
|
|
item.style = `min-width: ` + item.width + `px; width: ` + item.width + `px;max-width: ` + item.width + `px;` + style; |
|
|
|
} else { |
|
|
|
item.style = `min-width: ` + item.width + `; width: ` + item.width + `;max-width: ` + item.width + `;` + style; |
|
|
|
} |
|
|
|
delete item.width; |
|
|
|
|
|
|
|
if (item.hasOwnProperty('classes')) { |
|
|
|
item.classes = item.classes + ' truncate'; |
|
|
|
} else { |
|
|
|
item.classes = 'truncate'; |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
const columnChildrenHandler = (item: any, gridColumns: any) => { |
|
|
|
if (item.columns && item.columns.length > 0) { |
|
|
|
item.columns.forEach((column) => { |
|
|
|
columnChildrenHandler(column, gridColumns); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
columnStyle(item); |
|
|
|
gridColumns.push({ |
|
|
|
...{ align: 'left', label: item.name, field: item.name, sortable: true, hidden: false }, |
|
|
|
...item, |
|
|
|
}); |
|
|
|
} |
|
|
|
}; |
|
|
|
const extractTableColumnsProps = () => { |
|
|
|
const gridColumns = <any>[]; |
|
|
|
if (tableColumns.value && tableColumns.value.length > 0) { |
|
|
|
gridColumns.push({ name: '_sortNo_', align: 'center', label: '序号', field: '_sortNo_', hidden: props.sortNo ? false : true }); |
|
|
|
tableColumns.value.forEach((item: any) => { |
|
|
|
columnChildrenHandler(item, gridColumns); |
|
|
|
}); |
|
|
|
return gridColumns; |
|
|
|
} |
|
|
|
return []; |
|
|
|
}; |
|
|
|
const extractTableColumns = ref(extractTableColumnsProps()); |
|
|
|
watch( |
|
|
|
() => props.columns, |
|
|
|
(newVal, oldVal) => { |
|
|
|
tableColumns.value = newVal; |
|
|
|
tableColumnsMap.value = arrayToMap('name', tableColumns.value); |
|
|
|
extractTableColumns.value = extractTableColumnsProps(); |
|
|
|
}, |
|
|
|
); |
|
|
|
const queryFormFieldsMap = arrayToMap('name', props.queryFormFields); |
|
|
|
const rowKey_ = '_rowKey_'; // 行数据中前端附加的UUID字段名 |
|
|
|
const url = { |
|
|
@ -406,11 +460,10 @@ const url = { |
|
|
|
removeDataUrl: props.removeDataUrl, |
|
|
|
}; |
|
|
|
|
|
|
|
const extractTableColumns = extractTableColumnsProps(props); |
|
|
|
// 多表头插槽传入的 props 处理 |
|
|
|
const titleScopeHandler = (column: any, scope: any) => { |
|
|
|
if (extractTableColumns && extractTableColumns.length > 0) { |
|
|
|
const i = extractTableColumns.findIndex((item) => item.name === column.name); |
|
|
|
if (extractTableColumns.value && extractTableColumns.value.length > 0) { |
|
|
|
const i = extractTableColumns.value.findIndex((item) => item.name === column.name); |
|
|
|
if (i > -1) { |
|
|
|
return scope; |
|
|
|
} |
|
|
@ -425,7 +478,7 @@ const table = reactive({ |
|
|
|
allTicked: <null | boolean>false, |
|
|
|
gridConfig: false, |
|
|
|
stickyNum: props.stickyNum, |
|
|
|
columns: extractTableColumns, |
|
|
|
columns: extractTableColumns.value, |
|
|
|
treeExpand: props.treeDefaultExpandAll, |
|
|
|
checkboxSelection: props.checkboxSelection, |
|
|
|
sortNo: props.sortNo, |
|
|
@ -660,10 +713,10 @@ const buttonObj = { |
|
|
|
icon: 'file_download', |
|
|
|
label: '导出', |
|
|
|
click: (selected, context) => { |
|
|
|
const content = [props.columns.map((col) => wrapCsvValue(col.label))] |
|
|
|
const content = [tableColumns.value.map((col) => wrapCsvValue(col.label))] |
|
|
|
.concat( |
|
|
|
table.rows.map((row) => |
|
|
|
props.columns |
|
|
|
tableColumns.value |
|
|
|
.map((col) => wrapCsvValue(typeof col.field === 'function' ? col.field(row) : row[col.field === void 0 ? col.name : col.field], col.format, row)) |
|
|
|
.join(','), |
|
|
|
), |
|
|
@ -1004,7 +1057,7 @@ function findParents(arrData: any, name: any) { |
|
|
|
} |
|
|
|
|
|
|
|
const handlerMoreRowColumnTitle = () => { |
|
|
|
props.columns.forEach((tableColumn: any) => { |
|
|
|
tableColumns.value.forEach((tableColumn: any) => { |
|
|
|
columnToMap(tableColumn); |
|
|
|
}); |
|
|
|
let maxColumnChildrenLevel = 0; |
|
|
@ -1024,7 +1077,7 @@ const handlerMoreRowColumnTitle = () => { |
|
|
|
tmpColspan = 0; |
|
|
|
|
|
|
|
// 处理列的 parent |
|
|
|
const parent = findParents(props.columns, key); |
|
|
|
const parent = findParents(tableColumns.value, key); |
|
|
|
moreColumnTitleMap.get(key)!.parents = parent; |
|
|
|
|
|
|
|
// 处理列的 parentLevel |
|
|
@ -1076,7 +1129,7 @@ const tableHeightComputed = computed(() => { |
|
|
|
// 浏览器可视区域高度 |
|
|
|
const screenHeight = $q.screen.height; |
|
|
|
// 系统底部高度(一般用来显示XX版权所有那一层) |
|
|
|
const footerHeight = gc.theme.footer.enable ? gc.theme.footer.height : 0; |
|
|
|
const footerHeight = gc.theme.footer.show ? gc.theme.footer.height : 0; |
|
|
|
// 主面板下边距 |
|
|
|
const mainPaddingBottom = gc.theme.main.paddingBottom || 0; |
|
|
|
// 主面板容器下边距 |
|
|
@ -1107,7 +1160,7 @@ const noDataBottomHeightComputed = computed(() => { |
|
|
|
// 浏览器可视区域高度 |
|
|
|
const screenHeight = $q.screen.height; |
|
|
|
// 系统底部高度(一般用来显示XX版权所有那一层) |
|
|
|
const footerHeight = gc.theme.footer.enable ? gc.theme.footer.height : 0; |
|
|
|
const footerHeight = gc.theme.footer.show ? gc.theme.footer.height : 0; |
|
|
|
// 其他高度,边框,用户自定义留白等,默认 4px |
|
|
|
const otherHeight = table.spaceHeight || 4; |
|
|
|
// 主面板下边距 |
|
|
@ -1404,10 +1457,10 @@ const view = () => { |
|
|
|
viewInfo.infoArray.push({ label: item.label, value: value, originalValue: getSelectedRowsComputed.value[0][item.name] }); |
|
|
|
} else { |
|
|
|
let value = null; |
|
|
|
if (tableColumnsMap.get(item.name) && tableColumnsMap.get(item.name).format) { |
|
|
|
if (tableColumnsMap.value.get(item.name) && tableColumnsMap.value.get(item.name).format) { |
|
|
|
value = getSelectedRowsComputed.value[0][item.name]; |
|
|
|
try { |
|
|
|
value = tableColumnsMap.get(item.name).format(getSelectedRowsComputed.value[0][item.name], getSelectedRowsComputed.value[0]); |
|
|
|
value = tableColumnsMap.value.get(item.name).format(getSelectedRowsComputed.value[0][item.name], getSelectedRowsComputed.value[0]); |
|
|
|
} catch (error) { |
|
|
|
console.error('format error!'); |
|
|
|
} |
|
|
@ -1418,7 +1471,7 @@ const view = () => { |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
for (let item of tableColumnsMap) { |
|
|
|
for (let item of tableColumnsMap.value) { |
|
|
|
if (item[1].format) { |
|
|
|
let value = getSelectedRowsComputed.value[0][item[0]]; |
|
|
|
try { |
|
|
@ -1455,8 +1508,14 @@ const wrapCsvValue = (val, formatFn, row) => { |
|
|
|
|
|
|
|
// 替换全部行 |
|
|
|
const setLocalData = (rows: any) => { |
|
|
|
if (props.tree && props.treeRelationship === 'parent') { |
|
|
|
const treeRows = TreeBuilder.build(rows, props.foreignKey, props.primaryKey); |
|
|
|
table.rows = treeRows; |
|
|
|
} else { |
|
|
|
table.rows = rows; |
|
|
|
} |
|
|
|
addRowKey(table.rows); |
|
|
|
state.pagination.rowsNumber = table.rows.length; |
|
|
|
stickyHeaderColumn(); |
|
|
|
}; |
|
|
|
// 替换单行数据 |
|
|
@ -1478,6 +1537,7 @@ const removeRows = (rows) => { |
|
|
|
1, |
|
|
|
); |
|
|
|
}); |
|
|
|
state.pagination.rowsNumber = table.rows.length; |
|
|
|
stickyHeaderColumn(); |
|
|
|
}; |
|
|
|
// 新增一行数据 |
|
|
@ -1488,6 +1548,7 @@ const addRow = (row, index) => { |
|
|
|
table.rows.splice(index, 0, row); |
|
|
|
} |
|
|
|
addRowKey(table.rows); |
|
|
|
state.pagination.rowsNumber = table.rows.length; |
|
|
|
stickyHeaderColumn(); |
|
|
|
}; |
|
|
|
|
|
|
@ -1705,7 +1766,7 @@ const handlerStickyChildrenColumn = (item, columns) => { |
|
|
|
} |
|
|
|
}; |
|
|
|
const getStickyColumn = () => { |
|
|
|
const columns = props.columns.filter((item, index) => { |
|
|
|
const columns = tableColumns.value.filter((item, index) => { |
|
|
|
return index < table.stickyNum; |
|
|
|
}); |
|
|
|
const arr = []; |
|
|
@ -1880,7 +1941,7 @@ const tableClassComputed = computed(() => { |
|
|
|
if (table.stickyNum && table.stickyNum > 0) { |
|
|
|
if (columnTitleState.columnTitleRowNum > 1) { |
|
|
|
// 存在多行列头 |
|
|
|
const stickyColumn = props.columns.filter((item, index) => { |
|
|
|
const stickyColumn = tableColumns.value.filter((item, index) => { |
|
|
|
return index < table.stickyNum; |
|
|
|
}); |
|
|
|
let tdNum = excludeColumnNum.value; |
|
|
@ -2035,7 +2096,7 @@ const handlerQueryFormShowField = () => { |
|
|
|
}; |
|
|
|
|
|
|
|
onMounted(() => { |
|
|
|
if (extractTableColumns && extractTableColumns.length > props.columns.length) { |
|
|
|
if (extractTableColumns.value && extractTableColumns.value > tableColumns.value.length) { |
|
|
|
handlerMoreRowColumnTitle(); |
|
|
|
} |
|
|
|
handlerQueryFormShowField(); |
|
|
|