fix: 默认选中第一个字典

This commit is contained in:
2024-10-27 22:20:18 +08:00
parent 4b902475dd
commit 34d4faa090
3 changed files with 34 additions and 23 deletions

View File

@@ -11,15 +11,15 @@
</a-col>
<a-col :xs="24" :sm="16" :md="17" :lg="18" :xl="19" :xxl="20" flex="1" class="h-full ov-hidden">
<GiTable
row-key="id"
:data="dataList"
:columns="columns"
:loading="loading"
:scroll="{ x: '100%', y: '100%', minWidth: 600 }"
:pagination="pagination"
:disabled-tools="['size']"
:disabled-column-keys="['label']"
@refresh="search"
row-key="id"
:data="dataList"
:columns="columns"
:loading="loading"
:scroll="{ x: '100%', y: '100%', minWidth: 600 }"
:pagination="pagination"
:disabled-tools="['size']"
:disabled-column-keys="['label']"
@refresh="search"
>
<template #toolbar-left>
<a-input v-model="queryForm.description" placeholder="请输入标签/描述" allow-clear @change="search">

View File

@@ -10,8 +10,13 @@
</div>
<div class="dict-tree__container">
<div class="dict-tree__tree">
<a-tree :data="(treeData as unknown as TreeNodeData[])" :field-names="{ key: 'id' }" block-node
@select="select">
<a-tree
:data="(treeData as unknown as TreeNodeData[])"
:field-names="{ key: 'id' }"
block-node
:selected-keys="selectedKeys"
@select="select"
>
<template #title="node">
<a-typography-paragraph
:ellipsis="{
@@ -33,10 +38,10 @@
</template>
</a-tree>
</div>
</div>
</div>
<DictAddModal ref="DictAddModalRef" @save-success="getTreeData" />
</div>
<DictAddModal ref="DictAddModalRef" @save-success="getTreeData" />
</div>
</template>
<script setup lang="tsx">
@@ -58,13 +63,13 @@ const emit = defineEmits<{
(e: 'node-click', keys: Array<any>): void
}>()
const selectKey = ref()
const selectedKeys = ref()
// 选中节点
const select = (keys: Array<any>) => {
if (selectKey.value === keys[0]) {
if (selectedKeys.value && selectedKeys.value[0] === keys[0]) {
return
}
selectKey.value = keys[0]
selectedKeys.value = keys
emit('node-click', keys)
}
@@ -89,6 +94,9 @@ const getTreeData = async (query: DictQuery = { ...queryForm }) => {
return null
}
}))
await nextTick(() => {
select([treeData.value[0]?.id])
})
} finally {
loading.value = false
}
@@ -122,7 +130,7 @@ const onMenuItemClick = (mode: string, node: DictResp) => {
const res = await deleteDict(node.id)
if (res.success) {
Message.success('删除成功')
getTreeData()
await getTreeData()
}
return res.success
} catch (error) {

View File

@@ -20,11 +20,11 @@
<IconCaretDown v-if="!isLeaf" />
<IconIdcard v-else />
</template>
<template #title="nodeData">
<template v-if="index = getMatchIndex(nodeData?.title), index < 0">{{ nodeData?.title }}</template>
<span v-else>{{ nodeData?.title?.substr(0, index) }}
<span style="color: rgb(var(--arcoblue-6));">{{ nodeData?.title?.substr(index, searchKey.length) }}</span>
{{ nodeData?.title?.substr(index + searchKey.length) }}
<template #title="node">
<template v-if="index = getMatchIndex(node?.title), index < 0">{{ node?.title }}</template>
<span v-else>{{ node?.title?.substr(0, index) }}
<span style="color: rgb(var(--arcoblue-6));">{{ node?.title?.substr(index, searchKey.length) }}</span>
{{ node?.title?.substr(index + searchKey.length) }}
</span>
</template>
</a-tree>
@@ -50,6 +50,9 @@ const emit = defineEmits<{
// 选中节点
const selectedKeys = ref()
const select = (keys: Array<any>) => {
if (selectedKeys.value && selectedKeys.value[0] === keys[0]) {
return
}
selectedKeys.value = keys
emit('node-click', keys)
}