-
zhangwei
3 天以前 6002efe19de5fbf0ebf4f5192f3d9088f7588439
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
<template>
    <div class="sys-dict-container">
        <el-row :gutter="8" style="width: 100%; height: 100%; flex: 1">
            <el-col :span="12" :xs="24" style="display: flex; height: 100%; flex: 1">
                <el-card class="full-table" shadow="hover" :body-style="{ height: 'calc(100% - 51px)' }">
                    <template #header>
                        <el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"><ele-Collection /></el-icon>字典
                    </template>
                    <el-form :model="state.queryDictTypeParams" ref="queryForm" :inline="true" @submit.native.prevent>
                        <el-form-item label="名称">
                            <el-input v-model="state.queryDictTypeParams.name" @keyup.enter.native="handleDictTypeQuery" placeholder="字典名称" clearable />
                        </el-form-item>
                        <el-form-item>
                            <el-button-group>
                                <el-button type="primary" icon="ele-Search" @click="handleDictTypeQuery" v-auth="'sysDictType:page'"> 查询 </el-button>
                                <el-button icon="ele-Refresh" @click="resetDictTypeQuery"> 重置 </el-button>
                            </el-button-group>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" icon="ele-Plus" @click="openAddDictType" v-auth="'sysDictType:add'"> 新增 </el-button>
                        </el-form-item>
                    </el-form>
 
                    <el-table :data="state.dictTypeData" style="width: 100%" v-loading="state.typeLoading" @row-click="handleDictType" highlight-current-row border>
                        <el-table-column type="index" label="序号" width="55" align="center" />
                        <el-table-column prop="name" label="字典名称" min-width="120" header-align="center" show-overflow-tooltip />
                        <el-table-column prop="code" label="字典编码" min-width="140" header-align="center" show-overflow-tooltip />
                        <el-table-column prop="sysFlag" label="系统内置" min-width="70" align="center" show-overflow-tooltip v-if="userInfo.accountType === AccountTypeEnum.NUMBER_999">
                            <template #default="scope">
                <g-sys-dict v-model="scope.row.sysFlag" code="YesNoEnum" />
                            </template>
                        </el-table-column>
                        <el-table-column prop="isTenant" label="租户字典" min-width="70" align="center" show-overflow-tooltip v-if="userInfo.accountType === AccountTypeEnum.NUMBER_999">
                            <template #default="scope">
                <g-sys-dict v-model="scope.row.isTenant" code="YesNoEnum" />
                            </template>
                        </el-table-column>
                        <el-table-column prop="status" label="状态" width="70" align="center" show-overflow-tooltip>
                            <template #default="scope">
                <g-sys-dict v-model="scope.row.status" code="StatusEnum" />
                            </template>
                        </el-table-column>
                        <el-table-column prop="orderNo" label="排序" width="60" align="center" show-overflow-tooltip />
                        <el-table-column label="修改记录" width="100" align="center" show-overflow-tooltip>
                            <template #default="scope">
                                <ModifyRecord :data="scope.row" />
                            </template>
                        </el-table-column>
                        <el-table-column label="操作" width="120" fixed="right" align="center" v-if="auths(['sysDictType:update', 'sysDictType:delete'])">
                            <template #default="scope">
                                <el-tooltip content="编辑">
                                    <el-button icon="ele-Edit" size="small" text type="primary" :disabled="!hasPermission(scope.row)" @click="openEditDictType(scope.row)" v-auth="'sysDictType:update'"> </el-button>
                                </el-tooltip>
                                <el-tooltip content="删除">
                                    <el-button icon="ele-Delete" size="small" text type="danger" :disabled="scope.row?.sysFlag === 1 || !hasPermission(scope.row)" @click="delDictType(scope.row)" v-auth="'sysDictType:delete'"> </el-button>
                                </el-tooltip>
                            </template>
                        </el-table-column>
                    </el-table>
                    <el-pagination
                        v-model:currentPage="state.tableDictTypeParams.page"
                        v-model:page-size="state.tableDictTypeParams.pageSize"
                        :total="state.tableDictTypeParams.total"
                        :page-sizes="[10, 20, 50, 100]"
                        size="small"
                        background
                        @size-change="handleDictTypeSizeChange"
                        @current-change="handleDictTypeCurrentChange"
                        layout="total, sizes, prev, pager, next, jumper"
                    />
                </el-card>
            </el-col>
 
            <el-col :span="12" :xs="24" style="display: flex; height: 100%; flex: 1">
                <el-card class="full-table" shadow="hover" :body-style="{ height: 'calc(100% - 51px)' }">
                    <template #header>
                        <el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"><ele-Collection /></el-icon>字典值【{{ state.editDictTypeName }}】
                    </template>
                    <el-form :model="state.queryDictDataParams" ref="queryForm" :inline="true" @submit.native.prevent>
                        <el-form-item label="显示文本">
                            <el-input v-model="state.queryDictDataParams.label" placeholder="显示文本" @keyup.enter="handleDictDataQuery" />
                        </el-form-item>
                        <el-form-item>
                            <el-button-group>
                                <el-button type="primary" icon="ele-Search" @click="handleDictDataQuery"> 查询 </el-button>
                                <el-button icon="ele-Refresh" @click="resetDictDataQuery"> 重置 </el-button>
                            </el-button-group>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" icon="ele-Plus" @click="openAddDictData" :disabled="!hasPermission(state.selectDict)" v-auth="'sysDictData:add'"> 新增 </el-button>
                        </el-form-item>
                    </el-form>
 
                    <el-table :data="state.dictDataData" style="width: 100%" v-loading="state.loading" border>
                        <el-table-column type="index" label="序号" width="55" align="center" />
                        <el-table-column prop="value" label="显示文本" header-align="center" min-width="120" show-overflow-tooltip>
                            <template #default="scope">
                                <el-tag :type="scope.row.tagType" :style="scope.row.styleSetting" :class="scope.row.classSetting">{{ scope.row.label }}</el-tag>
                            </template>
                        </el-table-column>
                        <el-table-column prop="value" label="字典值" header-align="center" min-width="120" show-overflow-tooltip />
                        <el-table-column prop="code" label="编码" header-align="center" min-width="120" show-overflow-tooltip />
                        <el-table-column prop="extData" label="拓展数据" width="90" align="center">
                            <template #default="scope">
                                <el-tag type="warning" v-if="scope.row.extData == null || scope.row.extData == ''">空</el-tag>
                                <el-tag type="success" v-else>有值</el-tag>
                            </template>
                        </el-table-column>
                        <el-table-column prop="status" label="状态" width="70" align="center" show-overflow-tooltip>
                            <template #default="scope">
                <g-sys-dict v-model="scope.row.status" code="StatusEnum" />
                            </template>
                        </el-table-column>
                        <el-table-column prop="orderNo" label="排序" width="60" align="center" show-overflow-tooltip />
                        <el-table-column label="修改记录" width="100" align="center" show-overflow-tooltip>
                            <template #default="scope">
                                <ModifyRecord :data="scope.row" />
                            </template>
                        </el-table-column>
                        <el-table-column label="操作" width="120" fixed="right" align="center" show-overflow-tooltip v-if="auths(['sysDictData:add', 'sysDictData:update', 'sysDictData:delete'])">
                            <template #default="scope">
                                <el-tooltip content="编辑">
                                    <el-button icon="ele-Edit" size="small" text type="primary" @click="openEditDictData(scope.row)" v-auth="'sysDictData:update'"> </el-button>
                                </el-tooltip>
                                <el-tooltip content="删除">
                                    <el-button icon="ele-Delete" size="small" text type="danger" :disabled="!hasPermission(state.selectDict)" @click="delDictData(scope.row)" v-auth="'sysDictData:delete'"> </el-button>
                                </el-tooltip>
                                <el-tooltip content="复制">
                                    <el-button icon="ele-CopyDocument" size="small" text type="primary" :disabled="!hasPermission(state.selectDict)" @click="openCopyDictData(scope.row)" v-auth="'sysDictData:add'"> </el-button>
                                </el-tooltip>
                            </template>
                        </el-table-column>
                    </el-table>
                    <el-pagination
                        v-model:currentPage="state.tableDictDataParams.page"
                        v-model:page-size="state.tableDictDataParams.pageSize"
                        :total="state.tableDictDataParams.total"
                        :page-sizes="[10, 20, 50, 100]"
                        size="small"
                        background
                        @size-change="handleDictDataSizeChange"
                        @current-change="handleDictDataCurrentChange"
                        layout="total, sizes, prev, pager, next, jumper"
                    />
                </el-card>
            </el-col>
        </el-row>
        <EditDictType ref="editDictTypeRef" :title="state.editDictTypeTitle" @handleQuery="handleDictTypeQuery" @handleUpdate="updateDictSession" />
        <EditDictData ref="editDictDataRef" :title="state.editDictDataTitle" @handleQuery="handleDictDataQuery" @handleUpdate="updateDictSession" />
    </div>
