Skip to content

Commit

Permalink
fix: 默认选中第一个字典
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Oct 27, 2024
1 parent 4b90247 commit 34d4faa
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 23 deletions.
18 changes: 9 additions & 9 deletions src/views/system/dict/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
26 changes: 17 additions & 9 deletions src/views/system/dict/tree/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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="{
Expand All @@ -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">
Expand All @@ -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)
}
Expand All @@ -89,6 +94,9 @@ const getTreeData = async (query: DictQuery = { ...queryForm }) => {
return null
}
}))
await nextTick(() => {
select([treeData.value[0]?.id])
})
} finally {
loading.value = false
}
Expand Down Expand Up @@ -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) {
Expand Down
13 changes: 8 additions & 5 deletions src/views/system/user/dept/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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)
}
Expand Down

0 comments on commit 34d4faa

Please sign in to comment.