lzq 2025-12-10 17:38:20 +08:00
parent 1db6d96b2a
commit 344163a1e4
1 changed files with 34 additions and 15 deletions

View File

@ -17,14 +17,21 @@
<ElButton :icon="elIcons.Plus" type="primary" @click="addHandler"></ElButton> <ElButton :icon="elIcons.Plus" type="primary" @click="addHandler"></ElButton>
<ElButton :icon="elIcons.Filter" type="default" @click="showSearchForm = !showSearchForm"/> <ElButton :icon="elIcons.Filter" type="default" @click="showSearchForm = !showSearchForm"/>
</div> </div>
<!--
<ElTable v-loading="searching" :data="tableData" lazy
:load="treeLoad" :tree-props="{ children: 'children', hasChildren: 'hasChildren' }" :load="treeLoad"
-->
<ElTable v-loading="searching"
:data="tableData"
lazy
:load="treeLoad"
:tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
@expand-change="treeLoad"
cell-class-name="table-cell" cell-class-name="table-cell"
class="table-list" class="table-list"
empty-text="暂无数据" empty-text="暂无数据"
header-row-class-name="table-header" header-row-class-name="table-header"
lazy ref="dataTable"
row-key="id"> row-key="id">
<!-- <ElTableColumn type="expand" width="60"/> --> <!-- <ElTableColumn type="expand" width="60"/> -->
<ElTableColumn label="图标" prop="icon" width="100"> <ElTableColumn label="图标" prop="icon" width="100">
@ -84,12 +91,14 @@ import { elIcons } from '@/common/element/element.ts'
import MenuForm from '@/pages/sys/menus/MenuForm.vue' import MenuForm from '@/pages/sys/menus/MenuForm.vue'
import Strings from '@/common/utils/strings.ts' import Strings from '@/common/utils/strings.ts'
import AIcon from '@/components/a-icon/AIcon.tsx' import AIcon from '@/components/a-icon/AIcon.tsx'
import type { TableInstance } from 'element-plus'
const tableData = ref<MenuTypes.SysMenu[]>([]) const tableData = ref<MenuTypes.SysMenu[]>([])
const searchForm = reactive<MenuTypes.SearchForm>({}) const searchForm = reactive<MenuTypes.SearchForm>({})
const searching = ref(false) const searching = ref(false)
const showSearchForm = ref(true) const showSearchForm = ref(true)
const menuFormIns = useTemplateRef<InstanceType<typeof MenuForm>>('menuForm') const menuFormIns = useTemplateRef<InstanceType<typeof MenuForm>>('menuForm')
const dataTableIns = useTemplateRef<InstanceType<TableInstance>>('dataTable')
const deling = ref(false) const deling = ref(false)
function showDialog(data?: MenuTypes.MenuForm) { function showDialog(data?: MenuTypes.MenuForm) {
@ -131,6 +140,7 @@ function listAll() {
tableData.value = [] tableData.value = []
tableData.value = res.data?.map(it => { tableData.value = res.data?.map(it => {
it.hasChildren = true it.hasChildren = true
it.children = []
return it return it
}) ?? [] }) ?? []
}) })
@ -139,18 +149,27 @@ function listAll() {
}) })
} }
function treeLoad(row: MenuTypes.SysMenu, _: any, resolve: (data: MenuTypes.SysMenu[]) => void) { function treeLoad(row: MenuTypes.SysMenu, expanded: boolean, resolve: (data: MenuTypes.SysMenu[]) => void) {
if (resolve == null && !expanded) return
searching.value = true searching.value = true
MenuApi.listAll({...searchForm, pid: row.id}) MenuApi.listAll({...searchForm, pid: row.id})
.then(res => { .then(res => {
resolve(res.data?.map(it => { if (resolve!=null){
it.hasChildren = true resolve(res.data?.map(it => {
return it it.hasChildren = true
}) ?? []) return it
}) }) ?? [])
.finally(() => { } else {
searching.value = false dataTableIns.value.updateKeyChildren(row.id,res.data?.map(it => {
}) it.hasChildren = true
it.children = []
return it
}) ?? [])
}
})
.finally(() => {
searching.value = false
})
} }
onMounted(() => { onMounted(() => {