</template>
 
<script lang="ts" setup name="sysDict">
import { onMounted, reactive, ref } from 'vue';
import { getAPI } from '/@/utils/axios-utils';
import { useUserInfo } from '/@/stores/userInfo';
import { ElMessageBox, ElMessage } from 'element-plus';
import {SysDictType, SysDictData, UpdateDictDataInput, AccountTypeEnum} from '/@/api-services/models';
import { SysDictTypeApi, SysDictDataApi } from '/@/api-services/api';
import EditDictType from '/@/views/system/dict/component/editDictType.vue';
import EditDictData from '/@/views/system/dict/component/editDictData.vue';
import ModifyRecord from '/@/components/table/modifyRecord.vue';
import { auths } from "/@/utils/authFunction";
 
const userInfo = useUserInfo().userInfos;
const editDictTypeRef = ref<InstanceType<typeof EditDictType>>();
const editDictDataRef = ref<InstanceType<typeof EditDictData>>();
const state = reactive({
    loading: false,
    typeLoading: false,
    showMoveDictDialog: false,
    tenantList: [] as Array<any>,
    selectDict: {} as SysDictType,
    dictTypeData: [] as Array<SysDictType>,
    dictDataData: [] as Array<SysDictData>,
    queryDictTypeParams: {
        name: undefined,
        code: undefined,
    },
    tableDictTypeParams: {
        page: 1,
        pageSize: 50,
        total: 0 as any,
    },
    queryDictDataParams: {
    label: undefined,
        dictTypeId: 0, // 字典类型Id
    },
    tableDictDataParams: {
        page: 1,
        pageSize: 50,
        total: 0 as any,
    },
    editDictTypeTitle: '',
    editDictDataTitle: '',
    editDictTypeName: '',
});
 
