index.vue
4.22 KB
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<template>
<div class="layout-padding">
<splitpanes>
<pane class="ml10">
<splitpanes>
<pane size="30">
<div class="layout-padding-auto layout-padding-view">
<el-row>
<div class="mb8" style="width: 100%">
<el-button @click="dicDialogRef.openDialog()" class="ml10" icon="folder-add" type="primary">
{{ $t('common.addBtn') }}
</el-button>
<el-button plain @click="handleRefreshCache()" class="ml10" icon="refresh-left" type="primary">
{{ $t('common.refreshCacheBtn') }}
</el-button>
</div>
</el-row>
<el-scrollbar>
<query-tree ref="dictTreeRef" :query="state.queryList" @node-click="handleNodeClick" placeholder="请输入字典项或名称">
<template #default="{ data }">
<span class="custom-tree-node">
<span class="label">{{ data.description }}</span>
<span class="code">{{ data.dictType }}</span>
<span class="do">
<el-button-group>
<el-button icon="el-icon-edit" size="small" @click.stop="dicDialogRef.openDialog(data.id)"></el-button>
<el-tooltip :content="$t('sysdict.deleteDisabledTip')" :disabled="data.systemFlag === '0'" placement="top">
<span style="margin-left: 12px">
<el-button
:disabled="data.systemFlag !== '0'"
icon="el-icon-delete"
size="small"
@click.stop="handleDelete([data.id])"
></el-button>
</span>
</el-tooltip>
</el-button-group>
</span>
</span>
</template>
</query-tree>
</el-scrollbar>
<el-footer style="height: 40px; line-height: 40px">
<el-button type="primary" size="small" icon="Download" style="width: 100%" @click="exportExcel">{{
$t('common.exportBtn')
}}</el-button>
</el-footer>
</div>
</pane>
<pane class="ml8">
<DicDialog @refresh="handleRefreshTree" ref="dicDialogRef" />
<dict-item-dialog ref="dictItemDialogRef"></dict-item-dialog>
</pane>
</splitpanes>
</pane>
</splitpanes>
</div>
</template>
<script lang="ts" name="systemDic" setup>
import { delObj, fetchList, refreshCache } from '/@/api/admin/dict';
import { useMessage, useMessageBox } from '/@/hooks/message';
import { useI18n } from 'vue-i18n';
import { downBlobFile } from '/@/utils/other';
// 引入组件
const DicDialog = defineAsyncComponent(() => import('./form.vue'));
const DictItemDialog = defineAsyncComponent(() => import('./dictItem/index.vue'));
const QueryTree = defineAsyncComponent(() => import('/@/components/QueryTree/index.vue'));
const { t } = useI18n();
// 定义变量内容
const dicDialogRef = ref();
const dictTreeRef = ref();
const dictItemDialogRef = ref();
const state = reactive({
queryForm: {},
queryList: (name?: string) => {
return fetchList({
name: name,
});
},
});
// 导出EXCEL
const exportExcel = () => {
downBlobFile('/admin/dict/export', state.queryForm, 'dict.xlsx');
};
//刷新缓存
const handleRefreshCache = () => {
refreshCache().then(() => {
useMessage().success('同步成功');
});
};
// 点击树
const handleNodeClick = (data: any) => {
dictItemDialogRef.value.open(data);
};
// 刷新树
const handleRefreshTree = async (data: any) => {
await dictTreeRef.value.getdeptTree();
// 选择当前编辑、新增的节点
handleNodeClick(data);
};
// 删除操作
const handleDelete = async (ids: string[]) => {
try {
await useMessageBox().confirm(t('common.delConfirmText'));
} catch {
return;
}
try {
await delObj(ids);
useMessage().success(t('common.delSuccessText'));
dictTreeRef.value.getdeptTree();
} catch (err: any) {
useMessage().error(err.msg);
}
};
</script>
<style scoped>
.menu:deep(.el-tree-node__label) {
display: flex;
flex: 1;
height: 100%;
}
.custom-tree-node {
display: flex;
flex: 1;
align-items: center;
justify-content: space-between;
font-size: 14px;
padding-right: 24px;
height: 100%;
}
.custom-tree-node .code {
font-size: 12px;
color: #999;
}
.custom-tree-node .do {
display: none;
}
.custom-tree-node:hover .code {
display: none;
}
.custom-tree-node:hover .do {
display: inline-block;
}
</style>