wangzhibo
2026-07-16 b57020623cf0c946706573bf102e548c3a544423
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<template>
    <div class="dt-dict">
        <div class="top">
            <el-tooltip :content="$t('刷新')">
                <div class="cl-comm__icon" @click="reload">
                    <cl-svg name="refresh" />
                </div>
            </el-tooltip>
 
            <el-input
                v-model="keyWord"
                class="search"
                :placeholder="$t('搜索关键字')"
                clearable
                @input="onKeyWordChange"
            >
                <template #prefix>
                    <cl-svg name="search" />
                </template>
            </el-input>
        </div>
 
        <el-result
            icon="warning"
            :title="$t('没有可用的字典')"
            :sub-title="$t('请添加新的字典条目')"
            v-if="isEmpty(list)"
        >
            <template #extra>
                <el-button type="success" @click="add">
                    {{ $t('去添加') }}
                </el-button>
                <el-button type="primary" @click="reload">
                    {{ $t('刷新') }}
                </el-button>
            </template>
        </el-result>
 
        <el-tree :ref="setRefs('tree')" :data="list" :filter-node-method="filterNode" v-else />
    </div>
</template>
 
<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { useCool } from '/@/cool';
import { isEmpty } from 'lodash-es';
import { deepTree } from '/@/cool/utils';
 
interface Item {
    label: string;
    children: Item[];
}
 
const { service, refs, setRefs, router } = useCool();
 
const list = ref<Item[]>([{ label: '', children: [] }]);
const keyWord = ref('');
 
function refresh() {
    service.dict.type.list().then(types => {
        service.dict.info.list().then(res => {
            list.value = types.map(e => {
                return {
                    label: e.name! + ' - ' + e.key,
                    children: deepTree(
                        res.map(a => {
                            return {
                                ...a,
                                label: a.name + ' = ' + a.value
                            };
                        })
                    ).filter(a => a.typeId == e.id)
                };
            });
        });
    });
}
 
function reload() {
    refresh();
}
 
function add() {
    router.push('/dict/list');
}
 
function filterNode(value: string, data: any) {
    if (!value) return true;
    return data.label.includes(value);
}
 
function onKeyWordChange(val: string) {
    refs.tree?.filter(val);
}
 
onMounted(() => {
    refresh();
});
</script>
 
<style lang="scss" scoped>
.dt-dict {
    .top {
        display: flex;
        align-items: center;
        margin-bottom: 10px;
        position: sticky;
        top: 10px;
        z-index: 2;
        background-color: var(--el-bg-color);
 
        .search {
            margin-left: 5px;
 
            :deep(.el-input__wrapper) {
                height: 32px;
                border-radius: 6px;
            }
        }
 
        .cl-comm__icon {
            height: 32px;
            width: 32px;
        }
    }
 
    :deep(.el-tree-node__content) {
        border-radius: 4px;
        height: 32px;
    }
 
    :deep(.el-tree-node__label) {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: 450px;
    }
}
</style>