onMounted(async () => {
    handleDictTypeQuery();
});
 
// 查询字典操作
const handleDictTypeQuery = async () => {
    state.typeLoading = true;
    let params = Object.assign(state.queryDictTypeParams, state.tableDictTypeParams);
    const res = await getAPI(SysDictTypeApi).apiSysDictTypePagePost(params);
    state.dictTypeData = res.data.result?.items ?? [];
    state.tableDictTypeParams.total = res.data.result?.total;
    state.typeLoading = false;
};
 
// 查询字典值操作
const handleDictDataQuery = async () => {
    state.loading = true;
    let params = Object.assign(state.queryDictDataParams, state.tableDictDataParams);
    const res = await getAPI(SysDictDataApi).apiSysDictDataPagePost(params);
    state.dictDataData = res.data.result?.items ?? [];
    state.tableDictDataParams.total = res.data.result?.total;
    state.loading = false;
};
 
// 点击表格
const handleDictType = (row: any, event: any, column: any) => {
    openDictDataDialog(row);
};
 
// 判断是否有权限操作
const hasPermission = (row: any) => {
    if (row.code?.toLowerCase().endsWith('enum')) return false;
    return row?.sysFlag === 2 || userInfo.accountType === AccountTypeEnum.NUMBER_999;
};
 
