diff --git a/index.html b/index.html index 1f9ec73..925832b 100644 --- a/index.html +++ b/index.html @@ -15,9 +15,9 @@ diff --git a/src/components/piTable/index.vue b/src/components/piTable/index.vue index 73b7c21..411e3b4 100644 --- a/src/components/piTable/index.vue +++ b/src/components/piTable/index.vue @@ -134,6 +134,7 @@ const props = defineProps({ pageSize: {type: Number, default: config.pageSize}, pageSizes: {type: Array, default: config.pageSizes}, rowKey: {type: String, default: ""}, + primaryKey: {type: String, default: "id"}, summaryMethod: {type: Function, default: null}, column: { type: Object, default: () => { @@ -271,13 +272,13 @@ async function getData() { emptyText.value = response.msg; } else { emptyText.value = "暂无数据"; - if (props.hidePagination) { - tableData.value = response.data || []; - } else { - tableData.value = response.rows || []; - } + tableData.value = response.data || []; if (props.rowKey) { - tableData.value = tools.makeTreeData(tableData.value, 0, props.rowKey) + tableData.value = tools.makeTreeData(tableData.value, 0, props.primaryKey, props.rowKey) + // 适配搜索显示 + if (response.data.length > 0 && tableData.value.length === 0) { + tableData.value = response.data + } } total.value = response.total || 0; summary.value = response.summary || {}; @@ -465,7 +466,6 @@ function toggleRowSelection(row, selected) { piTableRef.value.toggleRowSelection(row, selected) } - function toggleAllSelection() { piTableRef.value.toggleAllSelection() } diff --git a/src/config/table.ts b/src/config/table.ts index b43e9fd..9cd19fd 100644 --- a/src/config/table.ts +++ b/src/config/table.ts @@ -8,7 +8,6 @@ export default { parseData: function (res) { //数据分析 return { data: res.data, //分析无分页的数据字段结构 - rows: res.data, //分析行数据字段结构 total: res.count, //分析总数字段结构 summary: res.summary, //分析合计行字段结构 msg: res.msg, //分析描述字段结构 @@ -28,11 +27,11 @@ export default { */ columnSettingSave: function (tableName, column) { return new Promise((resolve) => { - setTimeout(()=>{ + setTimeout(() => { //这里为了演示使用了session和setTimeout演示,开发时应用数据请求 tools.data.set(tableName, column) resolve(true) - },1000) + }, 1000) }) }, /** @@ -44,9 +43,9 @@ export default { return new Promise((resolve) => { //这里为了演示使用了session和setTimeout演示,开发时应用数据请求 const userColumn = tools.data.get(tableName) - if(userColumn){ + if (userColumn) { resolve(userColumn) - }else{ + } else { resolve(column) } }) @@ -59,10 +58,10 @@ export default { columnSettingReset: function (tableName, column) { return new Promise((resolve) => { //这里为了演示使用了session和setTimeout演示,开发时应用数据请求 - setTimeout(()=>{ + setTimeout(() => { tools.data.remove(tableName) resolve(column) - },1000) + }, 1000) }) } } diff --git a/src/utils/tools.ts b/src/utils/tools.ts index fd051f9..d1a7ea8 100644 --- a/src/utils/tools.ts +++ b/src/utils/tools.ts @@ -129,7 +129,7 @@ const tools = { } return fmt; }, - makeTreeData: function (data, pid = 0, key = "id", parent = "pid") { + makeTreeData: function (data, pid = 0, key = "id", parent = "parent_id") { const arr = []; for (let item of data) { if (item[parent] == pid) {