6060 :maxTableHeight =" 260"
6161 :row-key =" (row: any) => row.id"
6262 style =" min-width : 600px "
63-
63+ :expand-row-keys =" defaultExpandKeys"
64+ :default-expand-all =" searchForm.name || searchForm.permission?.length > 0"
6465 show-overflow-tooltip
6566 >
6667 <el-table-column type =" selection" width =" 55" :reserve-selection =" true" > </el-table-column >
138139 </div >
139140</template >
140141<script setup lang="ts">
141- import { ref , onMounted , computed , nextTick } from ' vue'
142+ import { ref , onMounted , computed , watch } from ' vue'
142143import { useRoute } from ' vue-router'
143144import type { Provider } from ' @/api/type/model'
144145import { SourceTypeEnum } from ' @/enums/common'
@@ -159,25 +160,40 @@ const props = defineProps<{
159160}>()
160161const emit = defineEmits ([' submitPermissions' ])
161162
162- const defaultExpandKeys = computed (() => {
163- const searchName = searchForm .value .name || ' '
164- const searchPermissions = searchForm .value .permission ?? []
165- if (! searchName && (! searchPermissions || searchPermissions .length === 0 )) {
166- return props .data ?.length > 0 ? [props .data [0 ]?.id ] : []
167- }
168- const expandIds: string [] = []
169- // 传入过滤后的数据
170- const collectExpandIds = (nodes : any []) => {
171- nodes .forEach ((node ) => {
172- if (node .children && node .children .length > 0 ) {
173- expandIds .push (node .id )
174- collectExpandIds (node .children )
175- }
176- })
177- }
178- collectExpandIds (filteredData .value )
179- return expandIds
180- })
163+ const defaultExpandKeys = ref <Array <string >>([])
164+ const isComputedFirst = ref (true ) // 仅第一次获得数据的时候需要计算一次展开属性
165+
166+ watch (
167+ () => props .data ,
168+ (newData ) => {
169+ if (newData && newData .length > 0 && isComputedFirst .value ) {
170+ defaultExpandKeys .value = props .data ?.length > 0 ? [props .data [0 ]?.id ] : []
171+ isComputedFirst .value = false
172+ }
173+ },
174+ { immediate: true },
175+ )
176+
177+ // const defaultExpandKeys = computed(() => {
178+ // const searchName = searchForm.value.name || ''
179+ // const searchPermissions = searchForm.value.permission ?? []
180+ // if (!searchName && (!searchPermissions || searchPermissions.length === 0)) {
181+ // return props.data?.length > 0 ? [props.data[0]?.id] : []
182+
183+ // }
184+ // const expandIds: string[] = []
185+ // // 传入过滤后的数据
186+ // const collectExpandIds = (nodes: any[]) => {
187+ // nodes.forEach((node) => {
188+ // if (node.children && node.children.length > 0) {
189+ // expandIds.push(node.id)
190+ // collectExpandIds(node.children)
191+ // }
192+ // })
193+ // }
194+ // collectExpandIds(filteredData.value)
195+ // return expandIds
196+ // })
181197
182198const permissionOptionMap = computed (() => {
183199 return {
0 commit comments