// 重置字典操作
const resetDictTypeQuery = () => {
    state.queryDictTypeParams.name = undefined;
    state.queryDictTypeParams.code = undefined;
    handleDictTypeQuery();
};
 
// 重置字典值操作
const resetDictDataQuery = () => {
    state.queryDictDataParams.label = undefined;
    handleDictDataQuery();
};
 
// 打开新增字典页面
const openAddDictType = () => {
    state.editDictTypeTitle = '添加字典';
    editDictTypeRef.value?.openDialog({ sysFlag: 2, status: 1, orderNo: 100 });
};
 
// 打开新增字典值页面
const openAddDictData = () => {
    if (!state.queryDictDataParams.dictTypeId) {
        ElMessage.warning('请选择字典');
        return;
    }
    state.editDictDataTitle = '添加字典值';
    editDictDataRef.value?.openDialog({ status: 1, orderNo: 100, dictTypeId: state.queryDictDataParams.dictTypeId });
};
 
// 打开编辑字典页面
const openEditDictType = (row: any) => {
    state.editDictTypeTitle = '编辑字典';
    editDictTypeRef.value?.openDialog(row);
};
 
// 打开复制字典值页面
const openCopyDictData = (row: any) => {
    state.editDictDataTitle = '复制字典值';
    const copyRow = JSON.parse(JSON.stringify(row));
    copyRow.id = 0;
    copyRow.dictType = null;
    editDictDataRef.value?.openDialog(copyRow);
};
 
// 打开编辑字典值页面
const openEditDictData = (row: any) => {
    row.dictType = state.selectDict;
    state.editDictDataTitle = '编辑字典值';
    editDictDataRef.value?.openDialog(row);
};
 
// 打开字典值页面
const openDictDataDialog = (row: any) => {
    state.selectDict = row;
    state.editDictTypeName = row.name;
    state.queryDictDataParams.dictTypeId = row.id;
    handleDictDataQuery();
};
 
// 删除字典
const delDictType = (row: any) => {
    ElMessageBox.confirm(`确定删除字典:【${row.name}】?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
    }).then(async () => {
            await getAPI(SysDictTypeApi).apiSysDictTypeDeletePost({ id: row.id });
            handleDictTypeQuery();
            updateDictSession();
            ElMessage.success('删除成功');
  }).catch(() => {});
};
 
// 删除字典值
const delDictData = (row: any) => {
    ElMessageBox.confirm(`确定删除字典值:【${row.value}】?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
    }).then(async () => {
            await getAPI(SysDictDataApi).apiSysDictDataDeletePost({ id: row.id });
            handleDictDataQuery();
            updateDictSession();
            ElMessage.success('删除成功');
  }).catch(() => {});
};
 
// 改变字典页面容量
const handleDictTypeSizeChange = (val: number) => {
    state.tableDictTypeParams.pageSize = val;
    handleDictTypeQuery();
};
 
// 改变字典页码序号
const handleDictTypeCurrentChange = (val: number) => {
    state.tableDictTypeParams.page = val;
    handleDictTypeQuery();
};
 
// 改变字典值页面容量
const handleDictDataSizeChange = (val: number) => {
    state.tableDictDataParams.pageSize = val;
    handleDictDataQuery();
};
 
// 改变字典值页码序号
const handleDictDataCurrentChange = (val: number) => {
    state.tableDictDataParams.page = val;
    handleDictDataQuery();
};
 
// 更新前端字典缓存
const updateDictSession = async () => {
    await useUserInfo().setDictList();
};
</script>
 
<style scoped>
:deep(.notice-bar) {
    position: absolute;
    display: inline-flex;
    height: 25px !important;
    width: 500px;
    overflow: hidden !important;
    div[data-slate-editor] {
        text-wrap-mode: nowrap;
    }
}
</style>