|
|
@@ -225,26 +225,55 @@ const { queryParams, form, rules } = toRefs(data);
|
|
|
|
|
|
/** 查询字典类型详细 */
|
|
|
function getTypes(dictId) {
|
|
|
+ const queryDictType = route.query?.dictType || '';
|
|
|
+ if (!dictId) {
|
|
|
+ setDictType(queryDictType);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const fromOption = typeOptions.value.find(item => String(item.dictId) === String(dictId))?.dictType || '';
|
|
|
getType(dictId).then(response => {
|
|
|
- queryParams.value.dictType = response.data.dictType;
|
|
|
- defaultDictType.value = response.data.dictType;
|
|
|
- getList();
|
|
|
+ setDictType(response?.data?.dictType || fromOption || queryDictType);
|
|
|
+ }).catch(() => {
|
|
|
+ setDictType(fromOption || queryDictType);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+/** 设置当前字典类型;类型不存在时降级为空列表 */
|
|
|
+function setDictType(dictType) {
|
|
|
+ const type = dictType || undefined;
|
|
|
+ queryParams.value.dictType = type;
|
|
|
+ defaultDictType.value = type;
|
|
|
+ if (!type) {
|
|
|
+ proxy.$modal.msgWarning('字典类型不存在或已删除,暂无可展示的字典数据');
|
|
|
+ }
|
|
|
+ getList();
|
|
|
+}
|
|
|
+
|
|
|
/** 查询字典类型列表 */
|
|
|
function getTypeList() {
|
|
|
- getDictOptionselect().then(response => {
|
|
|
- typeOptions.value = response.data;
|
|
|
+ return getDictOptionselect().then(response => {
|
|
|
+ typeOptions.value = response?.data || [];
|
|
|
+ }).catch(() => {
|
|
|
+ typeOptions.value = [];
|
|
|
});
|
|
|
}
|
|
|
|
|
|
/** 查询字典数据列表 */
|
|
|
function getList() {
|
|
|
+ if (!queryParams.value.dictType) {
|
|
|
+ dataList.value = [];
|
|
|
+ total.value = 0;
|
|
|
+ loading.value = false;
|
|
|
+ return;
|
|
|
+ }
|
|
|
loading.value = true;
|
|
|
listData(queryParams.value).then(response => {
|
|
|
- dataList.value = response.rows;
|
|
|
- total.value = response.total;
|
|
|
+ dataList.value = response?.rows || [];
|
|
|
+ total.value = response?.total || 0;
|
|
|
+ }).catch(() => {
|
|
|
+ dataList.value = [];
|
|
|
+ total.value = 0;
|
|
|
+ }).finally(() => {
|
|
|
loading.value = false;
|
|
|
});
|
|
|
}
|
|
|
@@ -291,6 +320,10 @@ function resetQuery() {
|
|
|
|
|
|
/** 新增按钮操作 */
|
|
|
function handleAdd() {
|
|
|
+ if (!queryParams.value.dictType) {
|
|
|
+ proxy.$modal.msgWarning('字典类型不存在,无法新增字典数据');
|
|
|
+ return;
|
|
|
+ }
|
|
|
reset();
|
|
|
open.value = true;
|
|
|
title.value = "添加字典数据";
|
|
|
@@ -357,6 +390,7 @@ function handleExport() {
|
|
|
}, `dict_data_${new Date().getTime()}.xlsx`);
|
|
|
}
|
|
|
|
|
|
-getTypes(route.params && route.params.dictId);
|
|
|
-getTypeList();
|
|
|
+getTypeList().finally(() => {
|
|
|
+ getTypes(route.params && route.params.dictId);
|
|
|
+});
|
|
|
</script>
|